Skip to content

Commit f05a074

Browse files
committed
build: add label commands workflow
1 parent 28edaba commit f05a074

File tree

1 file changed

+234
-0
lines changed

1 file changed

+234
-0
lines changed

.github/workflows/label_commands.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2024 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# Workflow name:
20+
name: label_commands
21+
22+
# Workflow triggers:
23+
on:
24+
pull_request:
25+
types:
26+
- labeled
27+
28+
# Workflow jobs:
29+
jobs:
30+
31+
# Define a job for removing the label and adding in-progress label:
32+
manage_labels:
33+
34+
# Define a display name:
35+
name: 'Manage labels'
36+
37+
# Define the type of virtual host machine:
38+
runs-on: ubuntu-latest
39+
40+
# Define the conditions under which the job should run:
41+
if: |
42+
github.event.label.name == 'bot: Merge' ||
43+
github.event.label.name == 'bot: Rebase' ||
44+
github.event.label.name == 'bot: Check Files' ||
45+
github.event.label.name == 'bot: Lint Autofix' ||
46+
github.event.label.name == 'bot: Update Copyright Years'
47+
48+
# Define the job's steps:
49+
steps:
50+
51+
- name: 'Remove label'
52+
# Pin action to full length commit SHA
53+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
54+
with:
55+
github-token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
56+
script: |
57+
try {
58+
await github.rest.issues.removeLabel({
59+
'owner': context.repo.owner,
60+
'repo': context.repo.repo,
61+
'issue_number': context.issue.number,
62+
'name': '${{ github.event.label.name }}'
63+
})
64+
} catch ( error ) {
65+
console.log( 'Error removing label: %s', error.message );
66+
}
67+
68+
- name: 'Add in-progress label'
69+
# Pin action to full length commit SHA
70+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
71+
with:
72+
github-token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
73+
script: |
74+
github.rest.issues.addLabels({
75+
'owner': context.repo.owner,
76+
'repo': context.repo.repo,
77+
'issue_number': context.issue.number,
78+
'labels': ['bot: In Progress']
79+
})
80+
81+
# Add initial reaction to comment with slash command:
82+
- name: 'Add initial reaction'
83+
run: |
84+
curl -X POST \
85+
-H "Accept: application/vnd.github.v3+json" \
86+
-H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \
87+
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/reactions" \
88+
-d '{"content":"eyes"}'
89+
90+
# Define a job for checking for required files:
91+
check_files:
92+
93+
# Define a display name:
94+
name: 'Check for required files'
95+
96+
# Ensure initial reaction job has completed before running this job:
97+
needs: [ manage_labels ]
98+
99+
# Define the conditions under which the job should run:
100+
if: |
101+
github.event.label.name == 'bot: Check Files'
102+
103+
# Run reusable workflow:
104+
uses: ./.github/workflows/check_required_files.yml
105+
with:
106+
pull_request_number: ${{ github.event.pull_request.number }}
107+
user: ${{ github.event.sender.login }}
108+
secrets:
109+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
110+
111+
# Define a job for updating copyright header years:
112+
update_copyright_years:
113+
114+
# Define a display name:
115+
name: 'Update copyright header years'
116+
117+
# Define the conditions under which the job should run:
118+
if: |
119+
github.event.label.name == 'bot: Update Copyright Years'
120+
121+
# Run reusable workflow:
122+
uses: ./.github/workflows/update_pr_copyright_years.yml
123+
with:
124+
pull_request_number: ${{ github.event.pull_request.number }}
125+
secrets:
126+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
127+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
128+
STDLIB_BOT_GPG_PRIVATE_KEY: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
129+
STDLIB_BOT_GPG_PASSPHRASE: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
130+
131+
# Define a job for auto-fixing lint errors:
132+
fix_lint_errors:
133+
134+
# Define a display name:
135+
name: 'Auto-fix lint errors'
136+
137+
# Ensure initial reaction job has completed before running this job:
138+
needs: [ manage_labels ]
139+
140+
# Define the conditions under which the job should run:
141+
if: |
142+
github.event.label.name == 'bot: Lint Autofix'
143+
144+
# Run reusable workflow:
145+
uses: ./.github/workflows/lint_autofix.yml
146+
with:
147+
pull_request_number: ${{ github.event.pull_request.number }}
148+
secrets:
149+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
150+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
151+
STDLIB_BOT_GPG_PRIVATE_KEY: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
152+
STDLIB_BOT_GPG_PASSPHRASE: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
153+
154+
# Define a job for merging develop branch:
155+
merge_develop:
156+
157+
# Define a display name:
158+
name: 'Merge changes from develop branch into this PR'
159+
160+
# Ensure initial reaction job has completed before running this job:
161+
needs: [ manage_labels ]
162+
163+
# Define the conditions under which the job should run:
164+
if: |
165+
github.event.label.name == 'bot: Merge'
166+
167+
# Run reusable workflow:
168+
uses: ./.github/workflows/pr_merge_develop.yml
169+
with:
170+
pull_request_number: ${{ github.event.pull_request.number }}
171+
secrets:
172+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
173+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
174+
STDLIB_BOT_GPG_PRIVATE_KEY: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
175+
STDLIB_BOT_GPG_PASSPHRASE: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
176+
177+
# Define a job for rebasing on develop branch:
178+
rebase_develop:
179+
180+
# Define a display name:
181+
name: 'Rebase this PR on top of develop branch'
182+
183+
# Ensure initial reaction job has completed before running this job:
184+
needs: [ manage_labels ]
185+
186+
# Define the conditions under which the job should run:
187+
if: |
188+
github.event.label.name == 'bot: Rebase'
189+
190+
# Run reusable workflow:
191+
uses: ./.github/workflows/pr_rebase_develop.yml
192+
with:
193+
pull_request_number: ${{ github.event.pull_request.number }}
194+
secrets:
195+
REPO_GITHUB_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}
196+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
197+
STDLIB_BOT_GPG_PRIVATE_KEY: ${{ secrets.STDLIB_BOT_GPG_PRIVATE_KEY }}
198+
STDLIB_BOT_GPG_PASSPHRASE: ${{ secrets.STDLIB_BOT_GPG_PASSPHRASE }}
199+
200+
# Define a job for removing the in-progress label:
201+
remove_progress_label:
202+
203+
# Define a display name:
204+
name: 'Remove in-progress label'
205+
206+
# Define the type of virtual host machine:
207+
runs-on: ubuntu-latest
208+
209+
# Ensure all previous jobs have completed before running this job:
210+
needs: [ manage_labels, check_files, update_copyright_years, fix_lint_errors, merge_develop, rebase_develop ]
211+
212+
# Define the conditions under which the job should run:
213+
if: always()
214+
215+
# Define the job's steps:
216+
steps:
217+
- name: Remove in-progress label
218+
# Run the step regardless of the outcome of previous steps:
219+
if: always()
220+
# Pin action to full length commit SHA
221+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
222+
with:
223+
github-token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
224+
script: |
225+
try {
226+
await github.rest.issues.removeLabel({
227+
'owner': context.repo.owner,
228+
'repo': context.repo.repo,
229+
'issue_number': context.issue.number,
230+
'name': 'bot: In Progress'
231+
})
232+
} catch ( error ) {
233+
console.log( 'Error removing label: %s', error.message );
234+
}

0 commit comments

Comments
 (0)