generated from jackfirth/racket-package-template
-
Notifications
You must be signed in to change notification settings - Fork 10
67 lines (65 loc) · 2.87 KB
/
resyntax-autofixer.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
name: Resyntax Autofixer
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 2"
jobs:
autofix:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: write
pull-requests: write
steps:
- name: Generate a token
id: generate-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.RESYNTAX_APP_ID }}
private-key: ${{ secrets.RESYNTAX_APP_PRIVATE_KEY }}
- name: Get GitHub App User ID
id: get-user-id
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Checkout code
uses: actions/[email protected]
# See https://github.com/actions/checkout/issues/118.
with:
fetch-depth: 0
- name: Install Racket
uses: Bogdanp/[email protected]
with:
version: current
dest: '"${HOME}/racketdist-current-CS"'
sudo: never
- name: Install Resyntax
run: raco pkg install --auto --link --name resyntax
- name: Create a new branch
run: git checkout -b autofix-${{ github.run_number }}-${{ github.run_attempt }}
- name: Run Resyntax
run: racket -l- resyntax/cli fix --directory . --max-fixes 20 --max-modified-files 3 --output-as-commit-message >> /tmp/resyntax-output.txt
- name: Create pull request
uses: actions/[email protected]
with:
github-token: ${{ steps.generate-token.outputs.token }}
script: |
const { readFile, writeFile } = require('fs/promises');
const commitMessageBody = await readFile('/tmp/resyntax-output.txt', { encoding: 'utf8' });
const commitMessageTitle = "Automated Resyntax fixes";
const commitMessage = commitMessageTitle + "\n\n" + commitMessageBody;
await writeFile('/tmp/resyntax-commit-message.txt', commitMessage);
await exec.exec('git config user.name "${{ steps.generate-token.outputs.app-slug }}[bot]"');
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"');
await exec.exec('git commit --all --file=/tmp/resyntax-commit-message.txt');
await exec.exec('git push --set-upstream origin autofix-${{ github.run_number }}-${{ github.run_attempt }}');
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: commitMessageTitle,
head: "autofix-${{ github.run_number }}-${{ github.run_attempt }}",
base: "master",
body: commitMessageBody,
maintainer_can_modify: true,
});