-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (84 loc) · 3.17 KB
/
Copy pathrelease.yml
File metadata and controls
96 lines (84 loc) · 3.17 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
name: Release
on:
pull_request:
types:
- closed
branches:
- master
permissions:
contents: write
pull-requests: read
jobs:
release:
name: Create release after versioned PR merge
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout merged commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0
- name: Resolve version label
id: version
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.pull_request.labels.map((label) => label.name);
const versionLabels = labels.filter((name) => /^v\d+\.\d+(\.\d+)?$/.test(name));
if (versionLabels.length !== 1) {
core.setFailed(`Merged pull request must have exactly one version label like v0.6. Found: ${versionLabels.join(', ') || 'none'}`);
return;
}
core.setOutput('tag', versionLabels[0]);
- name: Create git tag
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git rev-parse "${{ steps.version.outputs.tag }}" >/dev/null 2>&1; then
echo "Tag ${{ steps.version.outputs.tag }} already exists locally."
exit 0
fi
git tag "${{ steps.version.outputs.tag }}" "${{ github.event.pull_request.merge_commit_sha }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Create GitHub release
uses: actions/github-script@v7
with:
script: |
const tag = '${{ steps.version.outputs.tag }}';
const pr = context.payload.pull_request;
const extractSection = (body, heading) => {
const escapedHeading = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const pattern = new RegExp(`(?:^|\\n)##\\s+${escapedHeading}\\s*\\n([\\s\\S]*?)(?=\\n##\\s+|$)`, 'i');
const match = body.match(pattern);
return match ? match[1].trim() : '';
};
const summary = extractSection(pr.body || '', 'Summary');
const releaseChanges = summary || (pr.body || '').trim() || `- ${pr.title}`;
const releaseBody = [
'## Changes',
'',
releaseChanges,
'',
'## Pull request',
'',
`#${pr.number}: ${pr.html_url}`,
].join('\n');
try {
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: `ShiftPHP ${tag}`,
target_commitish: pr.merge_commit_sha,
body: releaseBody,
draft: false,
prerelease: false,
});
} catch (error) {
if (error.status === 422) {
core.info(`Release ${tag} already exists.`);
return;
}
throw error;
}