Skip to content

[Release] Updating versions #239

[Release] Updating versions

[Release] Updating versions #239

Workflow file for this run

name: Build project
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop, master, increment/*, release/* ]
workflow_dispatch:
jobs:
build:
name: ⏳ Build, test and deploy artifacts
runs-on: judong
timeout-minutes: 30
env:
SIGN_KEY_ID: ${{ secrets.GPG_KEYNAME }}
SIGN_KEY_PASS: ${{ secrets.GPG_PASSPHRASE }}
SIGN_KEY: ${{ secrets.GPG_SECRET_KEYS }}
if: ${{ github.event.pull_request.user.login != 'dependabot[bot]' }}
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: ⬇️ Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: 🛠️ Project context
id: context
uses: zero88/gh-project-context@v1.2
- name: 🧹 Remove toolchains.xml
run: rm $HOME/.m2/toolchains.xml || true
- name: 🛠️ Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'zulu'
- name: 🔢 Get the current PR number
uses: jwalton/gh-find-current-pr@v1
id: current-pr
with:
state: open
- name: 🧹 Remove settings.xml
run: rm $HOME/.m2/settings.xml || true
- name: 🛠️ Setup maven settings.xml
uses: whelk-io/maven-settings-xml-action@v21
with:
servers: >
[
{
"id": "judong-nexus-mirror",
"username": "${{ secrets.JUDONG_NEXUS_USERNAME }}",
"password": "${{ secrets.JUDONG_NEXUS_PASSWORD }}"
},
{
"id": "judong-nexus-distribution",
"username": "${{ secrets.JUDONG_NEXUS_USERNAME }}",
"password": "${{ secrets.JUDONG_NEXUS_PASSWORD }}"
},
{
"id": "ossrh",
"username": "${{ secrets.SONATYPE_USERNAME }}",
"password": "${{ secrets.SONATYPE_PASSWORD }}"
}
]
mirrors: >
[
{
"id": "judong-nexus-mirror",
"mirrorOf": "*",
"url": "https://nexus.judo.technology/repository/maven-judong/"
}
]
- name: 🔢 Calculate version number
id: version
run: |-
POM_VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dtycho.mode=maven -DskipModules=true -Dexpression=project.version -q -DforceStdout)
if [[ "${POM_VERSION}" == *-SNAPSHOT ]]; then
BASE_VERSION=$(echo "${POM_VERSION}" | cut -d'-' -f 1)
else
BASE_VERSION=${POM_VERSION}
fi
if [[ "${{ github.base_ref }}" == "master" ]]; then
VERSION_NUMBER=${BASE_VERSION}
else
TAG_NAME=$(echo "${{ steps.context.outputs.branch }}" | cut -d ' ' -f2 | tr '#\/\.-' '_')
VERSION_NUMBER=${BASE_VERSION}.$(date +%Y%m%d_%H%M%S)_${{ steps.context.outputs.shortCommitId }}_${TAG_NAME//[(\)]}
fi
echo "Version from POM: ${POM_VERSION}"
echo "Base version from POM: ${BASE_VERSION}"
echo "Building version: ${VERSION_NUMBER}"
echo "version=${VERSION_NUMBER}" >> $GITHUB_OUTPUT
##########################
# MAVEN BUILD START
##########################
# Phase 1 - Build and deploy to judong nexus
- name: 🔥 Build with Maven (build, test)
run: |-
./mvnw -B -Dstyle.color=always \
-Drevision=${{ steps.version.outputs.version }} \
-Psign-artifacts \
-Prelease-judong \
deploy
# Phase 2 - Build and deploy to maven central
- name: 🎁 Deploy with Maven (central)
if: ${{ always() && startsWith(github.head_ref, 'release') && job.status == 'success' }}
run: |-
./mvnw -B -Dstyle.color=always \
-Drevision=${{ steps.version.outputs.version }} \
-DdeployOnly \
-P"release-central,sign-artifacts,-verify-feature" \
-Dmaven.test.skip=true \
deploy
# - name: 🔎 Sonar Metrics
# if: steps.context.outputs.branch == 'develop'
# continue-on-error: true
# run: |-
# ./mvnw -B -Dstyle.color=always \
# -Dsonar.projectKey=judo-jsl-springboot \
# -Dsonar.host.url=https://sonar.judo.technology \
# -Dsonar.login=${{ secrets.JUDO_SONAR_TOKEN }} \
# sonar:sonar
##########################
# MAVEN BUILD END
##########################
- name: 📌 Create version tag
uses: actions/github-script@v6
with:
github-token: ${{ secrets.OSS_PAT }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.version.outputs.version }}',
sha: context.sha
})
- name: 📌 Tag to trigger PR merge on increment / release branch
if: |-
${{ always() &&
(startsWith(github.head_ref, 'increment') || startsWith(github.head_ref, 'release')) &&
job.status == 'success' }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.OSS_PAT }}
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/merge-pr/${{ steps.current-pr.outputs.pr }}',
sha: context.sha
})
- name: 🏗️ Build Changelog
id: create_changelog
uses: mikepenz/release-changelog-builder-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
toTag: v${{ steps.version.outputs.version }}
- name: 📖 Create release
if: |-
${{ always() &&
(startsWith(github.head_ref, 'develop') || github.ref == 'refs/heads/develop') &&
job.status == 'success' }}
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: v${{ steps.version.outputs.version }}
tag: v${{ steps.version.outputs.version }}
generateReleaseNotes: false
body: ${{steps.create_changelog.outputs.changelog}}
draft: false
prerelease: true
- name: 🎤 Create message
id: message
if: ${{ always() }}
run: |-
if [ "${{ job.status }}" == "success" ]; then
message=":white_check_mark: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
message="${message} Version: ${{ steps.version.outputs.version }}"
fi
if [ "${{ job.status }}" == "failure" ]; then
message=":x: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
fi
if [ "${{ job.status }}" == "canceled" ]; then
message=":x: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
fi
echo "message=${message}" >> $GITHUB_OUTPUT
- name: 📢 Send message to discord
uses: sarisia/actions-status-discord@v1
if: always()
with:
webhook: ${{ secrets.JUDONG_DISCORD_WEBHOOK }}
title: "Github action"
description: "${{ steps.message.outputs.message }}"