Skip to content

Commit 6eb2842

Browse files
authored
Add workflow for manual rule testing (#736)
1 parent 6ad3371 commit 6eb2842

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Manual Rule Test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
rule-name:
7+
description: The name of the refactoring rule to run.
8+
required: true
9+
10+
jobs:
11+
manual-rule-test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Generate a token
16+
id: generate-token
17+
uses: actions/create-github-app-token@v1
18+
with:
19+
app-id: 999945
20+
private-key: ${{ secrets.RESYNTAX_APP_PRIVATE_KEY }}
21+
22+
- name: Get GitHub App User ID
23+
id: get-user-id
24+
run: echo "user-id=$(gh api "/users/${{ steps.generate-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
25+
env:
26+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
27+
28+
- name: Checkout test corpus repository
29+
uses: actions/[email protected]
30+
with:
31+
repository: jackfirth/resyntax-test-corpus
32+
token: ${{ steps.generate-token.outputs.token }}
33+
34+
- name: Install Racket
35+
uses: Bogdanp/[email protected]
36+
with:
37+
version: current
38+
local_catalogs: $GITHUB_WORKSPACE
39+
40+
- name: Ensure test corpus packages are installed
41+
run: raco pkg install --auto --no-setup scribble-doc scribble-html-lib scribble-lib scribble-test scribble-text-lib scribble
42+
43+
- name: Update test corpus packages to local dirs
44+
run: raco pkg update --link --no-setup scribble-8.18/scribble-doc scribble-8.18/scribble-html-lib scribble-8.18/scribble-lib scribble-8.18/scribble-test scribble-8.18/scribble-text-lib scribble-8.18/scribble
45+
46+
- name: Compile test corpus packages
47+
run: raco setup --pkgs scribble-doc scribble-html-lib scribble-lib scribble-test scribble-text-lib scribble
48+
49+
- name: Install Resyntax
50+
run: raco pkg install --auto --skip-installed resyntax
51+
52+
- name: Configure token-based access to test corpus repository
53+
run: git remote set-url origin "https://x-access-token:${{ steps.generate-token.outputs.token }}@github.com/jackfirth/resyntax-test-corpus.git"
54+
55+
- name: Configure Git username
56+
run: git config user.name "${{ steps.generate-token.outputs.app-slug }}[bot]"
57+
58+
- name: Configure Git email
59+
run: git config user.email "${{ steps.get-user-id.outputs.user-id }}+${{ steps.generate-token.outputs.app-slug }}[bot]@users.noreply.github.com"
60+
61+
- name: Create branch in test corpus repository
62+
run: git checkout -b autofix-${{ github.run_number }}-${{ github.run_attempt }}
63+
64+
- name: Run Resyntax
65+
id: run-resyntax
66+
run: |
67+
echo "SUMMARY_JSON=$(racket -l- resyntax/cli fix \
68+
--package scribble-doc \
69+
--package scribble-html-lib \
70+
--package scribble-lib \
71+
--package scribble-test \
72+
--package scribble-text-lib \
73+
--package scribble \
74+
--refactoring-rule "${{ inputs.rule-name }}" \
75+
--max-pass-count 1 \
76+
--output-as-json \
77+
--create-multiple-commits)" >> "$GITHUB_OUTPUT"
78+
79+
- name: Push fixes to remote branch
80+
if: ${{ steps.run-resyntax.outputs.SUMMARY_JSON.fix_count > 0 }}
81+
uses: actions/[email protected]
82+
with:
83+
github-token: ${{ steps.generate-token.outputs.token }}
84+
script: |
85+
await exec.exec(
86+
'git push --set-upstream origin autofix-${{ github.run_number }}-${{ github.run_attempt }}',
87+
[],
88+
{cwd: 'cloned-package'});
89+
90+
- name: Create pull request
91+
if: ${{ steps.run-resyntax.outputs.SUMMARY_JSON.fix_count > 0 }}
92+
uses: actions/[email protected]
93+
env:
94+
SUMMARY_JSON: ${{ steps.run-resyntax.outputs.SUMMARY_JSON }}
95+
with:
96+
github-token: ${{ steps.generate-token.outputs.token }}
97+
script: |
98+
const { readFile, writeFile } = require('fs/promises');
99+
const commitMessageBody = process.env.SUMMARY_JSON.commit_message_body;
100+
const targetRepo = await github.rest.repos.get({owner: "jackfirth", repo: "resyntax-test-corpus"});
101+
console.log(targetRepo);
102+
const base = targetRepo.data.default_branch
103+
await github.rest.pulls.create({
104+
owner: "jackfirth",
105+
repo: "resyntax-test-corpus",
106+
title: "Automated Resyntax fixes",
107+
head: "autofix-${{ github.run_number }}-${{ github.run_attempt }}",
108+
base: base,
109+
body: commitMessageBody,
110+
maintainer_can_modify: true,
111+
});

0 commit comments

Comments
 (0)