Skip to content

Commit

Permalink
Merge pull request #92 from hubverse-org/diff-comment-workflow
Browse files Browse the repository at this point in the history
Diff comment workflow
  • Loading branch information
annakrystalli authored Jul 24, 2024
2 parents 0f5c1ed + aa15450 commit 9734436
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .github/workflows/comment-diff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Generate New Spec Diff"

on:
issue_comment:
types: [created]

jobs:
comment-changed-workflow:
name: 'Comment Spec Diff'
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/diff') }}
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: "Record DIFF"
id: dl
run: |
echo "body<<EOF" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
old=$(ls -d */ | sort | tail -n 2 | head -n 1)
new=$(ls -d */ | sort | tail -n 1)
echo "Here are your diffs for this pull request" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo '## `admin-schema.json`' >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo '```diff' >> $GITHUB_ENV
echo "$(diff -u ${old}admin-schema.json ${new}admin-schema.json)" >> $GITHUB_ENV
echo '```' >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo '## `tasks-schema.json`' >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
echo '```diff' >> $GITHUB_ENV
echo "$(diff -u ${old}tasks-schema.json ${new}tasks-schema.json)" >> $GITHUB_ENV
echo '```' >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: "Comment on PR"
uses: carpentries/actions/comment-diff@5d73d6a34b013488264890868d8eeab1edffdf2e
with:
pr: ${{ github.event.issue.number }}
body: ${{ env.body }}

14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ After making a new release to the schema repository, ensure `hubDocs` are also a

## Highlighting changes to schema in PRs

To bring attention to the changes in new schema versions, it's useful to include in any PR, a print out of the diffs in the `tasks-schema.json` and `admin-schema.json` files compared to the previous version. To print the diffs in each file you can use the following commands in the terminal:
To bring attention to the changes in new schema versions, it's useful to include in any PR, a print out of the diffs in the `tasks-schema.json` and `admin-schema.json` files compared to the previous version.

### Automated Process (via GitHub)

After you create a new Pull Request, if you create a new comment with `/diff`, GitHub will automatically generate the diffs of the `tasks-schema.json` and `admin-schema.json` and comment on the pull request.

If you need to update the schema after review, you can update the diffs by creating another `/diff` comment.

If this does not work for any reason, you can follow the manual process below.

### Manual Process

To print the diffs in each file you can use the following commands in the terminal:

#### `admin-schema.json`

Expand Down

0 comments on commit 9734436

Please sign in to comment.