Skip to content

chore: comment diffs automatically #5

chore: comment diffs automatically

chore: comment diffs automatically #5

Workflow file for this run

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-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-local
- name: Diff the libraries
id: diff
run: |
echo "DIFF_RESULT=$(diff -r old-library new-library)" $GITHUB_OUTPUT
- name: Comment on PR
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs')
const diff = fs.readFileSync('${{ steps.diff.outputs.DIFF_RESULT }}', 'utf-8');
const channel = 'pr-${{ github.event.number }}';
const url = `https://expo.dev/@react-navigation/react-navigation-example?serviceType=eas&distribution=expo-go&scheme=exp+react-navigation-example&channel=${channel}&sdkVersion=${sdkVersion}`;
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
})