From 30cd3c9afc6950487babc5e1d689ef91600d235f Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 14 Mar 2024 10:37:17 -0700 Subject: [PATCH] test pr labeler --- .../workflows/bundle-deploy-eas-update.yml | 11 +- .github/workflows/pull-request-commit.yml | 183 ++++++++++++++++++ 2 files changed, 190 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pull-request-commit.yml diff --git a/.github/workflows/bundle-deploy-eas-update.yml b/.github/workflows/bundle-deploy-eas-update.yml index ba42a56896..fca97362e9 100644 --- a/.github/workflows/bundle-deploy-eas-update.yml +++ b/.github/workflows/bundle-deploy-eas-update.yml @@ -2,6 +2,9 @@ name: Bundle and Deploy EAS Update on: + push: + branches: + - hailey/expo-updates workflow_dispatch: inputs: runtimeVersion: @@ -18,10 +21,6 @@ jobs: run: | [[ "${{ github.event.inputs.runtimeVersion }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && echo "Version is valid" || exit 1 - - name: ๐Ÿ‘† Validate fingerprint - run: | - [[ $(npx --yes @expo/fingerprint@latest . fingerprint.json) == "[]" ]] && echo "Fingerprint is valid" || exit 1 - - name: โฌ‡๏ธ Checkout uses: actions/checkout@v4 @@ -43,6 +42,10 @@ jobs: - name: ๐Ÿ”ค Compile Translations run: yarn intl:build + - name: ๐Ÿ‘† Validate fingerprint + run: | + [[ $(npx --yes @expo/fingerprint@latest . fingerprint.json) == "[]" ]] && echo "Fingerprint is valid" || exit 1 + - name: โœ๏ธ Write environment variables run: | export json='${{ secrets.GOOGLE_SERVICES_TOKEN }}' diff --git a/.github/workflows/pull-request-commit.yml b/.github/workflows/pull-request-commit.yml new file mode 100644 index 0000000000..6db1839cad --- /dev/null +++ b/.github/workflows/pull-request-commit.yml @@ -0,0 +1,183 @@ +--- +name: PR labeler + +on: + push: + branches: [main] + pull_request: + types: [opened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + test-suite-fingerprint: + runs-on: ubuntu-22.04 + if: ${{ github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' }} + # REQUIRED: limit concurrency when pushing main(default) branch to prevent conflict for this action to update its fingerprint database + concurrency: fingerprint-${{ github.event_name != 'pull_request' && 'main' || github.run_id }} + permissions: + # REQUIRED: Allow comments of PRs + pull-requests: write + # REQUIRED: Allow updating fingerprint in acton caches + actions: write + steps: + - name: ๐Ÿ‘€ Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 100 + - name: โฌ‡๏ธ Fetch commits from base branch + run: git fetch origin main:main --depth 100 + if: github.event_name == 'pull_request' + - name: โฌข Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + - name: โ™ป๏ธ Restore caches + uses: ./.github/actions/expo-caches + id: expo-caches + with: + yarn-workspace: 'true' + - name: ๐Ÿงถ Install node modules in root dir + if: steps.expo-caches.outputs.yarn-workspace-hit != 'true' + run: yarn install --frozen-lockfile + - name: Get the base commit + id: base-commit + run: | + # Since we limit this pr-labeler workflow only triggered from limited paths, we should use custom base commit + echo base-commit=$(git log -n 1 main --pretty=format:'%H' -- .github/workflows/pr-labeler.yml apps/bare-expo apps/test-suite packages yarn.lock) >> "$GITHUB_OUTPUT" + - name: ๐Ÿ“ท Check fingerprint + id: fingerprint + uses: expo/expo-github-action/fingerprint@main + with: + working-directory: apps/bare-expo + previous-git-commit: ${{ steps.base-commit.outputs.base-commit }} + + - name: ๐Ÿ‘€ Debug fingerprint + run: | + echo "previousGitCommit=${{ steps.fingerprint.outputs.previous-git-commit }} currentGitCommit=${{ steps.fingerprint.outputs.current-git-commit }}" + echo "isPreviousFingerprintEmpty=${{ steps.fingerprint.outputs.previous-fingerprint == '' }}" + + - name: ๐Ÿท๏ธ Labeling PR + uses: actions/github-script@v6 + if: ${{ github.event_name == 'pull_request' && steps.fingerprint.outputs.fingerprint-diff == '[]' }} + with: + script: | + try { + await github.rest.issues.removeLabel({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: ['bot: fingerprint changed'] + }) + } catch (e) { + if (e.status != 404) { + throw e; + } + } + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['bot: fingerprint compatible'] + }) + - name: ๐Ÿท๏ธ Labeling PR + uses: actions/github-script@v6 + if: ${{ github.event_name == 'pull_request' && steps.fingerprint.outputs.fingerprint-diff != '[]' }} + with: + script: | + try { + await github.rest.issues.removeLabel({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + name: ['bot: fingerprint compatible'] + }) + } catch (e) { + if (e.status != 404) { + throw e; + } + } + github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: ['bot: fingerprint changed'] + }) + + - name: ๐Ÿ” Find old comment if it exists + uses: peter-evans/find-comment@v2 + if: ${{ github.event_name == 'pull_request' }} + id: old_comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'expo-bot' + body-includes: + - name: ๐Ÿ’ฌ Add comment with fingerprint + if: ${{ github.event_name == 'pull_request' && steps.fingerprint.outputs.fingerprint-diff != '[]' && steps.old_comment.outputs.comment-id == '' }} + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }} + script: | + const diff = JSON.stringify(${{ steps.fingerprint.outputs.fingerprint-diff}}, null, 2); + const body = ` + The Pull Request introduced fingerprint changes against the base commit: ${{ steps.fingerprint.outputs.previous-git-commit }} +
Fingerprint diff + + \`\`\`json + ${diff} + \`\`\` + +
+ + --- + *Generated by [PR labeler](https://github.com/expo/expo/actions/workflows/pr-labeler.yml) ๐Ÿค–* + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body, + }); + - name: ๐Ÿ’ฌ Update comment with fingerprint + if: ${{ github.event_name == 'pull_request' && steps.fingerprint.outputs.fingerprint-diff != '[]' && steps.old_comment.outputs.comment-id != '' }} + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }} + script: | + const diff = JSON.stringify(${{ steps.fingerprint.outputs.fingerprint-diff}}, null, 2); + const body = ` + The Pull Request introduced fingerprint changes against the base commit: ${{ steps.fingerprint.outputs.previous-git-commit }} +
Fingerprint diff + + \`\`\`json + ${diff} + \`\`\` + +
+ + --- + *Generated by [PR labeler](https://github.com/expo/expo/actions/workflows/pr-labeler.yml) ๐Ÿค–* + `; + + github.rest.issues.updateComment({ + issue_number: context.issue.number, + comment_id: '${{ steps.old_comment.outputs.comment-id }}', + owner: context.repo.owner, + repo: context.repo.repo, + body: body, + }); + - name: ๐Ÿ’ฌ Delete comment with fingerprint + if: ${{ github.event_name == 'pull_request' && steps.fingerprint.outputs.fingerprint-diff == '[]' && steps.old_comment.outputs.comment-id != '' }} + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }} + script: | + github.rest.issues.deleteComment({ + issue_number: context.issue.number, + comment_id: '${{ steps.old_comment.outputs.comment-id }}', + owner: context.repo.owner, + repo: context.repo.repo, + }); \ No newline at end of file