-
Notifications
You must be signed in to change notification settings - Fork 110
95 lines (84 loc) · 4.38 KB
/
prepare-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
name: Prepare 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:
prepare-release:
name: Prepare Release
runs-on: pub-hk-ubuntu-24.04-ip
steps:
- name: Get token for GH application (Linguist)
uses: actions/create-github-app-token@v1
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:
# We always want the version bump/changelog and resultant PR to target main, not the branch of the workflow_dispatch.
ref: main
# 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.token }}
- name: Record latest release version
id: old-version
# We can't just use `gh release view` since we have to deal with multiple versions that may semantically the
# "latest version", depending on the subproject we prepare the release for. Additionally, `gh release list`
# does not support JSON output at the time of writing: https://github.com/cli/cli/issues/4572
run: echo "version=$(gh api /repos/heroku/webapp-runner/releases | jq -j 'map(select(.tag_name | startswith("v${{ inputs.major-version }}"))) | sort_by(.published_at | fromdateiso8601) | last | .tag_name[1:]')" >> "${GITHUB_OUTPUT}"
working-directory: webapp-runner-${{ inputs.major-version }}
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Drop -SNAPSHOT suffix from version
run: ./mvnw versions:set -DremoveSnapshot -DgenerateBackupPoms=false
working-directory: webapp-runner-${{ inputs.major-version }}
- 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: Update changelog
run: |
OLD_VERSION='${{ steps.old-version.outputs.version }}'
NEW_VERSION='${{ steps.new-version.outputs.version }}'
DATE_TODAY="$(date --utc --iso-8601)"
UNRELEASED_URL="https://github.com/${{ github.repository }}/compare/v${NEW_VERSION}...HEAD"
NEW_VERSION_URL="https://github.com/${{ github.repository }}/compare/v${OLD_VERSION}...v${NEW_VERSION}"
sed --in-place --regexp-extended \
--expression "s~(^## \[Unreleased\])$~\1\n\n\n## [${NEW_VERSION}] - ${DATE_TODAY}~" \
--expression "s~(^\[unreleased\]:) .*$~\1 ${UNRELEASED_URL}\n[${NEW_VERSION}]: ${NEW_VERSION_URL}~" \
CHANGELOG.md
working-directory: webapp-runner-${{ inputs.major-version }}
- name: Create pull request
id: pr
uses: peter-evans/[email protected]
with:
token: ${{ steps.generate-token.outputs.token }}
title: Prepare release v${{ steps.new-version.outputs.version }}
body: |
Changes:
https://github.com/${{ github.repository }}/compare/v${{ steps.old-version.outputs.version }}...main
commit-message: Prepare release v${{ steps.new-version.outputs.version }}
branch: prepare-release
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.token }}