-
Notifications
You must be signed in to change notification settings - Fork 90
93 lines (81 loc) · 3.05 KB
/
release.yml
File metadata and controls
93 lines (81 loc) · 3.05 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
name: Publish Release
on:
push:
branches:
- main
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.8.1'
- name: Install dependencies
run: npm ci
- name: Create Tag
uses: cycjimmy/semantic-release-action@v4.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Read version number
id: get_version
run: |
set -e
echo "---------------------------------------------------------"
if [ -s version.txt ]; then
version=$(cat version.txt)
echo "✅ New version detected: v$version"
echo "---------------------------------------------------------"
echo "version=${version}" >> $GITHUB_OUTPUT
else
echo "🚫 No version update detected. "
echo " This indicates that there is no new release to publish."
echo "---------------------------------------------------------"
echo "version=" >> $GITHUB_OUTPUT
fi
- name: Publish release notes
if: steps.get_version.outputs.version != ''
uses: actions/github-script@v7
env:
NEW_VERSION: ${{ steps.get_version.outputs.version }}
with:
script: |
(async () => {
try {
const newVersion = process.env.NEW_VERSION.trim();
const tagName = `v${newVersion}`;
const response = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Version ${newVersion}`,
generate_release_notes: true,
draft: false,
prerelease: false
});
const date = new Date().toLocaleDateString("en-US", {
timeZone: "America/New_York",
year: "numeric",
month: "long",
day: "numeric"
});
const customHeader = `Release Notes for Version ${newVersion} - ${date}\n\n`;
const updatedBody = customHeader + response.data.body;
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: response.data.id,
body: updatedBody,
name: `Version ${newVersion}`
});
console.log(`✅ Successfully published release notes for version ${newVersion}`);
} catch (error) {
console.error(`🚫 Failed to publish release notes: ${error}`);
process.exit(1);
}
})();