diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f11e8d2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +name: Continuous Integration + +on: + pull_request: + branches: ['**'] + push: + branches: [ master ] + tags: [ "*" ] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: Build and Test + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + distribution: temurin + java: 17 + - os: ubuntu-latest + distribution: temurin + java: 21 + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: "${{ matrix.distribution }}" + java-version: "${{ matrix.java }}" + + - name: Setup sbt + uses: sbt/setup-sbt@v1 + + - name: Build project + run: sbt test scripted + + - name: Compress target directories + run: tar cf targets.tar target sbt-protofetch/target project/target + + - name: Upload target directories + uses: actions/upload-artifact@v4 + with: + name: target-${{ matrix.java }} + path: targets.tar + + publish: + name: Publish Artifacts + needs: [build] + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master') + runs-on: ubuntu-latest + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java (temurin@17) + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Setup sbt + uses: sbt/setup-sbt@v1 + + - name: Download target directories + uses: actions/download-artifact@v4 + with: + name: target-17 + + - name: Inflate target directories + run: | + tar xf targets.tar + rm targets.tar + + - name: Publish project + env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + run: sbt ci-release 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/build.sbt b/build.sbt index 2870f01..bd94719 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ val versions = new { val munit = "1.0.2" } -val common = Seq( +val common: Seq[Setting[_]] = Seq( organizationName := "Coralogix Ltd.", organization := "com.coralogix", startYear := Some(2024), @@ -21,6 +21,7 @@ lazy val `sbt-protofetch` = (project in file("sbt-protofetch")) .enablePlugins(SbtPlugin) .settings(common) .settings( + common, pluginCrossBuild / sbtVersion := versions.sbt, libraryDependencies ++= Seq( "org.apache.commons" % "commons-compress" % versions.commonsCompress,