Skip to content

Improve sbt/gh actions infrastructure #466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 153 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,173 @@
name: CI
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Continuous Integration

on:
pull_request:
branches: ['**']
push:
tags-ignore:
- v*
branches: ['**']
tags: [v*]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the inverse of what we want :) Currently it's all tags except v*

Copy link
Member Author

@armanbilge armanbilge Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #466 (comment), I think it's fine like this?


jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
runs-on: ubuntu-latest
name: Build and Test
strategy:
fail-fast: false
matrix:
scalaversion: ["2.11.12", "2.12.10", "2.13.1"]
scalajsversion: ["1.x", "0.6.x"]
include:
- scalaversion: "2.10.7"
scalajsversion: "0.6.x"
os: [ubuntu-latest]
scala: [2.10.7, 2.11.12, 2.12.10, 2.13.1]
java: [[email protected]]
scalajs: [0.6.28, 1.0.0]
exclude:
- scala: 2.10.7
scalajs: 1.0.0
runs-on: ${{ matrix.os }}
env:
SCALAJS_VERSION: "${{ matrix.scalajsversion == '0.6.x' && '0.6.28' || '' }}"
SCALAJS_VERSION: ${{ matrix.scalajs }}
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v13
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v12
with:
java-version: "[email protected]"
- uses: coursier/cache-action@v6
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck'

- name: Build
run: sbt "++${{ matrix.scalaversion }}" package
run: sbt --client '++${{ matrix.scala }}; package'

- name: Test generate documentation
run: sbt "++${{ matrix.scalaversion }}" doc
run: sbt --client '++${{ matrix.scala }}; doc'

- name: Build examples
run: sbt "++${{ matrix.scalaversion }}" example/compile
run: sbt --client '++${{ matrix.scala }}; example/compile'

- name: scalafmt
run: sbt "++${{ matrix.scalaversion }}" scalafmtCheck
run: sbt --client '++${{ matrix.scala }}; scalafmtCheck'

- name: Readme generation
if: matrix.scalajs == '1.0.0' && matrix.scala == '2.12.10'
run: sbt --client '++${{ matrix.scala }}; readme/run'

- name: Create readme/target directory (if necessary)
run: mkdir -p readme/target

readme:
runs-on: ubuntu-latest
- name: Compress target directories
run: tar cf targets.tar target readme/target example/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
with:
path: targets.tar
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}-${{ matrix.scalajs }}

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
Copy link
Member Author

@armanbilge armanbilge Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's fine, this is where the check is whether to publish or not.

strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.10]
java: [[email protected]]
scalajs: [0.6.28, 1.0.0]
runs-on: ${{ matrix.os }}
env:
SCALAJS_VERSION: ${{ matrix.scalajs }}
steps:
- uses: actions/checkout@v2
- uses: olafurpg/setup-scala@v13
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
java-version: "[email protected]"
- uses: coursier/cache-action@v6
- name: Readme generation
run: sbt readme/run
fetch-depth: 0

- name: Setup Java and Scala
uses: olafurpg/setup-scala@v12
with:
java-version: ${{ matrix.java }}

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.10.7)
if: matrix.scalajs == '0.6.28'
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.10.7-${{ matrix.java }}-${{ matrix.scalajs }}

- name: Inflate target directories (2.10.7)
if: matrix.scalajs == '0.6.28'
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.11.12)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.11.12-${{ matrix.java }}-${{ matrix.scalajs }}

- name: Inflate target directories (2.11.12)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.10)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.12.10-${{ matrix.java }}-${{ matrix.scalajs }}

- name: Inflate target directories (2.12.10)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.1)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-2.13.1-${{ matrix.java }}-${{ matrix.scalajs }}

- name: Inflate target directories (2.13.1)
run: |
tar xf targets.tar
rm targets.tar

- env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt --client '++${{ matrix.scala }}; ci-release'
59 changes: 59 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}

# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }

# A temporary file which receives HTTP response headers.
TMPFILE=/tmp/tmp.$$

# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT

# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do

# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")

# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE

# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))

# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do

# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))

id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
75 changes: 61 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,72 @@ lazy val root = project.in(file(".")).

name := "Scala.js DOM"

lazy val scala210 = "2.10.7"
lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.10"
lazy val scala213 = "2.13.1"
Comment on lines +8 to +11
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to update some of these, I think @sjrd likes to keep them in sync with their respective Scala.js version.

lazy val scalaJS06 = "0.6.28"
lazy val scalaJS1 = "1.0.0"

ThisBuild / crossScalaVersions := {
if (scalaJSVersion.startsWith("1.")) Seq("2.12.10", "2.11.12", "2.13.1")
else Seq("2.12.10", "2.11.12", "2.10.7", "2.13.1")
if (scalaJSVersion.startsWith("1.")) Seq(scala212, scala211, scala213)
else Seq(scala212, scala211, scala210, scala213)
}
ThisBuild / scalaVersion := crossScalaVersions.value.head

ThisBuild / githubWorkflowBuildMatrixAdditions += "scalajs" -> List(scalaJS06, scalaJS1)
ThisBuild / githubWorkflowScalaVersions := List(scala210, scala211, scala212, scala213)
ThisBuild / githubWorkflowBuildMatrixExclusions += MatrixExclude(Map("scala" -> scala210, "scalajs" -> scalaJS1))
ThisBuild / githubWorkflowGeneratedCI ~= { _.map(job => job.copy(env = job.env + ("SCALAJS_VERSION" -> "${{ matrix.scalajs }}"))) }
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)

ThisBuild / githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("package"), name = Some("Build")),
WorkflowStep.Sbt(List("doc"), name = Some("Test generate documentation")),
WorkflowStep.Sbt(List("example/compile"), name = Some("Build examples")),
WorkflowStep.Sbt(List("scalafmtCheck"), name = Some("scalafmt")),
WorkflowStep.Sbt(List("readme/run"), name = Some("Readme generation"), cond = Some(s"matrix.scalajs == '${scalaJS1}' && matrix.scala == '${scala212}'")),
WorkflowStep.Run(List("mkdir -p readme/target"), name = Some("Create readme/target directory (if necessary)")) // Keeps upload step happy
)

ThisBuild / githubWorkflowGeneratedUploadSteps ~= {
_.init :+ WorkflowStep.Use(
name = Some("Upload target directories"),
ref = UseRef.Public("actions", "upload-artifact", "v2"),
params = Map("path" -> "targets.tar", "name" -> "target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}-${{ matrix.scalajs }}")
)
}

ThisBuild / githubWorkflowGeneratedCI ~= { jobs =>
var publish = jobs(1)
publish = publish.copy(matrixAdds = Map("scalajs" -> List(scalaJS06, scalaJS1)))
publish = publish.copy(steps = publish.steps.map {
case step: WorkflowStep.Use if step.name.exists(_.startsWith("Download target directories")) =>
step.copy(params = step.params.mapValues(_ + "-${{ matrix.scalajs }}"))
.copy(cond = if (step.name.exists(_.contains(scala210))) Some(s"matrix.scalajs == '${scalaJS06}'") else None)
case step: WorkflowStep.Run if step.name.exists(_.contains(scala210)) =>
step.copy(cond = Some(s"matrix.scalajs == '${scalaJS06}'"))
case step => step
})
jobs.updated(1, publish)
}
Comment on lines +44 to +56
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole mess is to cross on 0.6 and 1.0, I look forward to deleting it when we merge into master.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah 0.6 is such a pain this late in the game


ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v")))
ThisBuild / githubWorkflowPublish := Seq(WorkflowStep.Sbt(List("ci-release")))
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)

val commonSettings = Seq(
version := "1.2.0-SNAPSHOT",
organization := "org.scala-js",
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings")
)
Expand Down Expand Up @@ -63,16 +121,6 @@ scmInfo := Some(ScmInfo(
"scm:git:[email protected]:scala-js/scala-js-dom.git",
Some("scm:git:[email protected]:scala-js/scala-js-dom.git")))

publishMavenStyle := true

publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}

pomExtra := (
<developers>
<developer>
Expand Down Expand Up @@ -112,7 +160,6 @@ lazy val readme = ScalatexReadme(
source = "Index",
autoResources = Seq("example-opt.js")
).settings(
scalaVersion := "2.12.10",
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),
(Compile / resources) += (example / Compile / fullOptJS).value.data
)
Expand Down
4 changes: 4 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("com.lihaoyi" % "scalatex-sbt-plugin" % "0.3.11")

addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0")

addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.12.0")

addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")