-
Notifications
You must be signed in to change notification settings - Fork 11
142 lines (122 loc) · 5.75 KB
/
create-tag-on-merge.yml
File metadata and controls
142 lines (122 loc) · 5.75 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
name: Create Tag on merge
on:
workflow_dispatch:
push:
branches:
- develop
paths:
- src/**
- dist/**
- scripts/**
- package*.json
- action.yml
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WORKFLOWS_DEPLOYMENT_WEBHOOK }}
jobs:
create-tag:
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Create and push new tag
run: npm run create-tag
- name: Get latest commit
id: get-commit
run: echo "LAST_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Check for associated pull request and auto-deploy label
id: should-deploy
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const commit_sha = '${{ env.LAST_SHA }}';
const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ commit_sha, owner, repo });
if (prs?.length > 0) {
const pull_number = prs[0].number;
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number });
// Extract content from PR description - prioritize CHANGELOG if present
let releaseNote = pr.title;
if (pr.body) {
// First, check for __CHANGELOG__ section
const changelogMatch = pr.body.match(/__CHANGELOG__\s*(.*?)\s*_Generated by LinearB AI/s);
if (changelogMatch) {
releaseNote = changelogMatch[1].trim();
} else {
// Fallback to original gitstream placeholder extraction
const contentMatch = pr.body.match(/<!--start_gitstream_placeholder-->.*?### ✨ PR Description\s*(.*?)\s*_Generated by LinearB AI.*?<!--end_gitstream_placeholder-->/s);
if (contentMatch) {
releaseNote = contentMatch[1].trim();
} else {
// New format without gitstream placeholders
const newFormatMatch = pr.body.match(/## ✨ PR Description\s*(.*?)\s*(?:__CHANGELOG__|_Generated by LinearB AI)/s);
if (newFormatMatch) {
releaseNote = newFormatMatch[1].trim();
}
}
}
}
core.setOutput('pr-title', pr.title);
core.setOutput('release-notes', releaseNote);
core.setOutput('pr-number', pr.number);
// Check if CHANGELOG is present using the same logic as above
const hasChangelog = pr.body && pr.body.match(/__CHANGELOG__\s*(.*?)\s*_Generated by LinearB AI/s);
core.setOutput('has-changelog', !!hasChangelog);
return pr.labels.some(label => label.name.includes('auto-deploy'));
}
return false;
- name: Create GitHub Release & Deploy
if: steps.should-deploy.outputs.result == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ steps.should-deploy.outputs.has-changelog }}" = "true" ]; then
# Use custom release notes from CHANGELOG
printf "## What's Changed\n\n%s in [#%s](https://github.com/${{ github.repository }}/pull/%s)\n\n%s\n" \
"${{ steps.should-deploy.outputs.pr-title }}" \
"${{ steps.should-deploy.outputs.pr-number }}" \
"${{ steps.should-deploy.outputs.pr-number }}" \
"${{ steps.should-deploy.outputs.release-notes }}" > release_notes.md
gh release create $NEW_TAG --notes-file release_notes.md
else
# Use GitHub's automatic release notes generation
gh release create $NEW_TAG --generate-notes
fi
git checkout $NEW_TAG
npm run update-v2-tag
- name: Update v2-lite
if: steps.should-deploy.outputs.result == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.name 'GitHub Actions Bot'
git config --global user.email 'actions@github.com'
git checkout v2-lite
git checkout $NEW_TAG package.json package-lock.json dist/
git add package.json package-lock.json dist/
git commit -m "Update v2-lite to $NEW_TAG"
git push origin v2-lite
- name: Success Slack Notification
if: steps.should-deploy.outputs.result == 'true' && success()
uses: rtCamp/action-slack-notify@v2
env:
MSG_MINIMAL: true
SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }}
SLACK_TITLE: ${{ github.repository }}
SLACK_FOOTER: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run> | <${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ env.NEW_TAG }}|${{ env.NEW_TAG }}>
SLACK_MESSAGE: |
Released `${{ env.NEW_TAG }}` to `gitstream-github-action`
${{ steps.should-deploy.outputs.release-notes }}
- name: Failure Slack Notification
if: steps.should-deploy.outputs.result == 'true' && failure()
uses: rtCamp/action-slack-notify@v2
env:
MSG_MINIMAL: true
SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }}
SLACK_TITLE: ${{ github.repository }}
SLACK_COLOR: ${{ job.status }}
SLACK_FOOTER: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|workflow run>
SLACK_MESSAGE: Failed to release `${{ env.NEW_TAG }}` to `gitstream-github-action`