Release Maven Artifacts #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Maven Artifacts | |
on: | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Release tag name' | |
required: true | |
release: | |
types: [released, prereleased] | |
env: | |
# The values are extracted from the github.event context, | |
# which is only available when the workflow gets triggered by a release event. | |
RELEASE_VERSION: ${{ github.event.release.name }} | |
BRANCH: ${{ github.event.release.target_commitish }} | |
jobs: | |
release-maven: | |
if: github.repository_owner == 'Apicurio' && (github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, '3.')) | |
runs-on: ubuntu-20.04 | |
timeout-minutes: 30 | |
env: | |
RELEASE_TYPE: release | |
steps: | |
- name: Fetch Release Details | |
if: github.event_name == 'workflow_dispatch' | |
run: | | |
touch release.json && curl https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/tags/${{ github.event.inputs.tag }} > release.json | |
echo "RELEASE_VERSION=$(cat release.json | jq -r '.name')" >> $GITHUB_ENV | |
echo "BRANCH=$(cat release.json | jq -r '.target_commitish')" >> $GITHUB_ENV | |
- name: Download Source Code | |
run: | | |
git config --global user.name "apicurio-ci" | |
git config --global user.email "apicurio.ci@gmail.com" | |
git clone --branch $RELEASE_VERSION --single-branch https://apicurio-ci:${{ secrets.ACCESS_TOKEN }}@github.com/Apicurio/apicurio-registry.git registry | |
# We have faced issues in the past where a github release was created from a wrong commit | |
# This step will ensure that the release was created from the right commit | |
- name: Verify Project Version | |
run: | | |
cd registry | |
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
if [[ $PROJECT_VERSION != $RELEASE_VERSION ]] | |
then | |
echo "ERROR: Project Version '${PROJECT_VERSION}' does not match with Released Version '${RELEASE_VERSION}'" | |
exit 1 | |
fi | |
- name: Set up settings.xml | |
run: | | |
pwd | |
mkdir -p /home/runner/.m2 | |
chmod 755 /home/runner/.m2 | |
echo "<settings><servers><server><id>${{ secrets.OSSRH_ID }}</id><username>${{ secrets.OSSRH_USERNAME }}</username><password>${{ secrets.OSSRH_TOKEN }}</password></server></servers><profiles><profile><id>${{ secrets.OSSRH_ID }}</id><activation><activeByDefault>true</activeByDefault></activation><properties><gpg.executable>gpg</gpg.executable><gpg.passphrase>${{ secrets.GPG_PASSPHRASE}}</gpg.passphrase></properties></profile></profiles></settings>" > /home/runner/.m2/settings.xml | |
cat /home/runner/.m2/settings.xml | |
- name: Import GPG Key | |
uses: crazy-max/ghaction-import-gpg@f6f458f535f4ccdf100400ee0755c0e857226a66 | |
env: | |
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Maven Deploy | |
run: | | |
cd registry | |
# Retry 3 times before the steps actually fails | |
(echo "===== Maven Deploy Attempt: 1 ====" && mvn deploy --batch-mode -Pprod -Psql -Pmssql -Pkafkasql -Prelease -DskipTests --settings /home/runner/.m2/settings.xml) || \ | |
(echo "===== Maven Deploy Attempt: 2 ====" && mvn deploy --batch-mode -Pprod -Psql -Pmssql -Pkafkasql -Prelease -DskipTests --settings /home/runner/.m2/settings.xml) || \ | |
(echo "===== Maven Deploy Attempt: 3 ====" && mvn deploy --batch-mode -Pprod -Psql -Pmssql -Pkafkasql -Prelease -DskipTests --settings /home/runner/.m2/settings.xml) || \ | |
(echo "==== Maven Deploy Step Failed ====" && exit 1) | |
- name: Google Chat Notification | |
if: ${{ failure() }} | |
uses: Co-qn/google-chat-notification@b9227d9daa4638c9782a5bd16c4abb86268127a1 | |
with: | |
name: ${{ github.job }} | |
url: ${{ secrets.GOOGLE_CHAT_WEBHOOK }} | |
status: ${{ job.status }} |