From b6d4b145d5f21bd6f00489585e1da3e5d4961490 Mon Sep 17 00:00:00 2001 From: Matthew de Detrich Date: Mon, 11 Apr 2022 12:48:12 +0200 Subject: [PATCH] Replace travis with GitHub actions (#28) --- .github/workflows/ci.yml | 147 ++++++++++++++++++++++++++++++++++++ .github/workflows/clean.yml | 59 +++++++++++++++ .travis.yml | 40 ---------- build.sbt | 32 ++++++-- project/plugins.sbt | 8 +- 5 files changed, 236 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/clean.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..8f99f56 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,147 @@ +# 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: [master, main] + push: + branches: [master, main] + tags: [v*] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: Build and Test + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.12.15] + java: [temurin@8, temurin@11, temurin@17] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@8) + if: matrix.java == 'temurin@8' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 8 + + - name: Setup Java (temurin@11) + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 11 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 17 + + - 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 ++${{ matrix.scala }} githubWorkflowCheck + + - name: Build project + run: sbt ++${{ matrix.scala }} test + + - name: Compress target directories + run: tar cf targets.tar target project/target + + - name: Upload target directories + uses: actions/upload-artifact@v2 + with: + name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }} + path: targets.tar + + publish: + name: Publish Artifacts + needs: [build] + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v')) + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.12.15] + java: [temurin@8] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@8) + if: matrix.java == 'temurin@8' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 8 + + - name: Setup Java (temurin@11) + if: matrix.java == 'temurin@11' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 11 + + - name: Setup Java (temurin@17) + if: matrix.java == 'temurin@17' + uses: actions/setup-java@v2 + with: + distribution: temurin + java-version: 17 + + - 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.12.15) + uses: actions/download-artifact@v2 + with: + name: target-${{ matrix.os }}-2.12.15-${{ matrix.java }} + + - name: Inflate target directories (2.12.15) + 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 ++${{ matrix.scala }} ci-release diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 0000000..547aaa4 --- /dev/null +++ b/.github/workflows/clean.yml @@ -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/.*.*//') + 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/.travis.yml b/.travis.yml deleted file mode 100644 index f170cdf..0000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: scala -jdk: openjdk11 -scala: 2.12.10 - -jobs: - include: - - stage: test - script: sbt scalafmtCheck scalafmtSbtCheck - name: "Formatting check" - - script: sbt ";^test ;^scripted" - name: "Tests run" - - stage: publish - script: sbt ";^publish" - name: "Publish" - -stages: - - name: test # runs on master commits and PRs - if: NOT tag =~ ^v - - name: publish # runs on main repo master commits or version-tagged commits - if: repo = lightbend/sbt-paradox-dependencies AND ( ( branch = master AND type = push ) OR tag =~ ^v ) - -cache: - directories: - - $HOME/.sbt - - $HOME/cache/coursier/v1 - -before_cache: - - find $HOME/.ivy2/cache -name "ivydata-*.properties" -print -delete - - find $HOME/.sbt -name "*.lock" -print -delete - -notifications: - email: - on_success: never - -env: - global: - # travis encrypt BINTRAY_USER=... - - secure: "ZhnhCYL6LAWrAWljMB690IjBsATtxA0GkvtzAejYd/RLtMcc0pndLkqBWQCkflibpypi4h5VyIvtZ5c1h8I0x5N2Und0zROchCyumfa5C0vEnILetJIcWFA+fisqaLxljQpLE5wCa59laQpzwSOUwtdF9Sa7pWjo2fnhInabbBwzCEVjLlqdAb6cZz5pUdkoo3vQxoO4xqFuAfLBLrEiQQgyFnK4/FLcNf+0rFIoNuz9Al0mmc0tRLk+oVHx+MmixZR8xqmzO8UAMTmmOX7ImYrywdwlCagY0RgeonjVIURBzad7D+GiUCaXG1pJ5j7l1Uw4FY3Vye/Qm/OihAmNs0lXqVCoBn6nWztgG33LqPwqQXA8bb5U7qQFFoKooUlASPyic0yxSzmsV3AudZAPmXvmAsyfXADWIUaQlFVCBoe+J4pQ+htn7+pGwydn0Aw9qdpvWUBZM81GFRxcJRl/Zbgt6/oOUBVyjiPsycPtLlcQJC0NWiEldZA1YYXmQA88013P58IqSeUbnyfMboPk0oaYRgq22Ebr28nShrvT+fgO4ypJ62qvqgsueC1jaF3btFKKodhW+eRhXR9OEN1EZLvLbJ4FNS7daPFxI+oanh4JfNfYsZBYOoFQuiZHCOQ+UE3oD3O1Id91QeCCAzwLtKjfDif8z211yQ2vfnVhlpY=" - # travis encrypt BINTRAY_PASS=... - - secure: "ieV7nuLdoMYV76tHy6ymTg8wrvIxrVSBwayLR2tdJ4nqcaoalU37mDpJSs2IQSXW84OU5eGSqUz0oJpHk1SaoZEIcVXgw8zCaPgr0QMB8joHttNUc3jOoxmFwrLmp5lrjBn8LQ52IhMVcgjED3yBpNwzoPPq00sklILkrkbpdqgiwgTnqmt7AOBdCnhnsEeUO4fQ07PqdXvQwE+SQIAF1hh6cQ1BiOWaR2mCjkrI1icXZqCylIloMS6dzv8EZOnFJxFCK2KccDr+607IleWxGKYrNgb8G4ihObc6XvuLiJFGoYxxtx6weYSOWcz1BjYBrHo6AyFkB56uGPwdz+VB5ybWfiKEDXsCqFolHZBfQkrtkUsQ25Vs3etSHgvEcaPnSYROX+wuQKnGUzQNvU4n6C04iuF/DepF8oqR+Txqvkc9i2oolkAkRrOboRmBVJt9adeiB/NWz1WmIwpcKBQAHRG5/PHv8xxaVXYK8ElGI0KOkfhR8RpOIVQ32asGFpDTwlMF/ZccqoybuyG5yrARLseV4NxXQb52TvOApxezvknZmunnwtcQLdzca932Vhq6sdMYBmtOJTNyZDuRjYN1ydcjiKq0caVZFI/4ZZOlgxnDJD+sRzyRrLGWBMvTG3vljTDwCCmI3toQJngK+3XM4JiLbLu2AvpbvEc7ZYSkyiE=" diff --git a/build.sbt b/build.sbt index 3d8cd72..0b0bbfb 100644 --- a/build.sbt +++ b/build.sbt @@ -33,12 +33,32 @@ developers += Developer( organizationName := "Lightbend Inc." startYear := Some(2018) -bintrayOrganization := Some("sbt") -bintrayRepository := "sbt-plugin-releases" - enablePlugins(AutomateHeaderPlugin) scalafmtOnCompile := true -// don't do any API docs -doc / sources := Seq() -packageDoc / publishArtifact := false +ThisBuild / githubWorkflowTargetTags ++= Seq("v*") +ThisBuild / githubWorkflowPublishTargetBranches := + Seq(RefPredicate.StartsWith(Ref.Tag("v"))) +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 }}" + ) + ) +) + +ThisBuild / test / publishArtifact := false +ThisBuild / pomIncludeRepository := (_ => false) +sonatypeProfileName := "com.lightbend" + +ThisBuild / githubWorkflowJavaVersions := List( + JavaSpec.temurin("8"), + JavaSpec.temurin("11"), + JavaSpec.temurin("17") +) + +ThisBuild / githubWorkflowTargetBranches := Seq("master", "main") diff --git a/project/plugins.sbt b/project/plugins.sbt index cb21cbd..e82c594 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1") -addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.5") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")