172 lines
5.5 KiB
YAML
172 lines
5.5 KiB
YAML
# Credit for fingerprint action https://github.com/expo/expo
|
||
# https://github.com/expo/expo/blob/main/.github/workflows/pr-labeler.yml
|
||
---
|
||
name: PR Tests
|
||
|
||
on:
|
||
push:
|
||
branches: [main]
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
|
||
concurrency:
|
||
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
|
||
cancel-in-progress: true
|
||
|
||
permissions:
|
||
pull-requests: write
|
||
actions: write
|
||
contents: read
|
||
|
||
jobs:
|
||
bundle-analyzer:
|
||
runs-on: ubuntu-22.04
|
||
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request'}}
|
||
steps:
|
||
- name: ⬇️ Checkout
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 0
|
||
|
||
- uses: pnpm/action-setup@v6
|
||
|
||
- name: 🔧 Setup Node
|
||
uses: actions/setup-node@v6
|
||
with:
|
||
node-version-file: .nvmrc
|
||
cache: pnpm
|
||
|
||
- name: Ensure tracking relevant branches and checkout base
|
||
env:
|
||
HEAD_REF: ${{ github.head_ref }}
|
||
BASE_REF: ${{ github.base_ref }}
|
||
run: |
|
||
git checkout $HEAD_REF
|
||
git checkout $BASE_REF
|
||
|
||
- name: Get the base commit
|
||
id: base-commit
|
||
env:
|
||
BASE_REF: ${{ github.base_ref }}
|
||
run: echo base-commit=$(git log -n 1 $BASE_REF --pretty=format:'%H') >> "$GITHUB_OUTPUT"
|
||
|
||
- name: Merge PR commit
|
||
env:
|
||
HEAD_REF: ${{ github.head_ref }}
|
||
run: |
|
||
# Have to set a git config for the merge to work
|
||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||
git config --global user.name "github-actions[bot]"
|
||
git merge --no-edit $HEAD_REF
|
||
pnpm install
|
||
pnpm intl:build
|
||
|
||
- name: 🔦 Build and measure PR bundle
|
||
id: pr-size
|
||
run: |
|
||
pnpm build-web
|
||
PR_SIZE=$(find dist/_expo/static/js -name '*.js' ! -name '*.map' -exec cat {} + | wc -c | tr -d ' ')
|
||
echo "size=$PR_SIZE" >> "$GITHUB_OUTPUT"
|
||
echo "size_hr=$(echo "$PR_SIZE" | awk '{printf "%.2f KB", $1/1024}')" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: ⬇️ Get base size from cache
|
||
id: get-base-size
|
||
uses: actions/cache@v5
|
||
with:
|
||
path: base-bundle-size.txt
|
||
key: base-bundle-size-${{ steps.base-commit.outputs.base-commit }}
|
||
|
||
- name: Restore to base commit
|
||
if: ${{ !steps.get-base-size.outputs.cache-hit }}
|
||
run: |
|
||
rm -rf dist
|
||
git reset HEAD~
|
||
git restore .
|
||
|
||
- name: 🔦 Build and measure base bundle
|
||
if: ${{ !steps.get-base-size.outputs.cache-hit }}
|
||
run: |
|
||
pnpm install
|
||
pnpm intl:build
|
||
pnpm build-web
|
||
find dist/_expo/static/js -name '*.js' ! -name '*.map' -exec cat {} + | wc -c | tr -d ' ' > base-bundle-size.txt
|
||
|
||
- name: % Calculate diff
|
||
id: get-diff
|
||
run: |
|
||
BASE_SIZE=$(cat base-bundle-size.txt)
|
||
PR_SIZE=${{ steps.pr-size.outputs.size }}
|
||
DIFF=$((PR_SIZE - BASE_SIZE))
|
||
if [ "$BASE_SIZE" -gt 0 ]; then
|
||
PERCENT=$(awk "BEGIN {printf \"%.2f\", ($DIFF / $BASE_SIZE) * 100}")
|
||
else
|
||
PERCENT="0.00"
|
||
fi
|
||
BASE_HR=$(awk "BEGIN {printf \"%.2f KB\", $BASE_SIZE / 1024}")
|
||
DIFF_HR=$(awk "BEGIN {printf \"%+.2f KB\", $DIFF / 1024}")
|
||
echo "base_hr=$BASE_HR" >> "$GITHUB_OUTPUT"
|
||
echo "diff_hr=$DIFF_HR" >> "$GITHUB_OUTPUT"
|
||
echo "percent=$PERCENT" >> "$GITHUB_OUTPUT"
|
||
|
||
- name: 💬 Drop a comment
|
||
uses: marocchino/sticky-pull-request-comment@v2
|
||
with:
|
||
header: bundle-diff
|
||
message: |
|
||
| Old size | New size | Diff |
|
||
|----------|----------|------|
|
||
| ${{ steps.get-diff.outputs.base_hr }} | ${{ steps.pr-size.outputs.size_hr }} | ${{ steps.get-diff.outputs.diff_hr }} (${{ steps.get-diff.outputs.percent }}%) |
|
||
---
|
||
|
||
fingerprint-native:
|
||
runs-on: ubuntu-22.04
|
||
if: ${{ github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request'}}
|
||
steps:
|
||
- name: ⬇️ Checkout
|
||
uses: actions/checkout@v5
|
||
with:
|
||
fetch-depth: 100
|
||
|
||
- name: ⬇️ Fetch commits from base branch
|
||
run: git fetch origin main:main --depth 100
|
||
if: github.event_name == 'pull_request'
|
||
|
||
- uses: pnpm/action-setup@v6
|
||
|
||
- name: 🔧 Setup Node
|
||
uses: actions/setup-node@v6
|
||
with:
|
||
node-version-file: .nvmrc
|
||
cache: pnpm
|
||
|
||
- name: 📷 Check fingerprint and install dependencies
|
||
id: fingerprint
|
||
uses: bluesky-social/github-actions/fingerprint-native@main
|
||
with:
|
||
profile: pull-request
|
||
|
||
- name: 💬 Drop a comment
|
||
uses: marocchino/sticky-pull-request-comment@v2
|
||
if: ${{ steps.fingerprint.outputs.includes-changes }}
|
||
with:
|
||
header: fingerprint-diff
|
||
message: |
|
||
The Pull Request introduced fingerprint changes against the base commit:
|
||
<details><summary>Fingerprint diff</summary>
|
||
|
||
```json
|
||
${{ steps.fingerprint.outputs.diff }}
|
||
```
|
||
|
||
</details>
|
||
|
||
---
|
||
*Generated by [PR labeler](https://github.com/expo/expo/actions/workflows/pr-labeler.yml) 🤖*
|
||
|
||
- name: 💬 Delete comment
|
||
uses: marocchino/sticky-pull-request-comment@v2
|
||
if: ${{ !steps.fingerprint.outputs.includes-changes }}
|
||
with:
|
||
header: fingerprint-diff
|
||
delete: true
|