-
Notifications
You must be signed in to change notification settings - Fork 2
110 lines (97 loc) · 5.27 KB
/
_classic-buildpack-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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: _classic-buildpack-prepare-release
on:
workflow_call:
inputs:
custom_update_command:
description: An additional command to run before changes are committed, which can make use of the env vars EXISTING_VERSION and NEW_VERSION.
type: string
required: false
defaults:
run:
# Setting an explicit bash shell ensures GitHub Actions enables pipefail mode too,
# rather than only error on exit (improving failure UX when pipes are used). 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:
# We use our GitHub App's access token instead of GITHUB_TOKEN since otherwise other
# workflows (such as CI) won't automatically run on any PRs opened by this workflow:
# https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
- name: Generate access token for Linguist GitHub App
uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ vars.LINGUIST_GH_APP_ID }}
# Note: The calling workflow must enable secrets inheritance for this variable to be accessible:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idsecretsinherit
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
# Tags are not fetched by default, but we need them to determine the existing buildpack version.
fetch-tags: true
# Force a full clone, otherwise fetch-tags doesn't actually fetch any tags:
# https://github.com/actions/checkout/issues/1471
fetch-depth: 0
token: ${{ steps.generate-token.outputs.token }}
- name: Determine existing tagged version
id: existing-version
run: echo "version=$(git tag --list 'v*' --sort '-version:refname' | head --lines 1 | tr --delete 'v')" >> "${GITHUB_OUTPUT}"
- name: Calculate new version
id: new-version
run: echo "version=$(( ${{ steps.existing-version.outputs.version }} + 1 ))" >> "${GITHUB_OUTPUT}"
- name: Update changelog
run: |
EXISTING_VERSION='${{ steps.existing-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}...main"
NEW_VERSION_URL="https://github.com/${{ github.repository }}/compare/v${EXISTING_VERSION}...v${NEW_VERSION}"
sed --in-place --regexp-extended \
--expression "s~(^## \[Unreleased\])$~\1\n\n\n## [v${NEW_VERSION}] - ${DATE_TODAY}~" \
--expression "s~(^\[unreleased\]:) .*$~\1 ${UNRELEASED_URL}\n[v${NEW_VERSION}]: ${NEW_VERSION_URL}~" \
CHANGELOG.md
- name: Run custom update command
if: inputs.custom_update_command != ''
run: ${{ inputs.custom_update_command }}
env:
EXISTING_VERSION: ${{ steps.existing-version.outputs.version }}
NEW_VERSION: ${{ steps.new-version.outputs.version }}
- name: Generate list of unreleased commits
id: unreleased-commits
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
{
echo 'commits<<COMMITS_LIST_END'
git log --topo-order --reverse --format='- %s' v${{ steps.existing-version.outputs.version }}...main
echo COMMITS_LIST_END
} >> "${GITHUB_OUTPUT}"
- 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: |
Commits since the last release:
${{ steps.unreleased-commits.outputs.commits }}
For the full diff, see the compare view:
https://github.com/${{ github.repository }}/compare/v${{ steps.existing-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: PR link for GitHub summary
if: ${{ steps.pr.outputs.pull-request-number }}
run: echo '## PR [#${{ steps.pr.outputs.pull-request-number }}](${{ steps.pr.outputs.pull-request-url }}) ${{ steps.pr.outputs.pull-request-operation }}' >> "$GITHUB_STEP_SUMMARY"
- name: Enable pull request auto-merge
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 }}