mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 09:01:17 -08:00
134 lines
4.3 KiB
YAML
134 lines
4.3 KiB
YAML
name: Create Release PR
|
|
|
|
on:
|
|
push:
|
|
branches: [dev]
|
|
|
|
permissions: {}
|
|
|
|
jobs:
|
|
prepare-release:
|
|
if: "!contains(github.event.head_commit.message, 'chore: prepare release')"
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Generate bot token
|
|
id: generate-token
|
|
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859
|
|
with:
|
|
app-id: ${{ secrets.APP_ID }}
|
|
private-key: ${{ secrets.APP_PRIVATE_KEY }}
|
|
|
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
persist-credentials: true
|
|
token: ${{ steps.generate-token.outputs.token }}
|
|
|
|
- uses: fregante/setup-git-user@024bc0b8e177d7e77203b48dab6fb45666854b35 # v2.0.2
|
|
|
|
- uses: knope-dev/action@19617851f9f13ab2f27a05989c55efb18aca3675 # v2.1.2
|
|
with:
|
|
version: 0.22.3
|
|
|
|
- name: Prepare Release
|
|
run: knope prepare-release --verbose
|
|
env:
|
|
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
|
|
|
|
- name: Enrich changelog and update release PR
|
|
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
|
|
with:
|
|
github-token: ${{ steps.generate-token.outputs.token }}
|
|
script: |
|
|
const fs = require("fs");
|
|
const { owner, repo } = context.repo;
|
|
|
|
async function resolveHash(hash) {
|
|
try {
|
|
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
|
owner, repo, commit_sha: hash,
|
|
});
|
|
const pr = prs.data[0];
|
|
return pr
|
|
? `([#${pr.number}](<${pr.html_url}>) by @${pr.user.login})`
|
|
: `(\`${hash}\`)`;
|
|
} catch {
|
|
return `(\`${hash}\`)`;
|
|
}
|
|
}
|
|
|
|
async function enrichText(text) {
|
|
const marker = /<!-- commit:([0-9a-f]+) -->/g;
|
|
const hashes = [...new Set([...text.matchAll(marker)].map(m => m[1]))];
|
|
for (const hash of hashes) {
|
|
text = text.replaceAll(`<!-- commit:${hash} -->`, await resolveHash(hash));
|
|
}
|
|
return text;
|
|
}
|
|
|
|
const changelog = "CHANGELOG.md";
|
|
if (fs.existsSync(changelog)) {
|
|
const enriched = await enrichText(fs.readFileSync(changelog, "utf8"));
|
|
fs.writeFileSync(changelog, enriched);
|
|
}
|
|
|
|
const prs = await github.rest.pulls.list({
|
|
owner, repo,
|
|
head: `${owner}:release`,
|
|
state: "open",
|
|
});
|
|
|
|
if (prs.data.length === 0) {
|
|
core.warning("No open PR found for the release branch.");
|
|
return;
|
|
}
|
|
|
|
const pr = prs.data[0];
|
|
|
|
const label = "internal";
|
|
try {
|
|
await github.rest.issues.getLabel({ owner, repo, name: label });
|
|
} catch (e) {
|
|
if (e.status === 404) {
|
|
await github.rest.issues.createLabel({ owner, repo, name: label, color: "e4e669" });
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
await Promise.all([
|
|
github.rest.pulls.update({
|
|
owner, repo,
|
|
pull_number: pr.number,
|
|
body: await enrichText(pr.body ?? ""),
|
|
}),
|
|
github.rest.issues.addLabels({
|
|
owner, repo,
|
|
issue_number: pr.number,
|
|
labels: [label],
|
|
}),
|
|
]);
|
|
|
|
- name: Amend release commit with enriched changelog
|
|
shell: bash
|
|
run: |
|
|
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "release" ]]; then
|
|
echo "Not on release branch — skipping amend."
|
|
exit 1
|
|
fi
|
|
|
|
if git diff --cached --name-only | grep -q "CHANGELOG.md"; then
|
|
git add CHANGELOG.md
|
|
git commit --amend --no-edit
|
|
elif git diff --name-only HEAD | grep -q "CHANGELOG.md"; then
|
|
git add CHANGELOG.md
|
|
git commit --amend --no-edit
|
|
fi
|
|
|
|
- name: Push release branch
|
|
shell: bash
|
|
run: git push --force --set-upstream origin release
|