@@ -2,59 +2,38 @@ name: Redirects Workflow
2
2
on :
3
3
pull_request :
4
4
branches : [main]
5
- types : [opened, synchronize, labeled]
6
5
env :
7
- DIFF_DIRECTORIES : ' src/pages src/fragments'
6
+ ARTIFACT_NAME : ' redirectsArtifact'
7
+ PATHS_TO_CHECK : ' src/pages,src/fragments'
8
8
jobs :
9
- onPrOpen :
10
- name : Check if redirects are needed on PR opened
9
+ checkIfRedirectsAreNeeded :
10
+ name : Check if redirects are needed
11
11
runs-on : ubuntu-latest
12
- if : github.event.action == 'opened'
13
12
steps :
14
- - name : Checkout repository
15
- uses : actions/checkout@v3
16
- with :
17
- # Minimal depth 2 so we can checkout the commit before possible merge commit.
18
- fetch-depth : 2
13
+ - name : Checkout repository to get the workflow scripts
14
+ uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 https://github.com/actions/checkout/commit/c85c95e3d7251135ab7dc9ce3241c5835cc595a9
19
15
- name : Get count of deleted files
20
- env :
21
- GITHUB_PULL_REQUEST_HEAD_SHA : ${{ github.pull_request.head.sha }}
22
- run : |
23
- git fetch origin main
24
- echo "DELETED_FILES_ON_OPENED=$(git diff --name-status --diff-filter=D origin/main -- ${{ env.DIFF_DIRECTORIES }} ${{ env.GITHUB_PULL_REQUEST_HEAD_SHA }} | wc -l)" >> $GITHUB_ENV
25
- - name : Print number of deleted files
26
- run : |
27
- echo "Deleted file count: ${{ env.DELETED_FILES_ON_OPENED }}"
28
- - name : Fail status check if there are deleted files
29
- if : ${{ env.DELETED_FILES_ON_OPENED > 0 }}
30
- run : exit 1
31
- onPrSync :
32
- name : Check if redirects are needed on PR sync
33
- runs-on : ubuntu-latest
34
- if : github.event.action == 'synchronize'
35
- steps :
36
- - name : Checkout repository
37
- uses : actions/checkout@v3
16
+ uses : actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 https://github.com/actions/github-script/commit/d7906e4ad0b1822421a7e6a35d5ca353c962f410
17
+ id : set-deleted-files-count
38
18
with :
39
- # Minimal depth 2 so we can checkout the commit before possible merge commit.
40
- fetch-depth : 2
41
- - name : Get count of deleted files from last sync
19
+ github-token : ${{ secrets.GITHUB_TOKEN }}
20
+ result-encoding : string
21
+ script : |
22
+ const { PATHS_TO_CHECK } = process.env;
23
+ const paths = PATHS_TO_CHECK.split(',');
24
+
25
+ const { getDeletedFilesFromPR } = require('./.github/workflows/scripts/utilities.js');
26
+ return getDeletedFilesFromPR({github, context, paths});
27
+ - name : Create artifact containing the PR number and deleted file count
42
28
env :
43
- GITHUB_EVENT_BEFORE : ${{ github.event.before }}
44
- GITHUB_EVENT_AFTER : ${{ github.event.after }}
45
- run : |
46
- git fetch origin ${{ github.event.before }} --depth=1
47
- echo "DELETED_FILES_ON_SYNC=$(git diff --name-status --diff-filter=D ${{ env.GITHUB_EVENT_BEFORE}} -- ${{ env.DIFF_DIRECTORIES }} ${{ env.GITHUB_EVENT_AFTER }} | wc -l)" >> $GITHUB_ENV
48
- - name : Print number of deleted files
29
+ PR_NUMBER : ${{ github.event.pull_request.number }}
49
30
run : |
50
- echo "Deleted file count: ${{ env.DELETED_FILES_ON_OPENED }}"
51
- - name : Fail status check if there are deleted files
52
- if : ${{ env.DELETED_FILES_ON_SYNC > 0 }}
53
- run : exit 1
54
- failStatusCheck :
55
- name : Fail status check if redirects have not been added
56
- runs-on : ubuntu-latest
57
- if : contains(github.event.pull_request.labels.*.name, 'redirects-needed')
58
- steps :
59
- - name : Exit with error
60
- run : exit 1
31
+ artifactName="${{ env.ARTIFACT_NAME }}.txt"
32
+ echo ${{ env.PR_NUMBER }} >> $artifactName
33
+ echo ${{ steps.set-deleted-files-count.outputs.result }} >> $artifactName
34
+ - name : Upload the redirects file to artifacts
35
+ uses : actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 https://github.com/actions/upload-artifact/commit/0b7f8abb1508181956e8e162db84b466c27e18ce
36
+ with :
37
+ name : ${{ env.ARTIFACT_NAME }}
38
+ path : ' ${{ env.ARTIFACT_NAME }}.txt'
39
+ retention-days : 1
0 commit comments