Resyntax Autofixer #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Resyntax Autofixer | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * 0" | |
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.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Checkout code | |
uses: actions/checkout@v3.6.0 | |
# See https://github.com/actions/checkout/issues/118. | |
with: | |
fetch-depth: 0 | |
- name: Install Racket | |
uses: Bogdanp/setup-racket@v1.9.1 | |
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 disposable disposable-test | |
raco pkg update --auto --no-setup disposable disposable-test | |
- name: Install local packages | |
run: raco setup --pkgs disposable disposable-test | |
- 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 10 --output-as-commit-message >> /tmp/resyntax-output.txt | |
- name: Create pull request | |
uses: actions/github-script@v6.4.1 | |
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 "Resyntax CI"'); | |
await exec.exec('git config user.email "${{ vars.APP_ID }}+resyntax-ci[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, | |
}); |