-
Notifications
You must be signed in to change notification settings - Fork 279
127 lines (112 loc) · 4.6 KB
/
release-snapshot.yml
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
name: Snapshot release
run-name: Snapshot release by ${{ github.actor }}
on:
issue_comment:
types: [created]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.actor }}
cancel-in-progress: true
jobs:
snapshot-release:
if: ${{ startsWith(github.event.comment.body, '!snapshot') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
runs-on: ${{ vars.RUNNER_LARGE }}
timeout-minutes: ${{ fromJSON(vars.TIMEOUT_MINUTES_NORMAL) }}
permissions:
contents: read
id-token: write
steps:
- name: Limit action to Clerk members
uses: actions/github-script@v6
with:
result-encoding: string
retries: 3
retry-exempt-status-codes: 400,401
github-token: ${{ secrets.CLERK_COOKIE_PAT }}
script: |
const isMember = await github.rest.orgs.checkMembershipForUser({
org: 'clerk',
username: context.actor
});
if (!isMember) {
core.setFailed(`@${actor} is not a member of the Clerk organization`);
}
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.issue.number }}/head
- name: Setup
id: config
uses: ./.github/actions/init
with:
turbo-signature: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
turbo-team: ${{ vars.TURBO_TEAM }}
turbo-token: ${{ secrets.TURBO_TOKEN }}
registry-url: "https://registry.npmjs.org"
- name: Extract snapshot name
id: extract-snapshot-name
uses: actions/github-script@v6
with:
script: |
const match = context.payload.comment.body.match(/!snapshot (.*)/)
const name = match && match[1] || '';
const isKebabCase = name.match(/^[a-z]+(-[a-z]+)*$/)
if(name && !isKebabCase) {
core.setFailed(`Invalid snapshot name: ${name}`);
}
core.setOutput('name', name);
- name: Version packages for snapshot
id: version-packages
run: npm run version:snapshot ${{ steps.extract-snapshot-name.outputs.name }} | tail -1 >> "$GITHUB_OUTPUT"
- name: Build release
if: steps.version-packages.outputs.success == '1'
run: npx turbo build $TURBO_ARGS
- name: Snapshot release
if: steps.version-packages.outputs.success == '1'
run: npm run release:snapshot
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Package info
if: steps.version-packages.outputs.success == '1'
id: package-info
uses: actions/github-script@v6
with:
script: |
const fs = require("fs");
const files = await (await glob.create("./packages/*/package.json")).glob();
const descriptors = files
.map((file) => {
const { name, version } = JSON.parse(fs.readFileSync(file, "utf8"));
return { name, version };
})
.filter(({ version }) => version.includes("-${{ steps.extract-snapshot-name.outputs.name }}"));
let table = `| Package | Version |\n| --- | --- |\n`;
descriptors.forEach(({ name, version }) => {
table += `| ${name} | ${version} |\n`;
});
const snippets = descriptors
.map(
({ name, version }) =>
`\`${name}\`\n\`\`\`sh\nnpm i ${name}@${version} --save-exact\n\`\`\``
)
.join("\n");
core.setOutput("table", table);
core.setOutput("snippets", snippets);
- name: Update Comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/[email protected]
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
comment-id: ${{ github.event.comment.id }}
reactions: heart
- name: Create snapshot release comment
if: steps.version-packages.outputs.success == '1'
uses: peter-evans/[email protected]
with:
token: ${{ secrets.CLERK_COOKIE_PAT }}
issue-number: ${{ github.event.issue.number }}
body: |
Hey @${{ github.event.comment.user.login }} - the snapshot version command generated the following package versions:
${{ steps.package-info.outputs.table }}
Tip: Use the snippet copy button below to quickly install the required packages.
${{ steps.package-info.outputs.snippets }}