From bb0f7251b3972ddf1f9ea8053c351f5a7302e67f Mon Sep 17 00:00:00 2001 From: Anatolii Kmetiuk Date: Fri, 10 Sep 2021 19:59:31 +0200 Subject: [PATCH] Migrate to GitHub Actions CI (#50) * Add GitHub Actions CI * Derive publish version from Git tag * Remove Travis * Remove Travis CI files --- .github/workflows/actions.yml | 95 +++++++++++++++++++++++++++++++++++ .travis.yml | 27 ---------- build.sc | 78 ++-------------------------- ci/on-master.py | 10 ---- ci/publish-docs.sh | 20 -------- ci/release-github.sh | 7 --- ci/release-sonatype.sh | 16 ------ ci/test.sh | 5 -- ci/upload.sc | 56 --------------------- docs/build.sc | 9 ---- 10 files changed, 98 insertions(+), 225 deletions(-) create mode 100644 .github/workflows/actions.yml delete mode 100644 .travis.yml delete mode 100755 ci/on-master.py delete mode 100755 ci/publish-docs.sh delete mode 100755 ci/release-github.sh delete mode 100755 ci/release-sonatype.sh delete mode 100755 ci/test.sh delete mode 100644 ci/upload.sc diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml new file mode 100644 index 0000000000..65c0239d23 --- /dev/null +++ b/.github/workflows/actions.yml @@ -0,0 +1,95 @@ +name: ci + +on: + push: + pull_request: + branches: + - master + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + java: [ '8', '9' ] + name: Tests for Java ${{ matrix.Java }} + steps: + - uses: actions/checkout@v2 + - name: Setup java + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: ${{ matrix.java }} + - name: Run tests + run: | + set -eux + ./mill -i --disable-ticker __.testLocal + + publish-sonatype: + if: github.repository == 'com-lihaoyi/cask' && contains(github.ref, 'refs/tags/') + needs: test + runs-on: ubuntu-latest + env: + SONATYPE_PGP_PRIVATE_KEY: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY }} + SONATYPE_PGP_PRIVATE_KEY_PASSWORD: ${{ secrets.SONATYPE_PGP_PRIVATE_KEY_PASSWORD }} + SONATYPE_USER: ${{ secrets.SONATYPE_USER }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + LANG: "en_US.UTF-8" + LC_MESSAGES: "en_US.UTF-8" + LC_ALL: "en_US.UTF-8" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 9 + - name: Publish to Maven Central + run: | + if [[ $(git tag --points-at HEAD) != '' ]]; then + echo $SONATYPE_PGP_PRIVATE_KEY | base64 --decode > gpg_key + gpg --import --no-tty --batch --yes gpg_key + rm gpg_key + ./mill -i mill.scalalib.PublishModule/publishAll \ + --sonatypeCreds $SONATYPE_USER:$SONATYPE_PASSWORD \ + --gpgArgs --passphrase=$SONATYPE_PGP_PRIVATE_KEY_PASSWORD,--no-tty,--pinentry-mode,loopback,--batch,--yes,-a,-b \ + --publishArtifacts __.publishArtifacts \ + --readTimeout 600000 \ + --awaitTimeout 600000 \ + --release true \ + --signed true + fi + - name: Create GitHub Release + id: create_gh_release + uses: actions/create-release@v1.1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: + draft: false + + generate_docs: + if: github.repository == 'com-lihaoyi/cask' && contains(github.ref, 'refs/tags/') + needs: publish-sonatype + runs-on: ubuntu-20.04 + env: + LANG: "en_US.UTF-8" + LC_MESSAGES: "en_US.UTF-8" + LC_ALL: "en_US.UTF-8" + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 8 + - name: Generate Website + run: | + set -eux + curl -L -o ~/amm https://github.com/lihaoyi/Ammonite/releases/download/1.1.0/2.12-1.1.0 && chmod +x ~/amm + cd docs + ~/amm build.sc + - name: Deploy Website + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/target + publish_branch: gh-pages diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e815104b38..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: scala -sudo: required -dist: trusty - -matrix: - include: - - stage: build - script: ci/test.sh - jdk: oraclejdk9 - - - stage: build - script: ci/test.sh - jdk: oraclejdk8 - - - stage: release - script: "ci/on-master.py ci/release-github.sh" - jdk: oraclejdk9 - - stage: release - script: "ci/on-master.py ci/release-sonatype.sh" - jdk: oraclejdk9 - - stage: release - script: "ci/on-master.py ci/publish-docs.sh" - jdk: oraclejdk8 - -cache: - directories: - - $HOME/.coursier diff --git a/build.sc b/build.sc index e02af644a6..652c5002b6 100644 --- a/build.sc +++ b/build.sc @@ -1,6 +1,5 @@ import mill._, scalalib._, scalajslib._, publish._ -import $file.ci.upload, $file.ci.version import $file.example.compress.build import $file.example.compress2.build import $file.example.compress3.build @@ -25,6 +24,8 @@ import $file.example.websockets.build import $file.example.websockets2.build import $file.example.websockets3.build import $file.example.websockets4.build +import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version_mill0.9:0.1.1` +import de.tobiasroeser.mill.vcs.version.VcsVersion val scala213 = "2.13.5" val scala3 = "3.0.0" @@ -33,7 +34,7 @@ val dottyCustomVersion = Option(sys.props("dottyVersion")) trait CaskModule extends CrossScalaModule with PublishModule{ def isDotty = crossScalaVersion.startsWith("3") - def publishVersion = build.publishVersion()._2 + def publishVersion = VcsVersion.vcsState().format() def pomSettings = PomSettings( description = artifactName(), @@ -190,76 +191,3 @@ object example extends Module{ object websockets4 extends Cross[Websockets4Module](allVersions: _*) } - -def publishVersion = T.input($file.ci.version.publishVersion) -def gitHead = T.input($file.ci.version.gitHead) - -def uploadToGithub(authKey: String) = T.command{ - val (releaseTag, label) = publishVersion() - - if (releaseTag == label){ - requests.post( - "https://api.github.com/repos/lihaoyi/cask/releases", - data = ujson.write( - ujson.Obj( - "tag_name" -> releaseTag, - "name" -> releaseTag - ) - ), - headers = Seq("Authorization" -> s"token $authKey") - ) - } - - val examples = Seq( - $file.example.compress.build.millSourcePath, - $file.example.compress2.build.millSourcePath, - $file.example.compress3.build.millSourcePath, - $file.example.cookies.build.millSourcePath, - $file.example.decorated.build.millSourcePath, - $file.example.decorated2.build.millSourcePath, - $file.example.endpoints.build.millSourcePath, - $file.example.formJsonPost.build.millSourcePath, - $file.example.httpMethods.build.millSourcePath, - $file.example.minimalApplication.build.millSourcePath, - $file.example.minimalApplication2.build.millSourcePath, - $file.example.redirectAbort.build.millSourcePath, - $file.example.scalatags.build.millSourcePath, - $file.example.staticFiles.build.millSourcePath, - $file.example.staticFiles2.build.millSourcePath, - $file.example.todo.build.millSourcePath, - $file.example.todoApi.build.millSourcePath, - $file.example.todoDb.build.millSourcePath, - $file.example.twirl.build.millSourcePath, - $file.example.variableRoutes.build.millSourcePath, - $file.example.websockets.build.millSourcePath, - $file.example.websockets2.build.millSourcePath, - $file.example.websockets3.build.millSourcePath, - $file.example.websockets4.build.millSourcePath, - ) - for(example <- examples){ - val f = T.ctx().dest - val last = example.last + "-" + label - os.copy(example, f / last) - os.write.over( - f / last / "mill", - os.read(os.pwd / "mill") - ) - os.proc("chmod", "+x", f/last/"mill").call(f/last) - os.write.over( - f / last / "build.sc", - os.read(f / last / "build.sc") - .replaceFirst( - "trait AppModule extends CrossScalaModule\\s*\\{", - "object app extends ScalaModule \\{\n def scalaVersion = \"2.13.5\"") - .replaceFirst( - "def ivyDeps = Agg\\[Dep\\]\\(", - "def ivyDeps = Agg(\n ivy\"com.lihaoyi::cask:" + releaseTag + "\"," - ) - ) - - os.remove.all(f / "out.zip") - os.proc("zip", "-r", f / "out.zip", last).call(f) - upload.apply(f / "out.zip", releaseTag, last + ".zip", authKey) - } -} - diff --git a/ci/on-master.py b/ci/on-master.py deleted file mode 100755 index 9199f56baa..0000000000 --- a/ci/on-master.py +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env python - -import os, sys, subprocess -is_master_commit = ( - os.environ["TRAVIS_PULL_REQUEST"] == "false" and - (os.environ["TRAVIS_BRANCH"] == "master" or os.environ["TRAVIS_TAG"] != "") -) - -if is_master_commit: - subprocess.check_call(sys.argv[1:]) diff --git a/ci/publish-docs.sh b/ci/publish-docs.sh deleted file mode 100755 index 869f2e8d90..0000000000 --- a/ci/publish-docs.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -curl -L -o ~/bin/amm https://github.com/lihaoyi/Ammonite/releases/download/1.1.0/2.12-1.1.0 && chmod +x ~/bin/amm - -cd docs - -echo $GITHUB_DEPLOY_KEY | base64 --decode > deploy_key - -eval "$(ssh-agent -s)" -chmod 600 deploy_key -ssh-add deploy_key -rm deploy_key - - -git config --global user.email "haoyi.sg+travis@gmail.com" -git config --global user.name "Ammonite Travis Bot" - -amm build.sc --publish true \ No newline at end of file diff --git a/ci/release-github.sh b/ci/release-github.sh deleted file mode 100755 index 5904d943f9..0000000000 --- a/ci/release-github.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -eux - - - -./mill uploadToGithub $GITHUB_ACCESS_TOKEN diff --git a/ci/release-sonatype.sh b/ci/release-sonatype.sh deleted file mode 100755 index a0d6324be9..0000000000 --- a/ci/release-sonatype.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -echo $GPG_PRIVATE_KEY_B64 | base64 --decode > gpg_key - -gpg --import gpg_key - -rm gpg_key - -./mill -i mill.scalalib.PublishModule/publishAll \ - --sonatypeCreds lihaoyi:$SONATYPE_PASSWORD \ - --gpgArgs --passphrase,$GPG_PASSWORD,--batch,--yes,-a,-b \ - --signed true \ - --publishArtifacts __.publishArtifacts \ - --release true diff --git a/ci/test.sh b/ci/test.sh deleted file mode 100755 index 3b2554209e..0000000000 --- a/ci/test.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -./mill -i --disable-ticker __.testLocal \ No newline at end of file diff --git a/ci/upload.sc b/ci/upload.sc deleted file mode 100644 index 783f76802c..0000000000 --- a/ci/upload.sc +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env amm -import ammonite.ops._ - -@main -def shorten(longUrl: String) = { - println("shorten longUrl " + longUrl) - val shortUrl = requests.post( - "https://git.io", - data = Seq("url" -> longUrl), - ).headers("location").head - - println("shorten shortUrl " + shortUrl) - shortUrl -} -@main -def apply(uploadedFile: Path, - tagName: String, - uploadName: String, - authKey: String): String = { - val body = requests.get( - s"https://api.github.com/repos/lihaoyi/cask/releases/tags/$tagName", - headers = Seq("Authorization" -> s"token $authKey") - ).text - - val parsed = ujson.read(body) - - println(body) - - val snapshotReleaseId = parsed("id").num.toInt - - - val uploadUrl = - s"https://uploads.github.com/repos/lihaoyi/cask/releases/" + - s"$snapshotReleaseId/assets?name=$uploadName" - - val res = requests.post( - uploadUrl, - data = read.bytes! uploadedFile, - headers = Seq( - "Content-Type" -> "application/octet-stream", - "Authorization" -> s"token $authKey" - ), - connectTimeout = 5000, readTimeout = 60000 - ) - - - println(res.text) - val longUrl = ujson.read(res.text)("browser_download_url").str.toString - - println("Long Url " + longUrl) - - val shortUrl = shorten(longUrl) - - println("Short Url " + shortUrl) - shortUrl -} diff --git a/docs/build.sc b/docs/build.sc index e6c0f1f8bb..347acd84b3 100644 --- a/docs/build.sc +++ b/docs/build.sc @@ -198,13 +198,4 @@ def main(publish: Boolean = false) = { ) ) } - - if (publish){ - implicit val wd = cwd/'target - %git 'init - %git('add, "-A", ".") - %git('commit, "-am", "first commit") - %git('remote, 'add, 'origin, "git@github.com:lihaoyi/cask.git") - %git('push, "-uf", 'origin, "master:gh-pages") - } } \ No newline at end of file