From 72414bdb01763854ec97720314ca101b66fbe980 Mon Sep 17 00:00:00 2001 From: Bekir Oguz Date: Mon, 30 Sep 2024 10:46:14 +0200 Subject: [PATCH] optimize publishing to Azure feeds and create a release workflow to create release tags (#1766) --- .github/workflows/ci.yml | 22 +++---------------- .github/workflows/release.yml | 41 +++++++++++++++++++++++++++++++++++ project/Publish.scala | 22 ++++++++++++++----- 3 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3387438a6..0aa99a5f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,5 @@ name: CI on: - workflow_dispatch: pull_request: branches: ["master"] push: @@ -44,10 +43,8 @@ jobs: contents: write pull-requests: write name: Publish to Sonatype - # Publish to Sonatype only on tags starting with 'v' and on workflow_dispatch - if: | - github.event_name == 'workflow_dispatch' || - (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) + # Publish to Sonatype only on tags starting with 'v' + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') needs: [ci] runs-on: ubuntu-latest steps: @@ -87,20 +84,7 @@ jobs: java-version: 17 cache: sbt - name: Publish to Azure - run: |- - echo "Prepare credentials" - CONTENTS=$(cat << EOF - realm=pkgs.dev.azure.com - host=pkgs.dev.azure.com - user=$AZURE_FEEDUSER - password=$AZURE_FEEDPASSWORD - EOF - ) - echo "$CONTENTS" > ~/.credentials - - sbt "clean; +aetherDeploy; project interaction-example-make-payment-and-ship-items; +aetherDeploy; project interaction-example-reserve-items; +aetherDeploy; project bakery-client-example; +aetherDeploy; project bakery-kafka-listener-example; +aetherDeploy" - - rm ~/.credentials + run: sbt "clean; +aetherDeploy; project interaction-example-make-payment-and-ship-items; +aetherDeploy; project interaction-example-reserve-items; +aetherDeploy; project bakery-client-example; +aetherDeploy; project bakery-kafka-listener-example; +aetherDeploy" env: AZURE_FEEDUSER: ${{ secrets.AZURE_FEEDUSER }} AZURE_FEEDPASSWORD: ${{ secrets.AZURE_FEEDPASSWORD }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..66006caa5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release +on: + workflow_dispatch: + inputs: + release_tag: + description: 'Please specify the release version. i.e. v1.0.0 (must start with "v") with an optional suffix like -RC1' + required: true + type: string + +permissions: + contents: read + +jobs: + release: + name: Release + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.PAT_GIT_TAG_PUSH }} + + - name: Check release tag format + run: | + if [[ ! "${{ inputs.release_tag }}" =~ ^v[0-9]+(\.[0-9]+)*(-[A-Za-z0-9]+)?$ ]]; then + echo "Error: release_tag must start with 'v' followed by a version number i.e. v4.1.0, optionally with a suffix like -RC1." + exit 1 + fi + + - name: Set Git user name and email + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + + - name: Create release tag and push (triggers the CI run) + run: |- + git tag ${{ inputs.release_tag }} -m "${{ inputs.release_tag }}" + git push origin ${{ inputs.release_tag }} diff --git a/project/Publish.scala b/project/Publish.scala index 181594134..19f039112 100644 --- a/project/Publish.scala +++ b/project/Publish.scala @@ -7,7 +7,7 @@ object Publish { lazy val settings = if (sys.env.contains("AZURE_FEEDURL")) PublishToAzure - else if ( (sys.env.contains("SONATYPE_USERNAME"))) ReleaseToSonatype + else if ( (sys.env.contains("SONATYPE_USERNAME"))) PublishToSonatype else SuppressJavaDocs import aether.AetherKeys._ @@ -18,18 +18,28 @@ object Publish { packageSrc / publishArtifact := true ) + // `sbt aetherDeploy` will publish artifacts to the Azure Artifacts repository val PublishToAzure = inThisBuild(List( - dynverSeparator := "-" + dynverSeparator := "-", + version := version.value.replace("-SNAPSHOT", ""), )) ++ List( - credentials += Credentials(Path.userHome / ".credentials"), - publishTo := Some("pkgs.dev.azure.com" at sys.env.getOrElse("AZURE_FEEDURL", "")), - publishMavenStyle := true + credentials += Credentials( + "Azure Artifacts", + "pkgs.dev.azure.com", + sys.env.getOrElse("AZURE_FEEDUSER", ""), + sys.env.getOrElse("AZURE_FEEDPASSWORD", "") + ), + publishTo := Some("Azure Artifacts" at sys.env.getOrElse("AZURE_FEEDURL", "")), + publishMavenStyle := true, + sonatypeCredentialHost := "" ) - val ReleaseToSonatype = inThisBuild(List( + // `sbt ci-release` will publish artifacts to the Sonatype repository + val PublishToSonatype = inThisBuild(List( homepage := Some(url("https://github.com/ing-bank/baker")), licenses := List(License.MIT), dynverSeparator := "-", + version := version.value.replace("-SNAPSHOT", ""), )) ++ List( sonatypeProfileName := "com.ing", pomExtra := (