Skip to content

Commit d2795d5

Browse files
committed
Add workflow checking for missing files
1 parent 9482091 commit d2795d5

1 file changed

Lines changed: 166 additions & 0 deletions

File tree

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2022 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: check_required_files
21+
22+
# Workflow triggers:
23+
on:
24+
# Trigger the workflow when a PR review is requested:
25+
pull_request:
26+
types: [review_requested]
27+
28+
# Workflow jobs:
29+
jobs:
30+
31+
# Define a job for checking that pull requests contain the required files...
32+
check_required_files:
33+
34+
# Define the type of virtual host machine:
35+
runs-on: ubuntu-latest
36+
37+
# Define the sequence of job steps...
38+
steps:
39+
40+
# Checkout the repository:
41+
- name: 'Checkout repository'
42+
uses: actions/checkout@v2
43+
with:
44+
# Specify whether to remove untracked files before checking out the repository:
45+
clean: true
46+
47+
# Limit clone depth to the last 25 commits:
48+
fetch-depth: 25
49+
50+
# Specify whether to download Git-LFS files:
51+
lfs: false
52+
timeout-minutes: 10
53+
54+
# Exit early if the review is not requested from the `stdlib-bot` user:
55+
- name: 'Exit early if review is not requested from stdlib-bot'
56+
run: |
57+
if [[ "${{ github.event.review.requested_reviewer.login }}" != "stdlib-bot" ]]; then
58+
echo "Review not requested from stdlib-bot. Exiting early."
59+
exit 0
60+
fi
61+
62+
# Get list of changed files:
63+
- name: 'Get list of changed files'
64+
id: changed-files
65+
uses: tj-actions/changed-files@v32
66+
with:
67+
separator: ' '
68+
69+
# Check whether the pull request contains a new `README.md` file; if not, exit with a zero exit code:
70+
- name: 'Exit if pull request does not contain a new README.md file'
71+
run: |
72+
if [[ ! "${{ steps.changed-files.outputs.added_files }}" =~ "README.md" ]]; then
73+
echo "Pull request does not contain a new README.md file."
74+
exit 0
75+
fi
76+
77+
# Check whether the pull request contains files which are required to be present for all packages:
78+
- name: 'Check whether the pull request contains files which are required to be present for all packages'
79+
id: check-required-files
80+
run: |
81+
# Define a list of required files:
82+
required_files=(
83+
"package.json"
84+
"README.md"
85+
"docs/repl.txt"
86+
"docs/types/index.d.ts"
87+
"docs/types/test.ts"
88+
"lib/index.js"
89+
"lib/main.js"
90+
"benchmark/benchmark.js",
91+
"examples/index.js"
92+
"test/test.js"
93+
)
94+
# Get path of added `README.md` file:
95+
readme_path="${{ steps.changed-files.outputs.added_files }}" | grep "README.md"
96+
97+
if grep -q '## CLI' "${readme_path}"; then
98+
required_files+=("bin/cli")
99+
required_files+=("docs/usage.txt")
100+
required_files+=("etc/cli_opts.json")
101+
required_files+=("test/test.cli.js")
102+
fi
103+
104+
if grep -q '## C APIs' "${readme_path}"; then
105+
required_files+=("manifest.json")
106+
required_files+=("binding.gyp")
107+
required_files+=("include.gypi")
108+
required_files+=("src/Makefile")
109+
required_files+=("include/stdlib")
110+
fi
111+
112+
if grep -q '### Examples\n\n```c' "${readme_path}"; then
113+
required_files+=("examples/c/example.c")
114+
required_files+=("examples/c/Makefile")
115+
required_files+=("benchmark/c/Makefile")
116+
required_files+=("benchmark/c/benchmark.c")
117+
fi
118+
119+
# Define a list of missing files:
120+
missing_files=()
121+
122+
# Iterate over the list of required files:
123+
for file in "${required_files[@]}"; do
124+
# Check whether the file is present in the pull request:
125+
if [[ ! "${{ steps.changed-files.outputs.added_files }}" =~ "${file}" ]]; then
126+
# If not, add the file to the list of missing files:
127+
missing_files+=("${file}")
128+
fi
129+
done
130+
131+
# Add the list of missing and required files to the workflow output:
132+
echo "::set-output name=missing_files::${missing_files[*]}"
133+
echo "::set-output name=required_files::${required_files[*]}"
134+
135+
shell: bash
136+
timeout-minutes: 10
137+
138+
# Create a comment on the pull request informing the user that the pull request contains all required files:
139+
- name: 'Create a comment on the pull request informing the user that the pull request contains all required files'
140+
uses: peter-evans/create-or-update-comment@v1
141+
if: steps.check-required-files.outputs.missing_files == ''
142+
with:
143+
# Specify the issue or pull request number:
144+
issue-number: ${{ github.event.pull_request.number }}
145+
146+
# Specify the comment body:
147+
body: |
148+
### :white_check_mark: Success
149+
150+
Pull request contains all required files.
151+
152+
# Create a comment on the pull request alerting the user that the pull request is missing required files:
153+
- name: 'Create a comment on the pull request alerting the user that the pull request is missing required file'
154+
uses: peter-evans/create-or-update-comment@v1
155+
if: steps.check-required-files.outputs.missing_files != ''
156+
with:
157+
# Specify the issue or pull request number:
158+
issue-number: ${{ github.event.pull_request.number }}
159+
160+
# Specify the comment body:
161+
body: |
162+
Hi @${{ github.event.pull_request.user.login }}. The pull request contains a new `README.md` file, but is missing the following required files:
163+
164+
- ${ { steps.check-required-files.outputs.missing_files } }
165+
166+
Please add the missing files to the pull request.

0 commit comments

Comments
 (0)