Skip to content

Commit

Permalink
DAT-18303 DevOps :: Add Dry Run capabilities to extensions (#253)
Browse files Browse the repository at this point in the history
* 🔧 (create-release.yml): Add support for dry-run flag and dry-run version in the workflow to create a dry-run release
🔧 (extension-attach-artifact-release.yml): Implement logic to build and package artifacts for a dry-run release if the dry-run flag is set to true
✨ (extension-dry-run.yml): Introduce a new workflow for executing a dry-run release, including creating a draft release, getting the draft release ID, and attaching artifacts to the dry-run release.

* 🔧 (extension-attach-artifact-release.yml): change 'dryRun' to 'dry_run' for consistency and readability
🔧 (extension-dry-run.yml): change 'dryRun' to 'dry_run' for consistency and readability

* 🔧 (create-release.yml): update step id from 'create-release' to 'create-dry-run-release' for clarity and consistency

* 🔧 (extension-attach-artifact-release.yml): rename get-release to get-dry-run-release for clarity and consistency with dry-run process.

* 🔧 (create-release.yml): add name and tag inputs to release-drafter action for better version control
🔧 (extension-dry-run.yml): add cleanup step to delete liquibase dry-run tag and the dry-run draft release for better maintenance and organization of the repository

* 🔧 (create-release.yml): Remove dry_run and dry_run_version inputs as they are no longer needed
🔧 (extension-attach-artifact-release.yml): Remove dry_run_release_id input as it is no longer needed
🔧 (extension-dry-run.yml): Remove dry-run-create-release and dry-run-attach-artifact-to-release jobs as they are no longer needed
🔧 (extension-dry-run.yml): Remove cleanup job as it is no longer needed

* ✨ (extension-attach-artifact-release.yml): Add support for dry-run mode to skip certain steps and use a different version for artifact building and signing in GitHub Actions workflow.

* 🔧 (extension-attach-artifact-release.yml): add conditional check to only run sleep step if dry_run input is false

* 🐛 (extension-dry-run.yml): fix dry_run_version and release_name values to use dots instead of hyphens for better readability and consistency. Update the git push command to delete the tag with the corrected format.

* 🔧 (extension-dry-run.yml): Update dry_run_version to use github.run_number instead of github.run_id for better versioning
🔧 (extension-dry-run.yml): Update release_name to use v0.0.${{ github.run_number }} instead of vdry.run.${{ github.run_id }}
🔧 (extension-dry-run.yml): Update git push command to delete tag v0.0.${{ github.run_number }} instead of vdry.run.${{ github.run_id }}
🔧 (extension-dry-run.yml): Update SLACK_MESSAGE to include github.run_number instead of github.run_id for correct GitHub Actions URL viewing

* 🔧 (extension-attach-artifact-release.yml): update files path to include all files in the target directory for attaching to draft release

* 🔧 (extension-dry-run.yml): cleanup workflow file by removing commented out code and reformatting indentation for better readability.

* ✨ (extension-attach-artifact-release.yml): Update release body to include "Dry Run" prefix for better clarity
🔧 (extension-dry-run.yml): Add support for running a dry run release with specific version and configuration
🔧 (extension-release-published.yml): Implement steps for publishing a dry run release to Maven Central Repository

* 🔧 (extension-dry-run.yml): Remove extension-dry-run workflow file as it is no longer needed.

* 🔧 (extension-release-published.yml): remove unnecessary 'needs: maven-release' from dry-run-release job configuration

* 🔧 (extension-release-published.yml): update Sonatype Nexus staging repository URL to repo.liquibase.net for dry-run deployments

* 📝 (extension-release-published.yml): update release downloader action to use releaseId instead of tag for downloading artifacts

* 📝 (extension-release-published.yml): add dry_run_release_id input parameter to workflow for better customization and control over dry-run releases.

* 🔧 (extension-attach-artifact-release.yml): add shell configuration to specify bash as the shell for the build and package job

* 🔧 (extension-attach-artifact-release.yml): add shell configuration to specify bash as the shell for the script execution

---------

Co-authored-by: Alejandro Alvarez <[email protected]>
  • Loading branch information
jandroav and Alejandro Alvarez authored Sep 6, 2024
1 parent 72db753 commit 352c1d9
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 4 deletions.
85 changes: 82 additions & 3 deletions .github/workflows/extension-attach-artifact-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ on:
required: false
default: false
type: boolean
dry_run:
description: 'Specify it if you want to run a dry run'
required: false
default: false
type: boolean
dry_run_version:
description: 'The version of the dry-run release'
required: false
type: string
secrets:
BOT_TOKEN:
description: 'BOT_TOKEN from the caller workflow'
Expand Down Expand Up @@ -133,12 +142,23 @@ jobs:
${{ inputs.extraLinuxCommand }}
- name: Build and Package
if: ${{ inputs.dry_run == false }}
working-directory: ${{ inputs.artifactPath }}
shell: bash
run: |
mvn -B release:clean release:prepare -Darguments="-Dusername=liquibot -Dpassword=$GITHUB_TOKEN -Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -Dmaven.deploy.skip=true" -DcheckModificationExcludeList=** -DignoreSnapshots=true -DreleaseVersion=${{ github.event.inputs.liquibaseVersion }} -DpushChanges=false -P '${{ inputs.mavenProfiles }}'
git reset HEAD~ --hard
mvn -B dependency:go-offline clean package -DskipTests=true ${{ inputs.extraMavenArgs }}
- name: Build and Package (dry-run)
if: ${{ inputs.dry_run == true }}
working-directory: ${{ inputs.artifactPath }}
shell: bash
run: |
mvn -B release:clean release:prepare -Darguments="-Dusername=liquibot -Dpassword=$GITHUB_TOKEN -Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -Dmaven.deploy.skip=true" -DcheckModificationExcludeList=** -DignoreSnapshots=true -DreleaseVersion=${{ inputs.dry_run_version }} -DpushChanges=false -P '${{ inputs.mavenProfiles }}'
git reset HEAD~ --hard
mvn -B dependency:go-offline clean package -DskipTests=true ${{ inputs.extraMavenArgs }}
- name: Get Artifact ID
working-directory: ${{ inputs.artifactPath }}
id: get-artifact-id
Expand All @@ -148,13 +168,23 @@ jobs:
echo "artifact_id=$artifact_id" >> $GITHUB_OUTPUT
- name: Get Artifact Version
if: ${{ inputs.dry_run == false }}
working-directory: ${{ inputs.artifactPath }}
id: get-artifact-version
shell: bash
run: |
artifact_version=$(mvn help:evaluate "-Dexpression=project.version" -q -DforceStdout)
echo "artifact_version=$artifact_version" >> $GITHUB_OUTPUT
- name: Get Artifact Version
if: ${{ inputs.dry_run == true }}
working-directory: ${{ inputs.artifactPath }}
id: get-artifact-version-dry-run
shell: bash
run: |
echo "artifact_version=${{ inputs.dry_run_version }}" >> $GITHUB_OUTPUT
- name: Save Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -238,6 +268,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- run: sleep 30
if: ${{ inputs.dry_run == false }}

- uses: actions/checkout@v4

- name: Set up JDK 17
Expand Down Expand Up @@ -315,6 +347,7 @@ jobs:
${{ inputs.extraCommand }}
- name: Check and download artifacts from GPM
if: ${{ inputs.dry_run == false }}
id: check-download-artifacts
env:
ARTIFACT_NAME: ${{ github.event.repository.name }}
Expand All @@ -339,7 +372,7 @@ jobs:
- name: Build release artifacts
working-directory: ${{ inputs.artifactPath }}
if: env.ARTIFACT_FOUND == '0'
if: ${{ env.ARTIFACT_FOUND == '0' && inputs.dry_run == false }}
id: build-release-artifacts
run: |
mvn -B release:clean release:prepare -Darguments="-Dusername=liquibot -Dpassword=$GITHUB_TOKEN -Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -Dmaven.deploy.skip=true" -DcheckModificationExcludeList=** -DignoreSnapshots=true -DreleaseVersion=${{ github.event.inputs.liquibaseVersion }} -DpushChanges=false -P '${{ inputs.mavenProfiles }}'
Expand All @@ -356,6 +389,25 @@ jobs:
LAST_COMMIT_HASH=$(git rev-parse origin/$DEFAULT_BRANCH)
mvn clean install -DskipTests -P '${{ inputs.mavenProfiles }}' -DbuildNumber=$LAST_COMMIT_HASH
- name: Build release artifacts (dry-run)
working-directory: ${{ inputs.artifactPath }}
if: ${{ inputs.dry_run == true }}
id: build-release-artifacts-dry-run
run: |
mvn -B release:clean release:prepare -Darguments="-Dusername=liquibot -Dpassword=$GITHUB_TOKEN -Dmaven.javadoc.skip=true -Dmaven.test.skipTests=true -Dmaven.test.skip=true -Dmaven.deploy.skip=true" -DcheckModificationExcludeList=** -DignoreSnapshots=true -DreleaseVersion=${{ inputs.dry_run_version }} -DpushChanges=false -P '${{ inputs.mavenProfiles }}'
git reset HEAD~ --hard
# Determine the default branch (master or main)
if git rev-parse --verify origin/master >/dev/null 2>&1; then
DEFAULT_BRANCH="master"
elif git rev-parse --verify origin/main >/dev/null 2>&1; then
DEFAULT_BRANCH="main"
else
echo "Neither master nor main branch found. Exiting."
exit 1
fi
LAST_COMMIT_HASH=$(git rev-parse origin/$DEFAULT_BRANCH)
mvn clean install -DskipTests -P '${{ inputs.mavenProfiles }}' -DbuildNumber=$LAST_COMMIT_HASH
- name: Download multiarchitecture release artifacts
if: inputs.combineJars
uses: actions/download-artifact@v4
Expand All @@ -364,14 +416,15 @@ jobs:
path: ${{ inputs.artifactPath }}/target

- name: Get latest draft release ID
if: ${{ inputs.dry_run == false }}
id: get-release
run: |
LATEST_DRAFT_RELEASE=$(curl -X GET -H "Authorization: token ${{ secrets.BOT_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/releases?per_page=1" | jq -r 'if .[].draft == true then .[].id else empty end')
echo "Latest Draft Release ID: $LATEST_DRAFT_RELEASE"
echo "RELEASE_ID=$LATEST_DRAFT_RELEASE" >> $GITHUB_ENV
- name: List artifacts in release
if: env.RELEASE_ID != '' && env.RELEASE_ID != null
if: ${{ env.RELEASE_ID != '' && env.RELEASE_ID != null && inputs.dry_run == false }}
id: list-artifacts
run: |
RELEASE_ID="${{ env.RELEASE_ID }}"
Expand All @@ -381,7 +434,7 @@ jobs:
echo "ARTIFACTS_TO_DELETE=$ARTIFACTS_CLEANED" >> $GITHUB_ENV
- name: Delete artifacts
if: env.ARTIFACTS_TO_DELETE != null
if: ${{ env.ARTIFACTS_TO_DELETE != null && inputs.dry_run == false }}
run: |
RELEASE_ID="${{ env.RELEASE_ID }}"
ARTIFACTS_TO_DELETE="${{ env.ARTIFACTS_TO_DELETE }}"
Expand All @@ -402,6 +455,7 @@ jobs:
run: echo "REPO_ROOT=$(git rev-parse --show-toplevel)" >> $GITHUB_ENV

- name: Sign Files for Draft Release
if: ${{ inputs.dry_run == false }}
working-directory: ${{ inputs.artifactPath }}
run: |
gpg -K
Expand All @@ -411,7 +465,19 @@ jobs:
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}-javadoc.jar
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}-sources.jar
- name: Sign Files for Draft Release (dry-run)
if: ${{ inputs.dry_run == true }}
working-directory: ${{ inputs.artifactPath }}
run: |
gpg -K
version=${{ inputs.dry_run_version }}
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}.jar
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}.pom
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}-javadoc.jar
${{ env.REPO_ROOT }}/.github/sign_artifact.sh ${{ env.REPO_ROOT }}/${{ inputs.artifactPath }}/target/${{ env.artifact_id }}-${version}-sources.jar
- name: Set draft release title
if: ${{ inputs.dry_run == false }}
working-directory: ${{ inputs.artifactPath }}
id: set-release-title
run: |
Expand All @@ -421,6 +487,7 @@ jobs:
curl -X PATCH -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" -H "Authorization: Bearer ${{ secrets.BOT_TOKEN }}" -d '{"name": "'"$RELEASE_TITLE"'", "tag_name": "'"v$version"'"}' "https://api.github.com/repos/${{ github.repository }}/releases/${{ env.RELEASE_ID }}"
- name: Attach Files to Draft Release
if: ${{ inputs.dry_run == false }}
working-directory: ${{ inputs.artifactPath }}
id: upload-release-asset
run: ${{ env.REPO_ROOT }}/.github/upload_asset.sh $(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
Expand All @@ -429,6 +496,18 @@ jobs:
ASSET_NAME_PREFIX: "${{ env.artifact_id }}-"
ASSET_DIR: ./target

- name: Attach Files to Draft Release (dry-run)
id: attach-files-dry-run
if: ${{ inputs.dry_run == true }}
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ inputs.dry_run_version }}
fail_on_unmatched_files: true
body: Dry Run ${{ inputs.dry_run_version }}
generate_release_notes: true
draft: true
files: ./target/*

- name: Get upload_zip.sh Script File
if: inputs.zip == 'true'
run: |
Expand Down
122 changes: 121 additions & 1 deletion .github/workflows/extension-release-published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ on:
required: false
default: true
type: boolean
dry_run:
description: 'Specify it if you want to run a dry run'
required: false
default: false
type: boolean
dry_run_version:
description: 'The version of the dry-run release'
required: false
type: string
dry_run_release_id:
description: 'The release id of the dry-run release'
required: false
type: string
secrets:
SONATYPE_USERNAME:
description: 'SONATYPE_USERNAME from the caller workflow'
Expand Down Expand Up @@ -162,8 +175,115 @@ jobs:
-Dtypes=jar.asc,jar.asc,jar.asc,pom.asc \
-Dclassifiers=,sources,javadoc,
dry-run-release:
if: ${{ inputs.dry_run == true }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'

# look for dependencies in maven
- name: maven-settings-xml-action
uses: whelk-io/maven-settings-xml-action@v21
with:
repositories: |
[
{
"id": "liquibase",
"url": "https://maven.pkg.github.com/liquibase/liquibase",
"releases": {
"enabled": "true"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
},
{
"id": "liquibase-pro",
"url": "https://maven.pkg.github.com/liquibase/liquibase-pro",
"releases": {
"enabled": "true"
},
"snapshots": {
"enabled": "true",
"updatePolicy": "always"
}
},
{
"id": "dry-run-sonatype-nexus-staging",
"url": "https://repo.liquibase.net/repository/dry-run-sonatype-nexus-staging/",
"releases": {
"enabled": "true"
},
"snapshots": {
"enabled": "false"
}
}
]
servers: |
[
{
"id": "liquibase-pro",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
},
{
"id": "liquibase",
"username": "liquibot",
"password": "${{ secrets.LIQUIBOT_PAT }}"
},
{
"id": "dry-run-sonatype-nexus-staging",
"username": "${{ secrets.REPO_LIQUIBASE_NET_USER }}",
"password": "${{ secrets.REPO_LIQUIBASE_NET_PASSWORD }}"
}
]
- name: Configure Git
run: |
git config user.name "liquibot"
git config user.email "[email protected]"
- name: Get Artifact ID
working-directory: ${{ inputs.artifactPath }}
id: get-artifact-id
run: echo "artifact_id=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)" >> $GITHUB_ENV

- name: Download Release Artifacts
uses: robinraju/[email protected]
with:
releaseId: "${{ inputs.dry_run_release_id }}"
filename: "${{ env.artifact_id }}-*"
out-file-path: ${{ inputs.artifactPath }}

- name: Publish to Maven Central
working-directory: ${{ inputs.artifactPath }}
env:
MAVEN_USERNAME: ${{ secrets.REPO_LIQUIBASE_NET_USER }}
MAVEN_PASSWORD: ${{ secrets.REPO_LIQUIBASE_NET_PASSWORD }}
run: |
version=${{ inputs.dry_run_version }}
mvn -B org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file \
-Durl=https://repo.liquibase.net/repository/dry-run-sonatype-nexus-staging/ \
-DrepositoryId=dry-run-sonatype-nexus-staging \
-DpomFile=${{ env.artifact_id }}-${version}.pom \
-DgeneratePom=false \
-Dfile=${{ env.artifact_id }}-${version}.jar \
-Dsources=${{ env.artifact_id }}-${version}-sources.jar \
-Djavadoc=${{ env.artifact_id }}-${version}-javadoc.jar \
-Dfiles=${{ env.artifact_id }}-${version}.jar.asc,${{ env.artifact_id }}-${version}-sources.jar.asc,${{ env.artifact_id }}-${version}-javadoc.jar.asc,${{ env.artifact_id }}-${version}.pom.asc \
-Dtypes=jar.asc,jar.asc,jar.asc,pom.asc \
-Dclassifiers=,sources,javadoc,
deploy_xsd:
if: inputs.nameSpace != '' && inputs.deployToMavenCentral == true
if: inputs.nameSpace != '' && inputs.deployToMavenCentral == true && inputs.dry_run == false
name: Upload xsds
runs-on: ubuntu-20.04
# These permissions are needed to interact with GitHub's OIDC Token endpoint.
Expand Down

0 comments on commit 352c1d9

Please sign in to comment.