Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add release workflow #368

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
name: Prepare release

on:
workflow_dispatch:
on: workflow_dispatch

defaults:
run:
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too, rather
# than only error on exit. This is important for UX since this workflow uses pipes. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: bash

jobs:
prepare-release:
Expand All @@ -27,6 +33,8 @@ jobs:
- name: Record latest release version
id: old-version
run: echo "version=$(gh release view --json tagName | jq -j .tagName)" >> "${GITHUB_OUTPUT}"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.app_token }}

- name: Drop -SNAPSHOT suffix from version
run: ./mvnw versions:set -DremoveSnapshot -DgenerateBackupPoms=false
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Release

on: workflow_dispatch

defaults:
run:
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too, rather
# than only error on exit. This is important for UX since this workflow uses pipes. See:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell
shell: bash

jobs:
release:
name: Release
# Prevent accidentally performing a release from a branch other than `main`.
if: github.ref == 'refs/heads/main'
runs-on: pub-hk-ubuntu-22.04-small
steps:
- name: Get token for GH application (Linguist)
uses: heroku/use-app-token-action@main
id: generate-token
with:
app_id: ${{ vars.LINGUIST_GH_APP_ID }}
private_key: ${{ secrets.LINGUIST_GH_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4
with:
# Using the GH application token here will configure the local git config for this repo with credentials
# that can be used to make signed commits that are attributed to the GH application user
token: ${{ steps.generate-token.outputs.app_token }}

- name: Set up Java
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8'
server-id: ossrh
server-username: MAVEN_CENTRAL_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Record new version
id: new-version
run: echo "version=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -B -DforceStdout)" >> "${GITHUB_OUTPUT}"

- name: Check GitHub release does not already exist
run: |
if gh release view '${{ steps.new-version.outputs.version }}' --json url --jq '.url'; then
echo "Aborting since a GitHub release already exists for ${{ steps.new-version.outputs.version }}!" >&2
echo "If you are sure you want to recreate the release, delete the existing one first." >&2
exit 1
fi
env:
GH_TOKEN: ${{ steps.generate-token.outputs.app_token }}

- name: Extract changelog entry
id: changelog-entry
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
{
echo 'content<<CHANGELOG_END'
awk '/^## \[${{ steps.new-version.outputs.version }}\]/{flag=1; next} /^## /{flag=0} flag' CHANGELOG.md
echo CHANGELOG_END
} >> "${GITHUB_OUTPUT}"

- name: Deploy project
run: ./mvnw --batch-mode deploy
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

- name: Create GitHub Release
uses: softprops/[email protected]
with:
token: ${{ steps.generate-token.outputs.app_token }}
tag_name: v${{ steps.new-version.outputs.version }}
body: ${{ steps.changelog-entry.outputs.content }}

- name: Record next version
id: next-version
run: echo "version=$(echo ${{ steps.new-version.outputs.version }} | awk -F. -v OFS=. '{ $NF=sprintf("%d-SNAPSHOT", ($NF+1)); printf $0 }')" >> "${GITHUB_OUTPUT}"

- name: Update version
run: ./mvnw versions:set -DgenerateBackupPoms=false -DnewVersion="${{ steps.next-version.outputs.version }}"

- name: Create pull request
id: pr
uses: peter-evans/[email protected]
with:
token: ${{ steps.generate-token.outputs.app_token }}
title: Prepare next development iteration ${{ steps.next-version.outputs.version }}
body: |
Prepare next development iteration `${{ steps.next-version.outputs.version }}`.
commit-message: Prepare next development iteration ${{ steps.next-version.outputs.version }}
branch: prepare-next
delete-branch: true
committer: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>
author: ${{ vars.LINGUIST_GH_APP_USERNAME }} <${{ vars.LINGUIST_GH_APP_EMAIL }}>

- name: Configure pull request
if: steps.pr.outputs.pull-request-operation == 'created'
run: gh pr merge --auto --squash "${{ steps.pr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.app_token }}