-
Notifications
You must be signed in to change notification settings - Fork 9
140 lines (114 loc) · 4.43 KB
/
Copy pathrelease.yml
File metadata and controls
140 lines (114 loc) · 4.43 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
name: Release
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: write
jobs:
release:
name: Create GitHub Release
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect new changelog
id: changelog
shell: bash
run: |
set -euo pipefail
BEFORE_SHA="${{ github.event.before }}"
if [ -z "$BEFORE_SHA" ] || [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
BEFORE_SHA="HEAD^"
fi
NEW_FILE="$(git diff --name-status "$BEFORE_SHA" "${{ github.sha }}" | awk '$1 == "A" {print $2}' | grep -E '^changelog/v[0-9]+\.[0-9]+\.[0-9]+.*\.md$' | head -n 1 || true)"
if [ -z "$NEW_FILE" ]; then
echo "has_release=false" >> "$GITHUB_OUTPUT"
echo "version=" >> "$GITHUB_OUTPUT"
echo "file_path=" >> "$GITHUB_OUTPUT"
echo "No new changelog file found."
exit 0
fi
VERSION="$(basename "$NEW_FILE" .md)"
echo "has_release=true" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "file_path=$NEW_FILE" >> "$GITHUB_OUTPUT"
echo "Detected release changelog: $NEW_FILE"
- name: Setup Node.js
if: steps.changelog.outputs.has_release == 'true'
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install dependencies
if: steps.changelog.outputs.has_release == 'true'
run: npm ci
- name: Sync release artifacts
if: steps.changelog.outputs.has_release == 'true'
shell: bash
run: |
set -euo pipefail
TARGET_VERSION="${{ steps.changelog.outputs.version }}"
TARGET_VERSION="${TARGET_VERSION#v}"
node - <<'NODE' "$TARGET_VERSION"
const fs = require("node:fs");
const version = process.argv[2];
function updatePackageJson(filePath) {
const raw = fs.readFileSync(filePath, "utf8");
const json = JSON.parse(raw);
json.version = version;
fs.writeFileSync(filePath, JSON.stringify(json, null, 2) + "\n");
}
function updatePackageLock(filePath) {
if (!fs.existsSync(filePath)) return;
const raw = fs.readFileSync(filePath, "utf8");
const json = JSON.parse(raw);
json.version = version;
if (json.packages && json.packages[""]) {
json.packages[""].version = version;
}
fs.writeFileSync(filePath, JSON.stringify(json, null, 2) + "\n");
}
updatePackageJson("package.json");
updatePackageLock("package-lock.json");
NODE
npm run generate:openapi
npm run generate:skills
npx tsx scripts/check-openapi-contract.ts
git add package.json package-lock.json docs/openapi.json docs/openapi.yaml docs/skills.json
if git diff --cached --quiet; then
echo "Release artifacts are already up to date."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "chore(release): sync release artifacts to ${{ steps.changelog.outputs.version }} [skip ci]"
git push origin HEAD:${{ github.ref_name }}
- name: Finalize release commit
id: finalize
if: steps.changelog.outputs.has_release == 'true'
shell: bash
run: |
echo "build_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Generate release notes
if: steps.changelog.outputs.has_release == 'true'
shell: bash
run: |
set -euo pipefail
FILE_PATH="${{ steps.changelog.outputs.file_path }}"
cat "$FILE_PATH" > release.md
- name: Create release
if: steps.changelog.outputs.has_release == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.changelog.outputs.version }}
name: Release ${{ steps.changelog.outputs.version }}
body_path: release.md
target_commitish: ${{ steps.finalize.outputs.build_sha }}
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}