-
Notifications
You must be signed in to change notification settings - Fork 35
61 lines (54 loc) · 2.38 KB
/
urlchecker-pr-label.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
# From https://raw.githubusercontent.com/urlstechie/urlchecker-action/master/examples/urlchecker-pr-label.yml
on:
pull_request:
types: [labeled]
name: Commands
jobs:
urlchecks:
# check launched when a PR is labelled with the "needs-url-checks" label
# create that label first :-)
if: contains(github.event.pull_request.labels.*.name, 'needs-url-checks')
name: check-urls
runs-on: ubuntu-latest
steps:
# If you want to use git instead of the API to find changed files
# Use something like https://github.com/actions/checkout#fetch-all-branches
- uses: actions/checkout@v4
# As this only gets one page from the API it is limited to 30 files
# for more, checkout with more depth (see earlier comment)
# and use e.g. https://stackoverflow.com/a/41140296/5489251
# The changed files list is formatted for urlchecker
# and saved as an environment variable so the next step can access it.
- name: list files
run: |
PR=$(jq --raw-output .pull_request.number "${GITHUB_EVENT_PATH}")
echo "PR=${PR}" >> $GITHUB_ENV
files=$(curl --request GET \
--url https://api.github.com/repos/${{ github.repository }}/pulls/$PR/files \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github.antiope-preview+json' \
--header 'content-type: application/json' | jq --raw-output .[].filename | sed 's/^\|$/"/g'|paste -sd, - | tr -d \" | tr -d \')
echo "files=${files}" >> $GITHUB_ENV
# Run URL checks
- name: URLs-checker
uses: urlstechie/urlchecker-action@master
with:
save: "urls.csv"
# only include the changed files
include_files: ${{ env.files }}
print_all: true,
exclude_patterns: http://api.qrserver.com,http://172.
# In case of failure, upload results as artifacts
- name: Archive URL checking results
if: failure()
uses: actions/upload-artifact@v4.5.0
with:
name: urlchecker-results
path: urls.csv
# Remove the label from the PR after the checks are done
- name: Delete label
if: always()
run: |
curl --request DELETE \
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ env.PR }}/labels/needs-url-checks \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \