Skip to content

Commit

Permalink
Migrate to GitHub Actions CI (#50)
Browse files Browse the repository at this point in the history
* Add GitHub Actions CI

* Derive publish version from Git tag

* Remove Travis

* Remove Travis CI files
  • Loading branch information
anatoliykmetyuk authored Sep 10, 2021
1 parent 9fce2f1 commit bb0f725
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 225 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

78 changes: 3 additions & 75 deletions build.sc
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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(),
Expand Down Expand Up @@ -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)
}
}

10 changes: 0 additions & 10 deletions ci/on-master.py

This file was deleted.

20 changes: 0 additions & 20 deletions ci/publish-docs.sh

This file was deleted.

7 changes: 0 additions & 7 deletions ci/release-github.sh

This file was deleted.

16 changes: 0 additions & 16 deletions ci/release-sonatype.sh

This file was deleted.

5 changes: 0 additions & 5 deletions ci/test.sh

This file was deleted.

56 changes: 0 additions & 56 deletions ci/upload.sc

This file was deleted.

9 changes: 0 additions & 9 deletions docs/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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, "[email protected]:lihaoyi/cask.git")
%git('push, "-uf", 'origin, "master:gh-pages")
}
}

0 comments on commit bb0f725

Please sign in to comment.