Skip to content

Commit 55d1212

Browse files
committed
build(compat): Improve patch freshness check
Run patch freshness check outside of Testing Chores so as not to block other checks. Also, improve the logic to only check the patches that would be affected by the PR changes.
1 parent ec9161e commit 55d1212

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

.github/workflows/integration-workflow.yml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,6 @@ jobs:
4848
env:
4949
TARGET_BRANCH: ${{github.event.pull_request.base.ref}}
5050

51-
- name: 'Check that the patch files are consistent with fresh builds'
52-
run: |
53-
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- packages/plugin-compat/sources/patches packages/plugin-compat/extra/ | wc -l) -gt 0 ]]; then
54-
for generator in packages/plugin-compat/extra/*/gen-*-patch.ts; do
55-
yarn node -r @yarnpkg/monorepo/scripts/setup-ts-execution $generator '*';
56-
done
57-
[[ $(git diff --name-only packages/plugin-compat/sources/patches "packages/plugin-compat/extra/*/patches/*" | tee /dev/stderr | wc -l) -eq 0 ]]
58-
fi
59-
shell: bash
60-
if: |
61-
(success() || failure()) && github.event.pull_request != ''
62-
env:
63-
TARGET_BRANCH: ${{github.event.pull_request.base.ref}}
64-
6551
- name: 'Check that libzip artifacts are consistent with a fresh build (fix w/ "git merge master && bash packages/yarnpkg-libzip/artifacts/build.sh")'
6652
run: |
6753
if [[ $(git diff --name-only "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- 'packages/yarnpkg-libzip/artifacts' 'packages/yarnpkg-libzip/sources/*.js' | wc -l) -gt 0 ]]; then

.github/workflows/plugin-compat-workflow.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,45 @@ jobs:
2424
- name: 'Run the plugin-compat tests'
2525
run: |
2626
node ./scripts/run-yarn.js test:plugin-compat
27+
28+
check-patches:
29+
name: 'Check that the patch files are consistent with fresh builds'
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
- run: |
35+
git fetch --no-tags --unshallow origin HEAD master
36+
37+
- uses: ./.github/actions/prepare
38+
39+
- name: 'Regenerate affected patches'
40+
run: |
41+
PKGS=$(basename -a packages/plugin-compat/extra/*/)
42+
if ! git diff --quiet "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- 'packages/plugin-compat/extra' ':!packages/plugin-compat/extra/*/*'; then
43+
# If a file outside of the package-specific folders changed, rebuild all patches
44+
for pkg in $PKGS; do
45+
echo "::group::Regenerating $pkg patch"
46+
yarn "build:patch:$pkg" '*'
47+
echo "::endgroup::"
48+
done
49+
else
50+
# Otherwise, only rebuild the patches that have changed
51+
for pkg in $PKGS; do
52+
if ! git diff --quiet "$(git merge-base origin/"$TARGET_BRANCH" HEAD)" HEAD -- "packages/plugin-compat/sources/patches/$pkg.patch.ts" "packages/plugin-compat/extra/$pkg/"; then
53+
echo "::group::Regenerating $pkg patch"
54+
yarn "build:patch:$pkg" '*'
55+
echo "::endgroup::"
56+
fi
57+
done
58+
fi
59+
if ! git diff --quiet -- 'packages/plugin-compat/extra/*/patches/*' 'packages/plugin-compat/sources/patches/'; then
60+
echo ''
61+
echo "Files would be changed by fresh builds:"
62+
git diff --name-only -- 'packages/plugin-compat/extra/*/patches/*' 'packages/plugin-compat/sources/patches/' | sed 's/^/- /'
63+
exit 1
64+
fi
65+
shell: bash
66+
if: github.event.pull_request != ''
67+
env:
68+
TARGET_BRANCH: ${{github.event.pull_request.base.ref}}

0 commit comments

Comments
 (0)