Skip to content

Commit ccdcfa9

Browse files
authored
Analyze pull requests with Resyntax (#112)
1 parent 7201400 commit ccdcfa9

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/[email protected]
30+
# See https://github.com/actions/checkout/issues/118.
31+
with:
32+
fetch-depth: 0
33+
- name: Install Racket
34+
uses: Bogdanp/[email protected]
35+
with:
36+
version: current
37+
distribution: minimal
38+
local_catalogs: $GITHUB_WORKSPACE
39+
dest: '"${HOME}/racketdist-minimal-CS"'
40+
sudo: never
41+
- name: Register local packages
42+
run: raco pkg install --auto --no-setup plot plot-compat plot-doc plot-gui-lib plot-lib plot-test
43+
- name: Install local packages
44+
run: raco setup --pkgs plot plot-compat plot-doc plot-gui-lib plot-lib plot-test
45+
- name: Install Resyntax
46+
run: raco pkg install --auto resyntax
47+
- name: Analyze changed files
48+
run: xvfb-run racket -l- resyntax/cli analyze --local-git-repository . "origin/${GITHUB_BASE_REF}" --output-as-github-review --output-to-file ./resyntax-review.json
49+
- name: Upload analysis artifact
50+
uses: actions/[email protected]
51+
with:
52+
name: resyntax-review
53+
path: resyntax-review.json
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)