chore: comment diffs automatically #29
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: Comment diffs | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: | |
- main | |
paths: | |
- '.github/workflows/comment-diffs.yml' | |
- 'packages/create-react-native-library/**' | |
- '!**.md' | |
jobs: | |
comment-diffs: | |
runs-on: macos-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup | |
uses: ./.github/actions/setup | |
- name: Build crnl | |
run: | | |
yarn workspace create-react-native-library prepare | |
- name: Create library | |
run: | | |
./packages/create-react-native-library/bin/create-react-native-library new-version \ | |
--slug @bob/react-native-test \ | |
--description test \ | |
--author-name test \ | |
--author-email test@test \ | |
--author-url https://test.test \ | |
--repo-url https://test.test \ | |
--type module-mixed \ | |
--languages java-objc \ | |
--no-example \ | |
--no-local | |
- name: Store the commit hash | |
id: head_hash | |
run: echo "HEAD_HASH=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- name: Fetch main | |
run: git fetch origin main | |
- name: Checkout main | |
run: git checkout origin/main | |
# Removed this step for the sake of testing | |
# - name: Setup again # Add a check here to setup again if deps changed | |
# uses: ./.github/actions/setup | |
- name: Remove old build and build again | |
run: | | |
rm -rf ./packages/create-react-native-library/lib | |
yarn workspace create-react-native-library prepare | |
- name: Create library again | |
run: | | |
./packages/create-react-native-library/bin/create-react-native-library old-version \ | |
--slug @bob/react-native-test \ | |
--description test \ | |
--author-name test \ | |
--author-email test@test \ | |
--author-url https://test.test \ | |
--repo-url https://test.test \ | |
--type module-mixed \ | |
--languages java-objc \ | |
--no-example \ | |
--no-local | |
- name: Diff the libraries | |
id: diff | |
run: | | |
echo "DIFF_RESULT<<EOF" >> $GITHUB_OUTPUT | |
# Diff in recursive mod with unified format (unified format uses - and + instead of < and >) | |
diff -r -u --no-ignore-file-name-case old-version new-version >> $GITHUB_OUTPUT || true | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Comment on PR | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const body = `The commit with hash: ${{ steps.head_hash.outputs.HEAD_HASH }} has changed the output of \`create-react-native-library\`. You can find the diff of the change below: | |
\`\`\`diff | |
${{ steps.diff.outputs.DIFF_RESULT }} | |
\`\`\` | |
> This diff is between this branch and the \`main\` branch. | |
`; | |
const comments = await github.issues.listComments({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
if (comments.data.some(comment => comment.body === body)) { | |
return; | |
} | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body | |
}) | |