-
Notifications
You must be signed in to change notification settings - Fork 110
122 lines (108 loc) · 5.04 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Release
on:
workflow_dispatch:
inputs:
major-version:
description: 'Major Version'
required: true
default: '9'
type: choice
options:
- '9'
- '10'
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@v4
with:
distribution: 'zulu'
java-version: '11'
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}"
working-directory: webapp-runner-${{ inputs.major-version }}
- name: Check GitHub release does not already exist
run: |
if gh release view 'v${{ 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' webapp-runner-${{ inputs.major-version }}/CHANGELOG.md
echo CHANGELOG_END
} >> "${GITHUB_OUTPUT}"
- name: Deploy project
run: ./mvnw --batch-mode deploy
working-directory: webapp-runner-${{ inputs.major-version }}
env:
MAVEN_CENTRAL_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 }}"
working-directory: webapp-runner-${{ inputs.major-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 }}>
labels: |
skip changelog
- 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 }}