-
Notifications
You must be signed in to change notification settings - Fork 1.2k
157 lines (149 loc) · 5.4 KB
/
welcome.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
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
name: Welcome
on:
pull_request:
types:
# On by default if you specify no types.
- "opened"
- "reopened"
- "synchronize"
# For `skip-label` only.
- "labeled"
- "unlabeled"
jobs:
release-template:
if: ${{ github.head_ref == 'changeset-release/main' || github.head_ref == 'changeset-release/next_major' }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'
- name: Get or Create Comment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs')
const body = await fs.readFileSync('.github/release_template.md', 'utf8')
const result = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
console.log(result.data)
const primerComments = result.data.filter(c => c.user.login == 'github-actions[bot]')
if (!primerComments.length) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: body.replace('{{PR_AUTHOR}}', context.payload.sender.login)
})
}
check-for-changeset:
name: Check for changeset
runs-on: ubuntu-latest
env:
SKIP_LABEL: "skip changeset"
steps:
- if: "contains(github.event.pull_request.labels.*.name, 'skip changeset')"
run: echo "passed"; exit 0;
- if: "!contains(github.event.pull_request.labels.*.name, 'skip changeset')"
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- if: "!contains(github.event.pull_request.labels.*.name, 'skip changeset')"
name: "Check for changeset"
run: script/check-for-changeset
bundle-stats:
needs: release-template
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- run: npm ci
- run: npm run pretest
- name: Reporting bundle sizes
uses: primer/comment-token-update@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: github-actions[bot]
with:
comment-token: 'bundle_table'
script: |
bundles=$(script/bundle-size-report.js)
if [[ $bundles ]]; then
echo "### Bundles with a size change since [latest release](https://github.com/primer/css/releases/latest)"
echo ""
echo "$bundles"
fi
- name: Reporting selector diffs
uses: primer/comment-token-update@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_USER: github-actions[bot]
with:
comment-token: 'diff_report'
script: |
diff=$(script/selector-diff-report)
if [[ $diff ]]; then
echo "### Selectors added/removed since [latest release](https://github.com/primer/css/releases/latest)"
echo ""
echo "\`\`\`diff"
echo "$diff"
echo "\`\`\`"
fi
label-release:
if: ${{ github.repository == 'primer/css' }}
name: Semantic Version Label
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
id: version-result
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
result-encoding: string
script: |
const diff_url = context.payload.pull_request.diff_url
const result = await github.request(diff_url)
const match = [...result.data.matchAll(/^\+['"]@primer\/css['"]:\s(patch|minor|major)/mg)]
if (match && match[0]) {
return match[0][1]
}
- uses: actions/github-script@v7
env:
RELEASE: ${{ steps.version-result.outputs.result }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
if (process.env.RELEASE == 'undefined') { return }
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const currentLabels = issue.data.labels.map( l => l.name)
const newLabel = `${process.env.RELEASE} release`
if (!currentLabels.includes(newLabel)) {
const otherReleaseLabels = currentLabels.filter( l => l.endsWith(' release'))
if (otherReleaseLabels.length) {
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: [otherReleaseLabels]
})
}
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [newLabel]
})
}