From 9ccc980705fb55c46322ef537e34f248cdab9b50 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Wed, 14 Feb 2024 23:53:48 +1100 Subject: [PATCH] Add sbt-github-actions --- .github/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++++ .github/workflows/clean.yml | 60 +++++++++++++++++++++++++++ .github/workflows/publish.yml | 33 --------------- build.sbt | 13 ++++++ project/plugins.sbt | 1 + 5 files changed, 151 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/clean.yml delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..15c59f5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +# 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: + branches: ['**'] + tags: [v*] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: Build and Test + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + scala: [2.12.18] + java: [temurin@11, temurin@17, temurin@21] + runs-on: ${{ matrix.os }} + steps: + - name: Ignore line ending differences in git + if: contains(runner.os, 'windows') + shell: bash + run: git config --global core.autocrlf false + + - name: Configure pagefile for Windows + if: contains(runner.os, 'windows') + uses: al-cheb/configure-pagefile-action@v1.4 + with: + minimum-size: 2GB + maximum-size: 8GB + disk-root: 'C:' + + - name: Checkout current branch (full) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@11) + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 11 + cache: sbt + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + cache: sbt + + - name: Setup Java (temurin@21) + if: matrix.java == 'temurin@21' + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: sbt + + - name: Check that workflows are up to date + shell: bash + run: sbt '++ ${{ matrix.scala }}' githubWorkflowCheck + + - shell: bash + run: sbt '++ ${{ matrix.scala }}' test scripted diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 0000000..bfc865d --- /dev/null +++ b/.github/workflows/clean.yml @@ -0,0 +1,60 @@ +# 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 + 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/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index f015a59..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Publish - -on: - push: - branches: [ "main" ] - -jobs: - sbt: - name: Publish to apache nexus - runs-on: ubuntu-20.04 - if: github.repository == 'apache/incubator-pekko-sbt-paradox' - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - fetch-tags: 0 - - - name: Setup Java 8 - uses: actions/setup-java@v3 - with: - distribution: temurin - java-version: 8 - - - name: Cache Coursier cache - uses: coursier/cache-action@v6.4.0 - - - name: Publish - run: |- - sbt publish - env: - NEXUS_USER: ${{ secrets.NEXUS_USER }} - NEXUS_PW: ${{ secrets.NEXUS_PW }} diff --git a/build.sbt b/build.sbt index b42bc67..44ad485 100644 --- a/build.sbt +++ b/build.sbt @@ -84,3 +84,16 @@ lazy val pekkoPlugin = project IO.write(file, s"pekko.paradox.version=${version.value}") Seq(file) }).settings(publishSettings) + +ThisBuild / githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("test", "scripted"))) + +ThisBuild / githubWorkflowTargetTags ++= Seq("v*") +ThisBuild / githubWorkflowPublishTargetBranches := Seq() +ThisBuild / githubWorkflowPublish := Seq() + +ThisBuild / githubWorkflowOSes := Seq("ubuntu-latest", "macos-latest", "windows-latest") + +ThisBuild / githubWorkflowJavaVersions := Seq( + JavaSpec.temurin("11"), + JavaSpec.temurin("17"), + JavaSpec.temurin("21")) diff --git a/project/plugins.sbt b/project/plugins.sbt index a87033b..298794a 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -23,3 +23,4 @@ addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") addSbtPlugin("org.mdedetrich" % "sbt-apache-sonatype" % "0.1.10") addSbtPlugin("com.github.pjfanning" % "sbt-source-dist" % "0.1.10") addSbtPlugin("net.bzzt" % "sbt-reproducible-builds" % "0.31") +addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.23.0")