Skip to content

Commit 42b8e1e

Browse files
authored
Add Resyntax Autofixer workflow (#1390)
It's scheduled to run every Friday at midnight and limit pull requests to at most 20 fixes and 3 modified files.
1 parent eabda93 commit 42b8e1e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

.github/workflows/resyntax-analyze.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ on:
2121
jobs:
2222
analyze:
2323
runs-on: ubuntu-latest
24+
if: ${{ github.triggering_actor != 'resyntax-ci[bot]' }}
2425
env:
2526
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2627

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Resyntax Autofixer
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 0 * * 5"
7+
8+
jobs:
9+
autofix:
10+
runs-on: ubuntu-latest
11+
env:
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
permissions:
14+
pull-requests: write
15+
contents: write
16+
steps:
17+
- name: Generate a token
18+
id: generate-token
19+
uses: actions/create-github-app-token@v1
20+
with:
21+
app-id: ${{ vars.RESYNTAX_APP_ID }}
22+
private-key: ${{ secrets.RESYNTAX_APP_PRIVATE_KEY }}
23+
- name: Get GitHub App User ID
24+
id: get-user-id
25+
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
26+
env:
27+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
28+
- name: Checkout code
29+
uses: actions/checkout@v3.0.2
30+
# See https://github.com/actions/checkout/issues/118.
31+
with:
32+
fetch-depth: 0
33+
- name: Install Racket
34+
uses: Bogdanp/setup-racket@v1.9.1
35+
with:
36+
version: current
37+
packages: resyntax
38+
local_catalogs: $GITHUB_WORKSPACE
39+
dest: '"${HOME}/racketdist-current-CS"'
40+
sudo: never
41+
- name: Register local packages
42+
run: |
43+
raco pkg install -i --auto --no-setup --skip-installed typed-racket-test
44+
raco pkg update --auto --no-setup source-syntax typed-racket-lib typed-racket-more typed-racket-compatibility typed-racket-doc typed-racket typed-racket-test
45+
- name: Install local packages
46+
run: raco setup typed typed-racket typed-racket-test typed-scheme
47+
- name: Create a new branch
48+
run: git checkout -b autofix-${{ github.run_number }}-${{ github.run_attempt }}
49+
- name: Run Resyntax
50+
run: racket -l- resyntax/cli fix --directory . --max-fixes 20 --max-modified-files 3 --output-as-commit-message >> /tmp/resyntax-output.txt
51+
- name: Create pull request
52+
uses: actions/github-script@v6.4.1
53+
with:
54+
github-token: ${{ steps.generate-token.outputs.token }}
55+
script: |
56+
const { readFile, writeFile } = require('fs/promises');
57+
const commitMessageBody = await readFile('/tmp/resyntax-output.txt', { encoding: 'utf8' });
58+
const commitMessageTitle = "Automated Resyntax fixes";
59+
const commitMessage = commitMessageTitle + "\n\n" + commitMessageBody;
60+
await writeFile('/tmp/resyntax-commit-message.txt', commitMessage);
61+
await exec.exec('git config user.name "${{ steps.generate-token.outputs.app-slug }}[bot]"');
62+
await exec.exec('git config user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com"');
63+
await exec.exec('git commit --all --file=/tmp/resyntax-commit-message.txt');
64+
await exec.exec('git push --set-upstream origin autofix-${{ github.run_number }}-${{ github.run_attempt }}');
65+
await github.rest.pulls.create({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
title: commitMessageTitle,
69+
head: "autofix-${{ github.run_number }}-${{ github.run_attempt }}",
70+
base: "master",
71+
body: commitMessageBody,
72+
maintainer_can_modify: true,
73+
});

0 commit comments

Comments
 (0)