forked from mdn/translated-content
-
Notifications
You must be signed in to change notification settings - Fork 1
85 lines (75 loc) · 2.89 KB
/
pr-review-lint-companion.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# NOTE! This is a copy of
# https://github.com/mdn/content/blob/main/.github/workflows/pr-review-companion.yml
# with absolutely minor differences.
# Things to do and run after a "PR Test" workflow has finished successfully.
# Note, as of right now, this workflow does a bunch of things. It might be
# worth considering to break it up so there's a dedicated post-PR
# workflow just to posting PR comments about flaws, for example.
name: PR review lint companion
on:
workflow_run:
workflows: ["Add lint reviews to PRs"]
types:
- completed
jobs:
review:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'failure'
steps:
- name: "Download artifact"
uses: actions/github-script@v6
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
const matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "diff"
});
if (matchArtifacts.length === 0) {
console.warn(
'No artifacts to download probably just means nothing ' +
'was built in the "PR test" workflow. That\'s OK. ' +
'This is actually not a genuine CI error.'
);
throw new Error(
'No matched build artifacts. ' +
'Perhaps nothing built in the "PR test" workflow'
);
}
const matchArtifact = matchArtifacts[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/diff.zip', Buffer.from(download.data));
- name: Unzip what was downloaded
run: |
7z x diff.zip -odiff -bb1
GITHUB_REF=$(cat diff/event.json | jq -r .pull_request.head.ref)
echo "GITHUB_REF=${GITHUB_REF}" >> $GITHUB_ENV
- name: "Checkout PR"
uses: actions/checkout@v3
with:
ref: ${{ env.GITHUB_REF }}
path: content
- name: Setup reviewdog
uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export GITHUB_EVENT_PATH="${{github.workspace}}/diff/event.json"
cd content
reviewdog \
-name="mdn-linter" \
-f=diff \
-f.diff.strip=1 \
-reporter=github-pr-review < "${{github.workspace}}/diff/diff"