-
Notifications
You must be signed in to change notification settings - Fork 24
212 lines (172 loc) Β· 6.98 KB
/
Copy pathcreate-release-pr.yml
File metadata and controls
212 lines (172 loc) Β· 6.98 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
201
202
203
204
205
206
207
208
209
210
211
212
name: Create Release PR
run-name: ${{ github.actor }} is releasing app π
on:
workflow_dispatch:
pull_request:
types:
- closed
branches:
- "main"
jobs:
create-pre-release-pull-request:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: main
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: lts/*
- name: Install Yarn
run: npm install -g yarn
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Install dependencies and execute release
run: |
yarn
yarn release:patch
- name: Get modified files and validate
id: validate-files
run: |
echo "π Checking staged files..."
modified_files=$(git ls-files -m -o --exclude-standard)
if [ -z "$modified_files" ]; then
echo "β No modified files found"
exit 1
fi
# Extract package.json and CHANGELOG.md paths
package_json_path=$(echo "$modified_files" | grep "package.json" | head -n 1)
changelog_path=$(echo "$modified_files" | grep "CHANGELOG.md" | head -n 1)
if [ -z "$package_json_path" ]; then
echo "β package.json not found among modified files"
exit 1
fi
if [ -z "$changelog_path" ]; then
echo "β CHANGELOG.md not found among modified files"
exit 1
fi
# Extract changelog content
latest_changelog=$(git diff --no-color "$changelog_path" | grep -E '^(\+[^+]|-)' | grep -Ev '^--- a/' | sed 's/^+//;s/^-//')
if [ -z "$latest_changelog" ]; then
echo "β CHANGELOG.md has no changes"
exit 1
fi
# Save to temp file
changelog_temp_file=$(mktemp)
echo "$latest_changelog" > "$changelog_temp_file"
# Extract package info
package_name=$(jq -r '.name' "$package_json_path")
package_name="${package_name//@/}"
package_version=$(jq -r '.version' "$package_json_path")
echo "π¦ Package: $package_name"
echo "π·οΈ Version: $package_version"
# Set outputs
echo "package_name=$package_name" >> $GITHUB_OUTPUT
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "changelog_temp_file=$changelog_temp_file" >> $GITHUB_OUTPUT
echo "branchName=pre-release/$package_name/$package_version" >> $GITHUB_OUTPUT
- name: Check branch and create commit
run: |
branchName="${{ steps.validate-files.outputs.branchName }}"
echo "πΏ Branch: $branchName"
if git ls-remote --exit-code --heads origin "$branchName"; then
echo "β Branch already exists"
exit 1
fi
git checkout -B "$branchName"
git add -A
git commit -m "chore(RELEASE): ${{ steps.validate-files.outputs.package_version }}"
git push --set-upstream origin "$branchName"
echo "β
Branch and commit created"
- name: Create PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
changelog_content=$(cat "${{ steps.validate-files.outputs.changelog_temp_file }}")
default_branch=$(git remote show origin | grep 'HEAD branch' | awk '{print $NF}')
echo "π Creating PR..."
pr_url=$(gh pr create \
--title "chore(RELEASE): ${{ steps.validate-files.outputs.package_version }}" \
--body "$changelog_content" \
--base "$default_branch" \
--head "${{ steps.validate-files.outputs.branchName }}")
echo "β
PR created: $pr_url"
# Cleanup
rm -f "${{ steps.validate-files.outputs.changelog_temp_file }}"
release:
runs-on: ubuntu-latest
if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'pre-release/excel-collab/')
permissions:
contents: write
pull-requests: read
actions: write
steps:
- uses: actions/checkout@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: "main"
fetch-depth: 1
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: lts/*
- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Fetch PR metadata and create release
id: release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "π Fetching PR metadata..."
PR_NUMBER=${{ github.event.pull_request.number }}
PR_META=$(gh pr view "$PR_NUMBER" --json number,title,body,mergeCommit)
PR_TITLE=$(echo "$PR_META" | jq -r '.title')
PR_BODY=$(echo "$PR_META" | jq -r '.body')
TAG_NAME=$(echo "$PR_TITLE" | sed -e 's/^chore(RELEASE): *//' -e 's/ *$//')
COMMIT_ID=$(echo "$PR_META" | jq -r '.mergeCommit.oid')
if [ -z "$COMMIT_ID" ]; then
echo "β No merge commit found"
exit 1
fi
# Validate version format
if [[ ! "$TAG_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-hotfix-[0-9]+)?$ ]]; then
echo "β Invalid version format: $TAG_NAME"
exit 1
fi
echo "π Creating release: $TAG_NAME"
# Create release using gh CLI
gh release create "$TAG_NAME" \
--repo "$GITHUB_REPOSITORY" \
--title "$TAG_NAME" \
--target "$COMMIT_ID" \
--notes "$PR_BODY"
echo "β
Release created successfully: $TAG_NAME"
- name: Trigger publish workflow
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "π Triggering publish workflow..."
# Check if release was created successfully
if [ "${{ job.status }}" != "success" ]; then
echo "β Release job failed, skipping publish trigger"
exit 0
fi
# Trigger publish workflow using workflow_dispatch event
gh workflow run publish.yml \
--repo "$GITHUB_REPOSITORY" \
--ref "main" \
|| echo "β οΈ Failed to trigger publish workflow"
echo "β
Publish workflow triggered"