-
Notifications
You must be signed in to change notification settings - Fork 117
149 lines (123 loc) · 4.82 KB
/
create-release-pr.yml
File metadata and controls
149 lines (123 loc) · 4.82 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
name: Create Release PR
on:
workflow_dispatch:
jobs:
bump-version:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- name: Setup Vite+
uses: voidzero-dev/setup-vp@v1
with:
node-version-file: '.nvmrc'
- name: Get current SDK version
id: current_version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').config.sdkVersion")
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Get last release commit
id: last_commit
run: |
LAST_RELEASE_DATE=$(git show -s --format=%cI "${{ steps.current_version.outputs.current }}")
echo "date=$LAST_RELEASE_DATE" >> $GITHUB_OUTPUT
- name: Get merged PRs since last release
id: get_prs
uses: actions/github-script@v8
with:
script: |
const lastReleaseDate = '${{ steps.last_commit.outputs.date }}';
// Get merged PRs
const { data: prs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
base: 'main',
per_page: 100
});
// Filter and process PRs
const mergedPrs = prs
.filter(pr => pr.merged_at && new Date(pr.merged_at) > new Date(lastReleaseDate))
.map(pr => ({
number: pr.number,
title: pr.title,
}));
core.setOutput('prs', JSON.stringify(mergedPrs));
const hasFeatures = mergedPrs.some(pr => /^feat/i.test(pr.title));
core.setOutput('isFeature', hasFeatures);
- name: Calculate new version
id: new_version
run: |
CURRENT="${{ steps.current_version.outputs.current }}"
PRS='${{ steps.get_prs.outputs.prs }}'
IS_FEATURE='${{ steps.get_prs.outputs.isFeature }}'
MAJOR=${CURRENT:0:2}
MINOR=${CURRENT:2:2}
PATCH=${CURRENT:4:2}
if [[ "$IS_FEATURE" == "true" ]]; then
MINOR=$(printf "%02d" $((10#$MINOR + 1)))
PATCH="00"
else
PATCH=$(printf "%02d" $((10#$PATCH + 1)))
fi
NEW_VERSION="${MAJOR}${MINOR}${PATCH}"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Create release branch on main
run: |
git checkout -b rel/${{ steps.new_version.outputs.version }}
git push -u origin rel/${{ steps.new_version.outputs.version }}
- name: Update package.json sdk version
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
npm pkg set config.sdkVersion="$NEW_VERSION"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "Release $NEW_VERSION"
git push
- name: Generate release notes
id: release_notes
uses: actions/github-script@v8
with:
script: |
// Trim whitespace from PR titles
const prs = JSON.parse('${{ steps.get_prs.outputs.prs }}').map(pr => ({
...pr,
title: pr.title.trim()
}));
// Categorize PRs
const features = prs.filter(pr => /^feat/i.test(pr.title));
const fixes = prs.filter(pr => /^fix/i.test(pr.title));
const improvements = prs.filter(pr => /^(perf|refactor|chore)/i.test(pr.title));
// Helper function to build section
const buildSection = (title, prs) => {
if (prs.length === 0) return '';
let section = `### ${title}\n\n`;
prs.forEach(pr => {
section += `- ${pr.title} (#${pr.number})\n`;
});
return section + '\n';
};
let releaseNotes = '';
releaseNotes += buildSection('🚀 New Features', features);
releaseNotes += buildSection('🐛 Bug Fixes', fixes);
releaseNotes += buildSection('🔧 Improvements', improvements);
core.setOutput('notes', releaseNotes);
- name: Create release PR
run: |
NEW_VERSION="${{ steps.new_version.outputs.version }}"
# Write release notes to file to avoid shell interpretation
cat > release_notes.md << 'EOF'
Channels: Current, Stable
${{ steps.release_notes.outputs.notes }}
EOF
gh pr create \
--title "Release $NEW_VERSION" \
--body-file release_notes.md \
--base main \
--reviewer fadi-george,sherwinski,jkasten2