diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2d557408..8503d8f01 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,60 +1,123 @@ -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. -env: - JAVA_OPTS: "-Dfile.encoding=UTF-8 -Xms1024M -Xmx3072M -Xss4M" +name: Continuous Integration on: - push: - branches: '**' - tags: [ "v[0-9]+*" ] pull_request: - # avoid duplicate checks (push & PR) further in the review process - types: [opened] + branches: ['**'] + push: + branches: ['**'] + tags: [v*] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + JAVA_OPTS: '-Dfile.encoding=UTF-8 -Xmx4G' jobs: - test: - name: Run tests - runs-on: ubuntu-22.04 # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md + build: + name: Build and Test strategy: fail-fast: false matrix: - scala: [ 2.13.16 ] - java-version: [ 17, 21, 25 ] - command: [ udash-jvm/test, udash-js/test, guide-selenium/test ] + os: [ubuntu-latest] + scala: [2.13.16] + java: [temurin@17, temurin@21, temurin@25] + command: [udash-jvm/test, udash-js/test, guide-selenium/test] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-java@v4 + - name: Checkout current branch (full) + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v5 with: distribution: temurin - java-version: ${{ matrix.java-version }} + java-version: 17 cache: sbt - - uses: actions/setup-node@v4 + + - name: Setup Java (temurin@21) + if: matrix.java == 'temurin@21' + uses: actions/setup-java@v5 with: - cache: npm + distribution: temurin + java-version: 21 + cache: sbt + + - name: Setup Java (temurin@25) + if: matrix.java == 'temurin@25' + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 25 + cache: sbt + + - name: Setup sbt + uses: sbt/setup-sbt@v1 + + - name: Setup Node.js + uses: actions/setup-node@v4 + - name: Install npm dependencies run: npm install + + - name: Check that workflows are up to date + run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck + - name: Run tests - run: sbt ++${{ matrix.scala }} ${{ matrix.command }} + run: sbt '++ ${{ matrix.scala }}' '${{ matrix.command }}' publish: - name: Publish to Sonatype - # only run on tag push - if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/v')) - needs: [ test ] - runs-on: ubuntu-22.04 + name: Publish Artifacts + needs: [build] + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v')) + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.13.16] + java: [temurin@17] + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v4 - - name: Set up JDK - uses: actions/setup-java@v4 + - name: Checkout current branch (full) + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v5 with: distribution: temurin java-version: 17 cache: sbt - - name: Get version - id: get_tag_name - run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT - - name: Publish artifacts - env: + + - name: Setup Java (temurin@21) + if: matrix.java == 'temurin@21' + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 21 + cache: sbt + + - name: Setup Java (temurin@25) + if: matrix.java == 'temurin@25' + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: 25 + cache: sbt + + - name: Setup sbt + uses: sbt/setup-sbt@v1 + + - env: PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_SECRET: ${{ secrets.PGP_SECRET }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 000000000..4bb28c89d --- /dev/null +++ b/.github/workflows/clean.yml @@ -0,0 +1,63 @@ +# 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 + +permissions: + actions: write + +jobs: + delete-artifacts: + name: Delete Artifacts + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Delete artifacts + shell: bash {0} + 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=$(mktemp) + + # 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/.*.*//') + 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 diff --git a/build.sbt b/build.sbt index 73031d0bc..1cd70084f 100644 --- a/build.sbt +++ b/build.sbt @@ -22,6 +22,38 @@ inThisBuild(Seq( developers := List( Developer("ddworak", "Dawid Dworak", "d.dworak@avsystem.com", url("https://github.com/ddworak")), ), + scalaVersion := Dependencies.versionOfScala, + + githubWorkflowTargetTags ++= Seq("v*"), + githubWorkflowArtifactUpload := false, + githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"), JavaSpec.temurin("21"), JavaSpec.temurin("25")), + githubWorkflowBuildPreamble ++= Seq( + WorkflowStep.Use( + ref = UseRef.Public("actions", "setup-node", "v4"), + name = Some("Setup Node.js"), + ), + WorkflowStep.Run( + commands = List("npm install"), + name = Some("Install npm dependencies") + ) + ), + githubWorkflowPublishTargetBranches := Seq(RefPredicate.StartsWith(Ref.Tag("v"))), + githubWorkflowEnv += "JAVA_OPTS" -> "-Dfile.encoding=UTF-8 -Xmx4G", + githubWorkflowBuildMatrixFailFast := Some(false), + githubWorkflowBuildMatrixAdditions += "command" -> List("udash-jvm/test", "udash-js/test", "guide-selenium/test"), + githubWorkflowBuild := Seq(WorkflowStep.Sbt( + commands = List("${{ matrix.command }}"), + name = Some("Run tests"), + )), + 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 forIdeaImport = System.getProperty("idea.managed", "false").toBoolean && System.getProperty("idea.runid") == null @@ -34,8 +66,6 @@ val browserCapabilities: Capabilities = { } val commonSettings = Seq( - scalaVersion := Dependencies.versionOfScala, - crossScalaVersions := Seq(Dependencies.versionOfScala), scalacOptions ++= Seq( "-feature", "-deprecation", diff --git a/project/plugins.sbt b/project/plugins.sbt index bc55418e7..4cd030576 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -10,4 +10,5 @@ addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.3") addSbtPlugin("com.github.sbt" % "sbt-less" % "2.0.1") addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.4") addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.11.2") -addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.8") \ No newline at end of file +addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.8") +addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.28.0") \ No newline at end of file