Skip to content

Commit 95137d2

Browse files
committed
Add Resyntax pull request analysis workflows
1 parent 2fba63c commit 95137d2

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Resyntax Analysis
2+
3+
# The Resyntax integration is split into two phases: a workflow that analyzes the code and uploads
4+
# the analysis as an artifact, and a workflow that downloads the analysis artifact and creates a
5+
# review of the pull request. This split is for permissions reasons; the analysis workflow checks out
6+
# the pull request branch and compiles it, executing arbitrary code as it does so. For that reason,
7+
# the first workflow has read-only permissions in the github repository. The second workflow only
8+
# downloads the pull request review artifact and submits it, and it executes with read-write permissions
9+
# without executing any code in the repository. This division of responsibilities allows Resyntax to
10+
# safely analyze pull requests from forks. This strategy is outlined in the following article:
11+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
12+
13+
on:
14+
pull_request:
15+
types:
16+
- opened
17+
- reopened
18+
- synchronize
19+
- ready_for_review
20+
21+
jobs:
22+
analyze:
23+
runs-on: ubuntu-latest
24+
if: ${{ github.triggering_actor != 'resyntax-ci[bot]' }}
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/[email protected]
31+
# See https://github.com/actions/checkout/issues/118.
32+
with:
33+
fetch-depth: 0
34+
- uses: Bogdanp/[email protected]
35+
with:
36+
version: stable
37+
- run: raco pkg install --batch --auto --link --name resyntax
38+
- name: Analyze changed files
39+
run: racket -l- resyntax/cli analyze --local-git-repository . "origin/${GITHUB_BASE_REF}" --output-as-github-review --output-to-file ./resyntax-review.json
40+
- name: Upload analysis artifact
41+
uses: actions/[email protected]
42+
with:
43+
name: resyntax-review
44+
path: resyntax-review.json
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Resyntax Review Submission
2+
3+
# The Resyntax integration is split into two workflows. See ./resyntax-analyze.yml for details about
4+
# why it works this way.
5+
6+
on:
7+
workflow_run:
8+
workflows: ["Resyntax Analysis"]
9+
types:
10+
- completed
11+
12+
jobs:
13+
review:
14+
runs-on: ubuntu-latest
15+
if: >
16+
${{ github.event.workflow_run.event == 'pull_request' &&
17+
github.event.workflow_run.conclusion == 'success' }}
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
permissions:
21+
pull-requests: write
22+
23+
steps:
24+
- name: Checkout code
25+
uses: actions/[email protected]
26+
- name: Download Resyntax analysis
27+
# This uses a github script instead of the download-artifact action because
28+
# that action doesn't work for artifacts uploaded by other workflows. See
29+
# https://github.com/actions/download-artifact/issues/130 for more info.
30+
uses: actions/[email protected]
31+
with:
32+
script: |
33+
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
34+
owner: context.repo.owner,
35+
repo: context.repo.repo,
36+
run_id: ${{github.event.workflow_run.id }},
37+
});
38+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
39+
return artifact.name == "resyntax-review"
40+
})[0];
41+
var download = await github.rest.actions.downloadArtifact({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
artifact_id: matchArtifact.id,
45+
archive_format: 'zip',
46+
});
47+
var fs = require('fs');
48+
fs.writeFileSync('${{github.workspace}}/resyntax-review.zip', Buffer.from(download.data));
49+
- run: unzip resyntax-review.zip
50+
- name: Create pull request review
51+
uses: actions/[email protected]
52+
with:
53+
github-token: ${{ secrets.GITHUB_TOKEN }}
54+
script: |
55+
var create_review_request = require('./resyntax-review.json');
56+
await github.rest.pulls.createReview(create_review_request);

0 commit comments

Comments
 (0)