chore: comment diffs automatically #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: 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: Checkout to main | |
run: | | |
git fetch origin main --depth 1 | |
git checkout origin/main --no-overlay -- docs | |
# 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: | | |
diff -r --no-ignore-file-name-case old-version new-version || true # Just for debugging, promise I'll delete it | |
echo "DIFF_RESULT=$(diff -r --no-ignore-file-name-case old-version new-version || true)" >> $GITHUB_OUTPUT | |
- name: Ls dirs | |
run: | | |
ls -R old-version | |
ls -R new-version | |
- name: Print diff | |
run: | | |
echo ${{ steps.diff.outputs.DIFF_RESULT }} | |
- name: Comment on PR | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fs = require('fs') | |
const diff = '${{ steps.diff.outputs.DIFF_RESULT }}' | |
const channel = 'pr-${{ github.event.number }}'; | |
const body = `The diff | |
${diff} | |
`; | |
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 | |
}) | |