Skip to content

Commit

Permalink
optimize publishing to Azure feeds and create a release workflow to c…
Browse files Browse the repository at this point in the history
…reate release tags (#1766)
  • Loading branch information
bekiroguz authored Sep 30, 2024
1 parent 1423620 commit 72414bd
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
22 changes: 3 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: CI
on:
workflow_dispatch:
pull_request:
branches: ["master"]
push:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
22 changes: 16 additions & 6 deletions project/Publish.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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 := (
Expand Down

0 comments on commit 72414bd

Please sign in to comment.