Skip to content

Commit 5e64bdf

Browse files
committed
build: use inputs and secrets in reusable workflow
1 parent 2f1f30e commit 5e64bdf

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

.github/workflows/check_required_files.yml

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ name: check_required_files
2323
on:
2424
# Allow the workflow to be triggered by other workflows
2525
workflow_call:
26+
# Define the input parameters for the workflow:
27+
inputs:
28+
pull_request_number:
29+
description: 'Pull request number'
30+
required: true
31+
type: number
32+
user:
33+
required: true
34+
type: string
35+
# Define the secrets accessible by the workflow:
36+
secrets:
37+
STDLIB_BOT_GITHUB_TOKEN:
38+
description: 'stdlib-bot GitHub token to create pull request comments'
39+
required: true
40+
41+
# Allow the workflow to be manually triggered:
42+
workflow_dispatch:
43+
inputs:
44+
pull_request_number:
45+
description: 'Pull request number'
46+
required: true
47+
type: number
48+
user:
49+
required: true
50+
type: string
2651

2752
# Global permissions:
2853
permissions:
@@ -44,42 +69,15 @@ jobs:
4469
# Define the sequence of job steps...
4570
steps:
4671

47-
# Checkout the repository:
48-
- name: 'Checkout repository'
49-
# Pin action to full length commit SHA
50-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
51-
with:
52-
# Specify whether to remove untracked files before checking out the repository:
53-
clean: true
54-
55-
# Refers to the development branch:
56-
ref: 'develop'
57-
58-
# Refers to the repository name of the pull request:
59-
repository: ${{ github.event.issue.pull_request.head.repo.full_name }}
60-
61-
# Limit clone depth to the most recent commit:
62-
fetch-depth: 1
63-
64-
# Specify whether to download Git-LFS files:
65-
lfs: false
66-
timeout-minutes: 10
67-
68-
# Configure git:
69-
- name: 'Configure git'
70-
run: |
71-
git config --local user.email "noreply@stdlib.io"
72-
git config --local user.name "stdlib-bot"
73-
git fetch --all
74-
7572
# Get list of added files:
7673
- name: 'Get list of added files'
7774
id: added-files
7875
run: |
7976
page=1
8077
files=""
8178
while true; do
82-
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ github.event.issue.pull_request.number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
79+
new_files=$(curl -s -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN
80+
}}" "https://api.github.com/repos/stdlib-js/stdlib/pulls/${{ inputs.pull_request_number }}/files?page=$page&per_page=100" | jq -r '.[] | select(.status == "added") | .filename')
8381
if [ -z "$new_files" ]; then
8482
break
8583
fi
@@ -169,15 +167,15 @@ jobs:
169167
170168
body=""
171169
if [[ "${#missing_files[@]}" -eq 0 ]]; then
172-
body="Hi @${{ github.event.issue.pull_request.user.login }}, thank you for your contribution!
170+
body="Hi @${{ inputs.user }}, thank you for your contribution!
173171
174172
:tada: Your pull request contains all required files for the new package: :tada:
175173
176174
${checkbox_list}
177175
178176
-- stdlib-bot"
179177
else
180-
body="Hi @${{ github.event.issue.pull_request.user.login }}, thank you for your contribution! Your pull request contains a new package, but is missing some of the required files.
178+
body="Hi @${{ inputs.user }}, thank you for your contribution! Your pull request contains a new package, but is missing some of the required files.
181179
182180
Use the following checklist to keep track of the required files and which ones are still missing:
183181
@@ -203,7 +201,7 @@ jobs:
203201
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
204202
with:
205203
# Specify the issue or pull request number:
206-
issue-number: ${{ github.issue.pull_request.number }}
204+
issue-number: ${{ inputs.pull_request_number }}
207205

208206
# Specify the comment body:
209207
body: ${{ steps.check-required-files.outputs.comment-body }}

.github/workflows/slash_commands.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ jobs:
3535

3636
# Run reusable workflow:
3737
uses: ./.github/workflows/check_required_files.yml
38+
with:
39+
pull_request_number: ${{ github.event.issue.pull_request.number }}
40+
user: ${{ github.event.comment.user.login }}
41+
secrets:
42+
STDLIB_BOT_GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
3843

3944
# Define a job for updating copyright header years:
4045
update_copyright_years:

0 commit comments

Comments
 (0)