-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
145 lines (123 loc) · 5.47 KB
/
pr-release.yml
File metadata and controls
145 lines (123 loc) · 5.47 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
name: Release
on:
push:
branches:
- master
- release/v*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions: {}
jobs:
pr-release:
permissions:
id-token: write # Required for OIDC token
environment: release
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Checkout code repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0
persist-credentials: false
- name: Install dependencies
uses: ./.github/actions/pnpm
- name: Generate GitHub App token
uses: electron/github-app-auth-action@e25ab7f5aa15b949aee0f00d7e48972f1f3e0f5a
id: generate-token
with:
export-git-user: true
creds: ${{ secrets.RELEASE_BOT_APP_CREDS }}
- name: Determine dist-tag and changeset config
id: dist-tag
run: |
BRANCH="${{ github.ref_name }}"
if [ "$BRANCH" == "master" ]; then
echo "tag=next" >> $GITHUB_OUTPUT
echo "branch_type=prerelease" >> $GITHUB_OUTPUT
echo "config_file=config.json" >> $GITHUB_OUTPUT
elif [[ "$BRANCH" =~ ^release/v[0-9]+$ ]]; then
# Extract version from branch name (e.g., release/v27 -> v27)
VERSION=$(echo "$BRANCH" | sed -E 's/^release\/(v[0-9]+)$/\1/')
# Validate extraction
if [[ ! "$VERSION" =~ ^v[0-9]+$ ]]; then
echo "::error::Failed to extract valid version from branch: $BRANCH"
echo "::error::Expected format: release/v{major} (e.g., release/v27)"
echo "::error::Extracted version: $VERSION"
exit 1
fi
echo "tag=$VERSION" >> $GITHUB_OUTPUT
echo "branch_type=lts" >> $GITHUB_OUTPUT
echo "config_file=config.release-$VERSION.json" >> $GITHUB_OUTPUT
else
echo "::error::Unsupported branch for release: $BRANCH"
echo "::error::Expected 'master' or 'release/v{major}' (e.g., 'release/v27')"
exit 1
fi
# Log determined values
echo "Branch: $BRANCH"
echo "Dist-tag: $(grep '^tag=' $GITHUB_OUTPUT | cut -d= -f2)"
echo "Branch type: $(grep '^branch_type=' $GITHUB_OUTPUT | cut -d= -f2)"
echo "Config file: $(grep '^config_file=' $GITHUB_OUTPUT | cut -d= -f2)"
- name: Link changeset config for this branch
run: |
CONFIG_FILE="${{ steps.dist-tag.outputs.config_file }}"
CONFIG_PATH=".changeset/$CONFIG_FILE"
# Verify config exists
if [ ! -f "$CONFIG_PATH" ]; then
echo "::error::Changeset config not found: $CONFIG_PATH"
echo "::error::Please create $CONFIG_PATH with the appropriate baseBranch setting"
exit 1
fi
# Only create symlink if it's not already the default config.json
if [ "$CONFIG_FILE" != "config.json" ]; then
# Remove existing config.json if it exists (could be a file or symlink)
rm -f .changeset/config.json
# Create symbolic link (using relative path from .changeset/ directory)
cd .changeset
ln -s "$CONFIG_FILE" config.json
cd ..
echo "Linked .changeset/config.json -> .changeset/$CONFIG_FILE"
# Verify the link worked
if [ ! -L ".changeset/config.json" ]; then
echo "::error::Failed to create symbolic link"
exit 1
fi
# Verify the link points to the right file
LINK_TARGET=$(readlink .changeset/config.json)
if [ "$LINK_TARGET" != "$CONFIG_FILE" ]; then
echo "::error::Symlink points to wrong target: $LINK_TARGET (expected: $CONFIG_FILE)"
exit 1
fi
else
echo "Using default config: $CONFIG_PATH (no symlink needed)"
fi
- name: Create versions PR & prepare publish
id: changesets
uses: changesets/action@7af85527bb2f43a404b5823a6cad47661be255c1 # v1.5.3 - @marshallofsound fork
with:
commit: 'chore(deploy): Release (${{ steps.dist-tag.outputs.tag }})'
title: 'chore(deploy): Release (${{ steps.dist-tag.outputs.tag }})'
version: pnpm ci:version
publish: pnpm ci:publish
setupGitUser: false
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
NPM_DIST_TAG: ${{ steps.dist-tag.outputs.tag }}
- name: Publish Summary
if: steps.changesets.outputs.published == 'true'
run: |
echo "## 📦 Published Packages" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Dist-tag:** \`${{ steps.dist-tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Type:** \`${{ steps.dist-tag.outputs.branch_type }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
echo '${{ steps.changesets.outputs.publishedPackages }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: No changes to publish
if: steps.changesets.outputs.published != 'true'
run: echo "No changesets to publish"