Skip to content

Commit

Permalink
Add Resyntax Autofixer workflow
Browse files Browse the repository at this point in the history
It's scheduled to run every Friday at midnight and limit pull requests to at most 20 fixes and 3 modified files.
  • Loading branch information
jackfirth committed Sep 19, 2024
1 parent eabda93 commit 1cb4a66
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/resyntax-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
jobs:
analyze:
runs-on: ubuntu-latest
if: ${{ github.triggering_actor != 'resyntax-ci[bot]' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
73 changes: 73 additions & 0 deletions .github/workflows/resyntax-autofixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Resyntax Autofixer

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 5"

jobs:
autofix:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions:
pull-requests: write
contents: 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
packages: resyntax
local_catalogs: $GITHUB_WORKSPACE
dest: '"${HOME}/racketdist-current-CS"'
sudo: never
- name: Register local packages
run: |
raco pkg install -i --auto --no-setup --skip-installed typed-racket-test
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
- name: Install local packages
run: raco setup typed typed-racket typed-racket-test typed-scheme
- 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,
});

0 comments on commit 1cb4a66

Please sign in to comment.