Skip to content

Commit

Permalink
ci: automatic release via workflow_dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Aug 4, 2022
1 parent 6537808 commit 13d2369
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions .github/workflows/test.yml → .github/workflows/ci.yml
@@ -1,6 +1,7 @@
name: CI

on:
workflow_dispatch:
pull_request:
paths:
- '**.java'
Expand Down Expand Up @@ -148,6 +149,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
if: ${{ github.event_name == 'push' }}
# a workflow dispatch indicates a release, we need the full git history to generate the changelog
- uses: actions/checkout@v3
if: ${{ github.event_name == 'workflow_dispatch' }}
with:
fetch-depth: 0
- name: Set up Apache Maven Central
uses: actions/setup-java@v2
with: # running setup-java again overwrites the settings.xml
Expand All @@ -161,11 +168,43 @@ jobs:
gpg-passphrase: MAVEN_CENTRAL_GPG_PASSPHRASE # env variable for GPG private key passphrase (3)
- name: Get Project Version
run: |
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" | tee -a $GITHUB_ENV
- name: Cancel action for non SNAPSHOT push
if: ${{ github.event_name == 'push' && !endsWith(env.PROJECT_VERSION, '-SNAPSHOT')}}
uses: andymckay/cancel-action@0.2
# from that point, push means we deploy snapshot, workflow_dispatch means we perform a release
- name: Prepare release
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
mvn --no-transfer-progress versions:set -DremoveSnapshot -DgenerateBackupPoms=false
echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" | tee -a $GITHUB_ENV
- name: Release commit and push
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: EndBug/add-and-commit@v9
with:
message: 'chore(release): ${{ env.RELEASE_VERSION }} [skip ci]'
tag: '${{ env.RELEASE_VERSION }}'
default_author: github_actions
# The sonatype maven plugin will decide the right destination depending on whether the project is SNAPSHOT or not
- name: Publish to Apache Maven Central
if: ${{ endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }}
run: mvn --batch-mode --no-transfer-progress deploy -P release -DskipTests
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }} # must be the same env variable name as (1)
MAVEN_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} # must be the same env variable name as (2)
MAVEN_CENTRAL_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} # must be the same env variable name as (3)
MAVEN_CENTRAL_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} # must be the same env variable name as (3)
- name: Create Github release with JReleaser
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mvn --batch-mode --no-transfer-progress -DskipTests jreleaser:full-release
- name: Prepare next snapshot
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
mvn versions:set -DnextSnapshot -DgenerateBackupPoms=false
- name: Next snapshot commit and push
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: EndBug/add-and-commit@v9
with:
message: 'chore(release): prepare next snapshot [skip ci]'
default_author: github_actions

0 comments on commit 13d2369

Please sign in to comment.