-
Notifications
You must be signed in to change notification settings - Fork 0
200 lines (168 loc) · 6.45 KB
/
release-beta.yml
File metadata and controls
200 lines (168 loc) · 6.45 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: Release Beta with Changesets
# This workflow publishes beta versions on push to break/* branches
# Beta versions follow the pattern: X.Y.Z-beta.N (e.g., 2.0.0-beta.48)
# Uses Changesets for version management
#
# Required secrets:
# 1. NPM_TOKEN: NPM automation token for publishing packages
# 2. RELEASE_TOKEN: GitHub PAT with bypass permissions
on:
push:
branches:
- 'break/**'
permissions:
contents: write
pull-requests: write
packages: write
actions: read
id-token: write # Required for NPM provenance
jobs:
release-beta:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
registry-url: 'https://registry.npmjs.org'
- name: Enable Corepack
run: corepack enable
- name: Get Yarn cache directory
id: yarn-cache
shell: bash
run: |
echo "CACHE_DIR=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Setup Yarn cache
uses: actions/cache@v4
with:
path: ${{ steps.yarn-cache.outputs.CACHE_DIR }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: |
echo "Installing dependencies with yarn..."
yarn --version
yarn install --immutable
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get latest commit message
id: commit
run: |
echo "message<<EOF" >> $GITHUB_OUTPUT
git log -1 --pretty=%B >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "Commit message: $(git log -1 --pretty=format:"%s")"
- name: Create beta changeset
run: |
COMMIT_MSG="${{ steps.commit.outputs.message }}"
# Clean commit message for changeset summary
SUMMARY=$(echo "$COMMIT_MSG" | sed -E 's/^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|break|breaking)(\([^)]+\))?!?:\s*//')
# Create changeset file
CHANGESET_ID=$(date +%s)
CHANGESET_FILE=".changeset/beta-$CHANGESET_ID.md"
echo "---" > $CHANGESET_FILE
echo "\"@kubit-ui-web/react-charts\": major" >> $CHANGESET_FILE
echo "---" >> $CHANGESET_FILE
echo "" >> $CHANGESET_FILE
echo "$SUMMARY" >> $CHANGESET_FILE
echo "✅ Created beta changeset:"
cat $CHANGESET_FILE
- name: Enter prerelease mode
run: |
echo "📦 Checking prerelease mode status..."
# Check if already in pre mode
if [ -f ".changeset/pre.json" ]; then
echo "⚠️ Already in prerelease mode, exiting first..."
yarn changeset pre exit
# Commit the exit
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add .
if ! git diff --staged --quiet; then
git commit -m "chore: exit prerelease mode [skip ci]"
fi
fi
echo "📦 Entering beta prerelease mode..."
yarn changeset pre enter beta
- name: Version packages
run: |
echo "📦 Versioning packages for beta..."
yarn changeset:version
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Commit version changes
git add .
if git diff --staged --quiet; then
echo "No version changes to commit"
else
git commit -m "chore: version packages for beta [skip ci]"
git push origin ${{ github.ref_name }}
fi
- name: Build packages
run: |
echo "🏗️ Building packages..."
yarn dist
env:
NODE_ENV: production
- name: Publish beta to NPM
run: |
echo "🚀 Publishing beta to NPM..."
yarn changeset:publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Exit prerelease mode
run: |
echo "📦 Exiting beta prerelease mode..."
yarn changeset pre exit
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: exit beta prerelease mode [skip ci]"
git push origin ${{ github.ref_name }}
fi
- name: Get published version
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const version = '${{ steps.version.outputs.version }}';
const npmLink = `https://www.npmjs.com/package/@kubit-ui-web/react-charts/v/${version}`;
let comment = '## 🚀 Beta Package Published\n\n';
comment += '**Branch:** `${{ github.ref_name }}`\n\n';
comment += '| Package | Version | NPM Link |\n';
comment += '|---------|---------|----------|\n';
comment += `| @kubit-ui-web/react-charts | \`${version}\` | [View on NPM](${npmLink}) |\n`;
comment += '\n✅ Beta package has been successfully published to NPM!\n\n';
comment += '**Install beta version:**\n';
comment += '```sh\n';
comment += `npm install @kubit-ui-web/react-charts@${version}\n`;
comment += '```';
// Try to find an open PR for this branch
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${{ github.ref_name }}`,
state: 'open'
});
if (prs.data.length > 0) {
await github.rest.issues.createComment({
issue_number: prs.data[0].number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}