-
Notifications
You must be signed in to change notification settings - Fork 278
244 lines (207 loc) · 8.67 KB
/
release.yml
File metadata and controls
244 lines (207 loc) · 8.67 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: release-it
on:
schedule:
# Run weekly on Monday at 1:00 AM UTC
- cron: '0 1 * * 1'
workflow_dispatch:
# Enable manual triggering from the GitHub UI
inputs: {}
# No inputs needed, but we need to specify the branches filter
# Set default permissions as restrictive as possible
permissions: {}
jobs:
check-user:
runs-on: ubuntu-latest
permissions: {} # No permissions needed for user check
# Only run this check for workflow_dispatch events
if: github.event_name == 'workflow_dispatch' &&
contains('["alisonjoseph", "kennylam", "sstrubberg", "tay1orjones", "eng618", "emyarod", "ariellalgilmore" , "riddhybansal" , "annawen1" , "2nikhiltom" , "heloiselui" , "Gururajj77" , "maradwan26" , "sunny-kukkar-ibm" ]',
github.actor)
steps:
- name: User validation
run: echo "User ${{ github.actor }} is authorized to trigger this workflow"
# For workflow_dispatch events - depends on check-user
check-for-new-commits-manual:
runs-on: ubuntu-latest
needs: check-user
if: github.event_name == 'workflow_dispatch'
permissions:
contents: read
outputs:
has_new_commits: ${{ steps.check-commits.outputs.has_new_commits }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for untagged commits
id: check-commits
uses: actions/github-script@v8
with:
script: |
const { execSync } = require('child_process');
try {
// Get the latest commit hash
const latestCommit = execSync('git rev-parse HEAD').toString().trim();
console.log(`Latest commit: ${latestCommit}`);
// Get the most recent tag
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim();
console.log(`Latest tag: ${latestTag}`);
// Get the commit hash of the latest tag
const taggedCommit = execSync(`git rev-list -n 1 ${latestTag}`).toString().trim();
console.log(`Tagged commit: ${taggedCommit}`);
// Check if latest commit is different from the tagged commit
const hasNewCommits = latestCommit !== taggedCommit;
console.log(`Has new commits since last tag: ${hasNewCommits}`);
core.setOutput('has_new_commits', hasNewCommits ? 'true' : 'false');
} catch (error) {
console.log('Error checking tags, assuming new commits needed:', error.message);
core.setOutput('has_new_commits', 'true');
}
- name: Debug commits check
run: |
echo "::group::Debug commits check outputs"
echo "has_new_commits: ${{ steps.check-commits.outputs.has_new_commits }}"
echo "job status: ${{ job.status }}"
echo "::endgroup::"
# For scheduled events - no dependency
check-for-new-commits-scheduled:
runs-on: ubuntu-latest
if: github.event_name == 'schedule'
permissions:
contents: read
outputs:
has_new_commits: ${{ steps.check-commits.outputs.has_new_commits }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for untagged commits
id: check-commits
uses: actions/github-script@v8
with:
script: |
const { execSync } = require('child_process');
try {
// Get the latest commit hash
const latestCommit = execSync('git rev-parse HEAD').toString().trim();
console.log(`Latest commit: ${latestCommit}`);
// Get the most recent tag
const latestTag = execSync('git describe --tags --abbrev=0').toString().trim();
console.log(`Latest tag: ${latestTag}`);
// Get the commit hash of the latest tag
const taggedCommit = execSync(`git rev-list -n 1 ${latestTag}`).toString().trim();
console.log(`Tagged commit: ${taggedCommit}`);
// Check if latest commit is different from the tagged commit
const hasNewCommits = latestCommit !== taggedCommit;
console.log(`Has new commits since last tag: ${hasNewCommits}`);
core.setOutput('has_new_commits', hasNewCommits ? 'true' : 'false');
} catch (error) {
console.log('Error checking tags, assuming new commits needed:', error.message);
core.setOutput('has_new_commits', 'true');
}
- name: Debug commits check
run: |
echo "::group::Debug commits check outputs"
echo "has_new_commits: ${{ steps.check-commits.outputs.has_new_commits }}"
echo "job status: ${{ job.status }}"
echo "::endgroup::"
check-validate-status:
runs-on: ubuntu-latest
needs: [check-for-new-commits-manual, check-for-new-commits-scheduled]
permissions:
actions: read
contents: read
if: |
always() && ((needs.check-for-new-commits-manual.result == 'success' &&
needs.check-for-new-commits-manual.outputs.has_new_commits == 'true') ||
(needs.check-for-new-commits-scheduled.result == 'success' &&
needs.check-for-new-commits-scheduled.outputs.has_new_commits == 'true'))
outputs:
validate_status: ${{ steps.check-validate.outputs.validate_status }}
steps:
- name: Check Validate workflow status
id: check-validate
uses: actions/github-script@v8
with:
script: |
const workflow_name = 'Validate';
const branch = 'main';
const { data: workflows } = await github.rest.actions.listRepoWorkflows({
owner: context.repo.owner,
repo: context.repo.repo
});
const workflow = workflows.workflows.find(w => w.name === workflow_name);
if (!workflow) {
core.setFailed(`Couldn't find workflow named "${workflow_name}"`);
return;
}
const { data: runs } = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: workflow.id,
branch: branch,
status: 'completed',
per_page: 1
});
if (runs.total_count === 0) {
core.setFailed(`No completed runs found for workflow "${workflow_name}" on branch "${branch}"`);
return;
}
const latestRun = runs.workflow_runs[0];
console.log(`Latest ${workflow_name} run conclusion: ${latestRun.conclusion}`);
core.setOutput('validate_status', 'success');
if (latestRun.conclusion !== 'success') {
core.setFailed(`Latest ${workflow_name} run did not succeed. Status: ${latestRun.conclusion}`);
}
- name: Debug output status
run: |
echo "::group::Debug check-validate-status outputs"
echo "Job result: ${{ job.status }}"
echo "Step result: ${{ steps.check-validate.outcome }}"
echo "Validate status: ${{ steps.check-validate.outputs.validate_status }}"
echo "::endgroup::"
release:
runs-on: ubuntu-latest
needs: check-validate-status
# Simplified condition to only check the job result
if: always() && needs.check-validate-status.result == 'success'
permissions:
id-token: write
contents: write
steps:
- name: Debug Conditions
run: |
echo "::group::Debug release conditions"
echo "check-validate-status result: '${{ needs.check-validate-status.result }}'"
echo "::endgroup::"
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up node
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'yarn'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: yarn install --immutable
- name: Initialize Git user
run: |
git config --global user.name "Eric N. Garcia"
git config --global user.email "eng618@garciaericn.com"
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
env:
SSH_PRIVATE_KEY: ${{ SECRETS.SSH_PRIVATE_KEY }}
- name: Upgrade npm
run: npm install -g npm@latest
- name: Run release command
run: yarn release:ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
npm_config_provenance: true
# Lockfile is now updated as part of the release commit via release-it hooks