Skip to content

Commit

Permalink
adding protobin difftool to github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Nov 15, 2023
1 parent 5be5197 commit 240efda
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 2 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/diff_protobin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Diff Protobin

on:
pull_request:
paths:
- '**/*.bin'
jobs:
custom-diff:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install ProtoC
run: sudo apt-get install -y protobuf-compiler

- name: Fetch PR commits
run: |
git fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/pull/${{ github.event.pull_request.number }}/head
git fetch origin ${{ github.base_ref }}
git fetch origin ${{ github.head_ref }}
- name: Get Filenames
run: |
for file in $(git diff --name-only origin/${{ github.base_ref }}...origin/${{ github.head_ref }} | grep '.bin$'); do
if [ -n "$(git ls-tree "origin/${{ github.base_ref }}" -- "$file")" ]; then
git show origin/${{ github.base_ref }}:$file > $file._old
protoc --decode=waypoint.Waypoint xml_converter/proto/waypoint.proto < $file._old > $file._old._textproto
else
touch $file._old._textproto
fi
protoc --decode=waypoint.Waypoint xml_converter/proto/waypoint.proto < $file > $file._textproto
diff -u $file._old._textproto $file._textproto > $file._diff || true
echo $file >> file_list.txt
done
- name: Get PR commit hash
id: prcommithash
run: |
PR_COMMIT_HASH=$(git log --format="%H" -n 1 refs/pull/${{ github.event.pull_request.number }}/head)
echo "Latest PR Commit Hash: $PR_COMMIT_HASH"
echo "pr_commit_hash="$PR_COMMIT_HASH >> $GITHUB_OUTPUT
- name: Post Comment
if: always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const issue_number = context.issue.number;
const githubToken = process.env.GITHUB_TOKEN;
const files = fs.readFileSync('file_list.txt', 'utf8').split("\n");
for (let file of files) {
if (file == "") {
continue;
}
const diff_contents = fs.readFileSync(file + "._diff", 'utf8')
let comment_body = [
"<details>",
"<summary>Full Diff</summary>",
"",
"```diff",
diff_contents,
"```",
"</details>",
].join("\n");
await github.rest.pulls.createReviewComment({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue_number,
path: file,
body: comment_body,
commit_id: '${{ steps.prcommithash.outputs.pr_commit_hash }}',
subject_type: "file",
});
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

E
My Category 2B\�)Cf�RC{�WC� 2B\�)Cf�RC{�WC� 
y
My Category 2B\�)Cf�RC{�WC� 2B\�)Cf�RC{�WC�( 2B\�)Cf�RC{�WC�( 2B\�)Cf�RC{�WC� 
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<POIs>
<POI Type="mycategory" Festival="dragonbash" MapID="50" XPos="169.809998" YPos="210.649994" ZPos="215.830002"/>
<POI Type="mycategory" Festival="superadventurefestival" MapID="50" XPos="169.809998" YPos="210.649994" ZPos="215.830002"/>
<POI Type="mycategory" Festival="superadventurefestival" MapID="50" XPos="169.809998" YPos="210.649994" ZPos="215.830002"/>
<POI Type="mycategory" Festival="festivalofthefourwinds,halloween,lunarnewyear" MapID="50" XPos="169.809998" YPos="210.649994" ZPos="215.830002"/>
</POIs>
</OverlayData>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<POIs>
<POI Festival="DragonBash" Type="mycategory" XPos="169.81" YPos="210.65" ZPos="215.83" MapID="50" />
<POI Festival="SuperAdventureBox" Type="mycategory" XPos="169.81" YPos="210.65" ZPos="215.83" MapID="50" />
<POI Festival="SuperAdventureFestival" Type="mycategory" XPos="169.81" YPos="210.65" ZPos="215.83" MapID="50" />
<POI Festival="FestivalOfTheFourWinds,Halloween,LunarNewYear" Type="mycategory" XPos="169.81" YPos="210.65" ZPos="215.83" MapID="50" />
</POIs>
</OverlayData>

0 comments on commit 240efda

Please sign in to comment.