forked from tryopendata/openchart
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (98 loc) · 3.7 KB
/
release.yml
File metadata and controls
115 lines (98 loc) · 3.7 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
name: Release
on:
push:
branches: [main]
permissions: {}
jobs:
publish:
name: Publish to npm
# Only run on release commits created by scripts/release.mjs
if: "startsWith(github.event.head_commit.message, 'release: openchart v')"
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Setup
uses: ./.github/actions/setup-bun
with:
node-version: '20'
- name: Build
run: bun run build
- name: Typecheck
run: bun run typecheck
- name: Test
run: bun run test
- name: Extract version from commit message
id: version
run: |
VERSION=$(echo "${{ github.event.head_commit.message }}" | sed 's/release: openchart v//')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Rewrite workspace dependencies to real versions
run: |
node -e "
const fs = require('fs');
const pkgs = ['core', 'engine', 'vanilla', 'react', 'vue', 'svelte'];
const versions = {};
for (const pkg of pkgs) {
const p = JSON.parse(fs.readFileSync('packages/' + pkg + '/package.json', 'utf8'));
versions[p.name] = p.version;
}
for (const pkg of pkgs) {
const path = 'packages/' + pkg + '/package.json';
const p = JSON.parse(fs.readFileSync(path, 'utf8'));
for (const field of ['dependencies', 'peerDependencies', 'devDependencies']) {
for (const [k, v] of Object.entries(p[field] || {})) {
if (v === 'workspace:*') {
if (!versions[k]) throw new Error(k + ' not found in workspace');
p[field][k] = versions[k];
}
}
}
fs.writeFileSync(path, JSON.stringify(p, null, 2) + '\n');
}
console.log('Resolved workspace versions:', versions);
"
- name: Verify no workspace references remain
run: |
if grep -r "workspace:" packages/*/package.json; then
echo "ERROR: workspace: references found in package.json files"
exit 1
fi
- name: Publish packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
publish_pkg() {
local dir=$1
echo "Publishing $dir..."
output=$(npm publish --provenance --access public 2>&1) && echo "$output" && return 0
if echo "$output" | grep -qi "previously published\|already exists\|cannot publish over"; then
echo "Already published, skipping"
return 0
fi
echo "$output" >&2
return 1
}
for pkg in core engine vanilla react vue svelte; do
(cd "packages/$pkg" && publish_pkg "$pkg")
done
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.version.outputs.version }}"
# Extract changelog entry for this version from core (representative)
NOTES=$(sed -n "/^## \[${VERSION}\]/,/^## \[/{ /^## \[${VERSION}\]/p; /^## \[${VERSION}\]/!{ /^## \[/!p; } }" packages/core/CHANGELOG.md)
if [ -z "$NOTES" ]; then
NOTES="Release openchart v${VERSION}"
fi
gh release create "core-v${VERSION}" \
--title "openchart v${VERSION}" \
--notes "$NOTES" \
--verify-tag