ci: GitHub Actions workflow for automated versioning and tagging #9
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: Build and Publish to GitHub Maven | |
on: | |
push: | |
branches: | |
- '**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: maven | |
- name: Extract current version | |
id: extract_version | |
run: echo "::set-output name=BASE_VERSION::$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" | |
- name: Temporarily bump version | |
id: bump_version | |
run: | | |
BASE_VERSION=${{ steps.extract_version.outputs.BASE_VERSION }} | |
NEW_VERSION="${BASE_VERSION}-$(date +%Y%m%d%H%M%S)" | |
echo "New version: $NEW_VERSION" | |
mvn versions:set -DnewVersion=$NEW_VERSION | |
echo "::set-output name=NEW_VERSION::$NEW_VERSION" | |
- name: Build with Maven | |
run: mvn clean install | |
- name: Create and push tag | |
run: | | |
NEW_VERSION=${{ steps.bump_version.outputs.NEW_VERSION }} | |
git tag $NEW_VERSION | |
git push origin $NEW_VERSION | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Maven settings | |
run: | | |
mkdir -p $HOME/.m2 | |
echo '<settings><servers><server><id>github</id><username>${env.GITHUB_ACTOR}</username><password>${{ secrets.GITHUB_TOKEN }}</password></server></servers></settings>' > $HOME/.m2/settings.xml | |
shell: bash | |
env: | |
GITHUB_ACTOR: ${{ github.actor }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to GitHub Packages | |
run: mvn deploy -DskipTests | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |