-
Notifications
You must be signed in to change notification settings - Fork 7
197 lines (172 loc) · 8.16 KB
/
prepare-release-pr.yml
File metadata and controls
197 lines (172 loc) · 8.16 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Prepare Release PR
on:
workflow_call:
concurrency:
group: release-pr-${{ github.repository }}
cancel-in-progress: true
jobs:
release-pr:
if: ${{ github.event_name != 'push' || !contains(github.event.head_commit.message, 'chore(release)') }}
runs-on: ubuntu-latest
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d
with:
egress-policy: audit
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
fetch-depth: 0
fetch-tags: true
- name: Checkout .github repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
repository: FossifyOrg/.github
path: .github-repo
- name: Get next version code
id: version-code
run: |
currentVersionCode=$(grep '^VERSION_CODE=' gradle.properties | cut -d= -f2)
nextVersionCode=$((currentVersionCode+1))
echo "nextVersionCode=$nextVersionCode" >> $GITHUB_OUTPUT
- name: Get next version name
id: version-name
uses: ietf-tools/semver-action@c90370b2958652d71c06a3484129a4d423a6d8a8
with:
token: ${{ github.token }}
branch: ${{ github.event.repository.default_branch }}
noNewCommitBehavior: "warn"
noVersionBumpBehavior: "warn"
patchList: fix, bugfix, perf, refactor, test, tests, chore
- name: Check if release branch needs update
if: ${{ steps.version-name.outputs.nextStrict }}
id: skip-update
run: |
set -euo pipefail
MAIN="${{ github.event.repository.default_branch }}"
RELEASE="fossifybot/release"
if git rev-parse --verify -q "origin/$RELEASE"; then
if git merge-base --is-ancestor "origin/$MAIN" "origin/$RELEASE"; then
echo "needs_update=false" >> $GITHUB_OUTPUT
echo "Release branch is up-to-date."
else
echo "needs_update=true" >> $GITHUB_OUTPUT
echo "Release branch is behind the main branch."
fi
else
echo "needs_update=true" >> $GITHUB_OUTPUT
echo "Release branch doesn't exist yet."
fi
- name: Update files and check changelog
if: ${{ steps.skip-update.outputs.needs_update == 'true' && steps.version-name.outputs.nextStrict }}
id: update-version
run: |
chmod +x .github-repo/scripts/update-version.sh
if ! .github-repo/scripts/update-version.sh \
"${{ steps.version-name.outputs.nextStrict }}" \
"${{ steps.version-code.outputs.nextVersionCode }}" \
"${{ github.repository }}"; then
echo "::error::Release aborted - No changes found in CHANGELOG.md [Unreleased] section"
echo "::error::Please add your changes to the [Unreleased] section before creating a release"
exit 1
fi
- name: Setup NodeJS
if: ${{ steps.update-version.outcome == 'success' }}
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f
with:
node-version: "20"
- name: Install keep-a-changelog parser
if: ${{ steps.update-version.outcome == 'success' }}
run: npm install keep-a-changelog@2.6.2
- name: Add translations entry in changelog
if: ${{ steps.update-version.outcome == 'success' }}
id: update_changelog
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
script: |
const fs = require('fs');
const path = require('path');
const { parser } = require('keep-a-changelog');
const changelogPath = path.join(process.env.GITHUB_WORKSPACE, 'CHANGELOG.md');
if (!fs.existsSync(changelogPath)) {
throw new Error(`Changelog file not found at ${changelogPath}`);
}
const changelogContent = fs.readFileSync(changelogPath, 'utf8');
let parsed;
try {
parsed = parser(changelogContent);
console.log(`Parsed ${parsed.releases.length} releases from changelog.`);
} catch (error) {
throw new Error(`Failed to parse CHANGELOG.md: ${error.message}`);
}
const tagVersion = "${{ steps.version-name.outputs.nextStrict }}";
const release = parsed.findRelease(tagVersion);
if (!release) {
throw new Error(`No changelog entry found for version ${tagVersion} in ${changelogPath}.`);
}
const changedEntries = release.changes.get('changed') || [];
if (!changedEntries.some(entry => entry.toString().includes('Updated translations'))) {
release.changed('Updated translations');
const updatedChangelog = parsed.toString();
fs.writeFileSync(changelogPath, updatedChangelog, 'utf8');
console.log(`Added "Updated translations" to version ${tagVersion}`);
} else {
console.log(`"Updated translations" already present for version ${tagVersion}.`);
}
- name: Normalize changelog
if: ${{ steps.update-version.outcome == 'success' }}
run: |
npx keep-a-changelog --file="CHANGELOG.md" --no-v-prefix
- name: Extract changelog notes
if: ${{ steps.update-version.outcome == 'success' }}
id: extract_changelog
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd
with:
script: |
const fs = require('fs');
const path = require('path');
const { formatForGitHub, formatForFastlane } = require('./.github-repo/scripts/changelog-parser.js');
const changelogPath = path.join(process.env.GITHUB_WORKSPACE, 'CHANGELOG.md');
const tagVersion = "${{ steps.version-name.outputs.nextStrict }}";
if (!tagVersion) {
throw new Error('VERSION_NAME environment variable is not set.');
}
try {
const fastlaneNotes = formatForFastlane(changelogPath, tagVersion);
const versionCode = "${{ steps.version-code.outputs.nextVersionCode }}";
const metadataPath = path.join(process.env.GITHUB_WORKSPACE, 'fastlane', 'metadata', 'android', 'en-US', 'changelogs');
if (!fs.existsSync(metadataPath)) {
fs.mkdirSync(metadataPath, { recursive: true });
}
fs.writeFileSync(path.join(metadataPath, `${versionCode}.txt`), fastlaneNotes);
// Use GitHub format for the PR body
const notes = formatForGitHub(changelogPath, tagVersion, null, process.env.GITHUB_REPOSITORY);
core.setOutput('changelog', notes);
} catch (error) {
core.setFailed(error.message);
return;
}
- id: app-token
if: ${{ steps.update-version.outcome == 'success' }}
uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Create or update PR
if: ${{ steps.update-version.outcome == 'success' && steps.extract_changelog.outcome == 'success' }}
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1
with:
token: ${{ steps.app-token.outputs.token }}
sign-commits: true
labels: "testers needed"
branch: fossifybot/release
commit-message: "chore(release): v${{ steps.version-name.outputs.nextStrict }} (${{ steps.version-code.outputs.nextVersionCode }})"
title: "chore(release): v${{ steps.version-name.outputs.nextStrict }} (${{ steps.version-code.outputs.nextVersionCode }})"
body: |
## Release notes
${{ steps.extract_changelog.outputs.changelog }}
add-paths: |
CHANGELOG.md
gradle.properties
.fossify/release-marker.txt
fastlane/metadata/android/en-US/changelogs/*.txt