Unverified Commit fc917572 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update CI job skipping based on related changes (#38479)

* Update CI job skipping based on related changes

* add for azure too

* update value

* simplify docs change value

* update value for swc as well
parent 0887d283
......@@ -37,7 +37,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{ steps.docs-change.outputs.docsChange != 'docs only change' }}
if: ${{ steps.docs-change.outputs.docsChange == 'nope' }}
with:
node-version: 16
check-latest: true
......@@ -50,6 +50,12 @@ jobs:
- name: tune linux network
run: sudo ethtool -K eth0 tx off rx off
- name: Check non-docs only change
run: echo ::set-output name=DOCS_CHANGE::$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')
id: docs-change
- run: echo ${{steps.docs-change.outputs.DOCS_CHANGE}}
- run: npm i -g pnpm@${PNPM_VERSION}
- id: get-store-path
......@@ -69,11 +75,6 @@ jobs:
- run: node run-tests.js --timings --write-timings -g 1/1
- run: node ./scripts/fetch-tags.mjs ${{ github.sha }}
- name: Check docs only change
run: echo ::set-output name=DOCS_CHANGE::$(node skip-docs-change.js echo 'not-docs-only-change')
id: docs-change
- run: echo ${{steps.docs-change.outputs.DOCS_CHANGE}}
- id: check-release
run: |
if [[ $(git describe --exact-match 2> /dev/null || :) = v* ]];
......@@ -116,9 +117,21 @@ jobs:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/cache@v3
id: restore-build
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- run: echo ::set-output name=SWC_CHANGE::$(node scripts/run-for-change.js --type next-swc --exec echo 'yup')
id: swc-change
- run: echo ${{ steps.swc-change.outputs.SWC_CHANGE }}
- name: Install
uses: actions-rs/toolchain@v1
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
with:
profile: minimal
toolchain: ${{ env.RUST_TOOLCHAIN }}
......@@ -126,27 +139,20 @@ jobs:
- name: Cache cargo registry
uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
with:
path: ~/.cargo/registry
key: stable-ubuntu-clippy-cargo-registry
- name: Cache cargo index
uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
with:
path: ~/.cargo/git
key: stable-ubuntu-clippy-cargo-index
- uses: actions/cache@v3
id: restore-build
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- name: Check
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
run: |
cargo fmt -- --check
cargo clippy --all -- -D warnings
......@@ -161,24 +167,24 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
# https://github.com/actions/virtual-environments/issues/1187
- name: tune linux network
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/checkout@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: mv .git .git-bak
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
......@@ -187,10 +193,10 @@ jobs:
- run: npm i -g pnpm@${PNPM_VERSION}
- run: rm -rf .git && mv .git-bak .git
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: ./scripts/check-pre-compiled.sh
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- uses: EndBug/add-and-commit@v7
if: ${{ failure() }}
......@@ -208,29 +214,29 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type unit
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testDev:
name: Test Development
......@@ -246,7 +252,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: ${{ matrix.node }}
check-latest: true
......@@ -258,27 +264,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type development
name: Run test/development
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -301,7 +307,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -313,27 +319,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type development
name: Run test/development
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -361,7 +367,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: ${{ matrix.node }}
check-latest: true
......@@ -373,27 +379,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: NEXT_TEST_MODE=dev node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2
name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -421,7 +427,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -433,27 +439,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: NEXT_TEST_MODE=dev node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2
name: Run test/e2e (dev)
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -479,7 +485,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: ${{ matrix.node }}
check-latest: true
......@@ -491,27 +497,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type production
name: Run test/production
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testProdReact17:
name: Test Production (react v17)
......@@ -524,7 +530,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -536,27 +542,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js --type production
name: Run test/production
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testProdE2E:
name: Test Production (E2E)
......@@ -574,7 +580,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: ${{ matrix.node }}
check-latest: true
......@@ -586,27 +592,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: NEXT_TEST_MODE=start node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2
name: Run test/e2e (production)
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testProdE2EReact17:
name: Test Production (E2E) (react v17)
......@@ -624,7 +630,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: ${{ matrix.node }}
check-latest: true
......@@ -636,27 +642,27 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: NEXT_TEST_MODE=start node run-tests.js --type e2e --timings -g ${{ matrix.group }}/2
name: Run test/e2e (production)
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testIntegration:
name: Test Integration
......@@ -673,7 +679,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -685,26 +691,26 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: xvfb-run node run-tests.js --timings -g ${{ matrix.group }}/18
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- name: Upload test trace
if: always()
......@@ -727,32 +733,32 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: cd test/integration/with-electron/app && yarn install
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: xvfb-run node run-tests.js test/integration/with-electron/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testsPass:
name: thank you, next
......@@ -781,29 +787,29 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npx playwright install-deps && npx playwright install firefox
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js test/integration/production/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
# test rsc hydration on firefox due to limited support of TransformStream api
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testSafari:
name: Test Safari (production)
......@@ -820,7 +826,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -830,28 +836,28 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
# TODO: use macos runner so that we can use playwright to test against
# PRs instead of only running on canary?
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || npm i -g browserstack-local@1.4.0'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js -c 1 test/integration/production/test/index.test.js test/e2e/basepath.test.ts'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testSafariOld:
name: Test Safari 10.1 (nav)
......@@ -868,7 +874,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -878,26 +884,26 @@ jobs:
run: sudo ethtool -K eth0 tx off rx off
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || npm i -g browserstack-local@1.4.0'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: '[[ -z "$BROWSERSTACK_ACCESS_KEY" ]] && echo "Skipping for PR" || node run-tests.js test/integration/production-nav/test/index.test.js'
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
testFirefoxNode18:
name: Test Firefox Node.js 18
......@@ -909,27 +915,27 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 18
check-latest: true
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npx playwright install-deps && npx playwright install firefox
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node run-tests.js test/integration/production/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
publishRelease:
if: ${{ needs.build.outputs.isRelease == 'true' }}
......@@ -945,7 +951,7 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
......@@ -999,7 +1005,7 @@ jobs:
key: ${{ github.sha }}-${{ github.run_number }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
......@@ -1067,33 +1073,33 @@ jobs:
with:
fetch-depth: 25
- run: echo ::set-output name=DOCS_CHANGE::$(node skip-docs-change.js echo 'not-docs-only-change')
- run: echo ::set-output name=DOCS_CHANGE::$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')
id: docs-change
- name: Setup node
uses: actions/setup-node@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
node-version: 16
check-latest: true
- name: Install
uses: actions-rs/toolchain@v1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
profile: minimal
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Cache cargo registry
uses: actions/cache@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: ~/.cargo/registry
key: stable-ubuntu-18.04-cargo-registry
- name: Cache cargo index
uses: actions/cache@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: ~/.cargo/git
key: stable-ubuntu-18.04-cargo-index
......@@ -1105,7 +1111,7 @@ jobs:
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-${{ github.sha }}
......@@ -1130,7 +1136,7 @@ jobs:
# to install napi globally
- run: npm i -g @napi-rs/cli@${{ env.NAPI_CLI_VERSION }} turbo@${{ env.TURBO_VERSION }} pnpm@${PNPM_VERSION}
- name: Build
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
run: turbo run build-native --cache-dir=".turbo" -- --release
env:
MACOSX_DEPLOYMENT_TARGET: '10.13'
......@@ -1142,7 +1148,7 @@ jobs:
path: packages/next-swc/native/next-swc.linux-x64-gnu.node
- name: Clear the cargo caches
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
run: |
cargo install cargo-cache --no-default-features --features ci-autoclean
cargo-cache
......@@ -1155,16 +1161,21 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 25
- run: echo ::set-output name=DOCS_CHANGE::$(node skip-docs-change.js echo 'not-docs-only-change')
id: docs-change
- run: echo ::set-output name=SWC_CHANGE::$(node scripts/run-for-change.js --type next-swc --exec echo 'yup')
id: swc-change
- run: echo ${{ steps.swc-change.outputs.SWC_CHANGE }}
- name: Install
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
profile: minimal
- run: cd packages/next-swc && cargo test
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.swc-change.outputs.SWC_CHANGE == 'yup' }}
test-wasm:
name: Test the wasm build
......@@ -1173,49 +1184,49 @@ jobs:
steps:
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: wasm-dev-binary
path: packages/next-swc/crates/wasm/pkg-nodejs
- run: ls packages/next-swc/crates/wasm
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
# node version needs to be 16+ to use --no-addons option
- name: Setup node
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
uses: actions/setup-node@v3
with:
node-version: 16
check-latest: true
- run: npm i -g playwright-chromium@1.22.2 && npx playwright install-deps
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: node ./scripts/setup-wasm.mjs
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: npm i -g pnpm@${PNPM_VERSION}
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: TEST_WASM=true xvfb-run node run-tests.js test/integration/production/test/index.test.js
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
- run: TEST_WASM=true xvfb-run node run-tests.js test/production/react-18-streaming-ssr/index.test.ts
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
# Build binaries for publishing
build-native:
......@@ -1547,14 +1558,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
id: restore-build
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- name: Setup node
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
uses: actions/setup-node@v3
with:
node-version: 16
......@@ -1563,7 +1574,7 @@ jobs:
- run: npm i -g turbo@${{ env.TURBO_VERSION }} pnpm@${PNPM_VERSION}
- name: Install Rust
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
uses: actions-rs/toolchain@v1
with:
profile: minimal
......@@ -1574,7 +1585,7 @@ jobs:
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
path: .turbo
......@@ -1585,19 +1596,19 @@ jobs:
turbo-${{ github.job }}-canary-${{ steps.get-week.outputs.WEEK }}-
- name: Install wasm-pack
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Build
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: turbo run build-wasm --cache-dir=".turbo" -- --target nodejs --dev
- name: Add target to folder name
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: '[[ -d "packages/next-swc/crates/wasm/pkg" ]] && mv packages/next-swc/crates/wasm/pkg packages/next-swc/crates/wasm/pkg-nodejs || ls packages/next-swc/crates/wasm'
- name: Upload artifact
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
uses: actions/upload-artifact@v3
with:
name: wasm-dev-binary
......@@ -1613,6 +1624,7 @@ jobs:
TRACE_API_KEY: ${{ secrets.DATA_DOG_API_KEY }}
if: "${{ env.TRACE_API_KEY != '' }}"
run: echo "::set-output name=defined::true"
build-performance-metrics:
name: Performance Metrics for Release Build
runs-on: ubuntu-latest
......@@ -1623,43 +1635,43 @@ jobs:
steps:
- name: Setup node
uses: actions/setup-node@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
node-version: 16
check-latest: true
- uses: actions/cache@v3
id: restore-build
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
path: ./*
key: ${{ github.sha }}-${{ github.run_number }}
- name: Set Git Short sha Env
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: echo "GIT_SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV
- name: Check Git Short sha Env
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: echo ${GIT_SHORT_SHA}
- uses: actions/download-artifact@v3
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
name: next-swc-test-binary
path: packages/next-swc/native
- name: Generate metrics data
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: |
yarn --cwd bench/nested-deps install
node bench/nested-deps/bench.mjs build
- uses: datadog/agent-github-action@v1
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
with:
api_key: ${{ secrets.DATA_DOG_API_KEY }}
- name: Sending metrics data to Datadog
if: ${{needs.build.outputs.docsChange != 'docs only change'}}
if: ${{needs.build.outputs.docsChange == 'nope'}}
run: |
node scripts/trace-dd.mjs bench/nested-deps/.next/trace build ${GIT_SHORT_SHA} ./bench/nested-deps/next.config.js
env:
......
......@@ -23,33 +23,34 @@ jobs:
with:
fetch-depth: 25
- run: echo ::set-output name=DOCS_CHANGE::$(node skip-docs-change.js echo 'not-docs-only-change')
- name: Check non-docs only change
run: echo ::set-output name=DOCS_CHANGE::$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')
id: docs-change
- name: Setup node
uses: actions/setup-node@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
node-version: 16
check-latest: true
- name: Install
uses: actions-rs/toolchain@v1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
profile: minimal
toolchain: nightly-2021-11-15
- name: Cache cargo registry
uses: actions/cache@v1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: ~/.cargo/registry
key: stable-ubuntu-18.04-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: ~/.cargo/git
key: stable-ubuntu-18.04-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
......@@ -61,7 +62,7 @@ jobs:
- name: Turbo Cache
id: turbo-cache
uses: actions/cache@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
path: .turbo
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ steps.get-week.outputs.WEEK }}-${{ github.sha }}
......@@ -87,7 +88,7 @@ jobs:
- run: npm i -g turbo@${TURBO_VERSION} pnpm@${PNPM_VERSION}
- name: Build
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
run: turbo run build-native --cache-dir=".turbo"
env:
MACOSX_DEPLOYMENT_TARGET: '10.13'
......@@ -102,7 +103,7 @@ jobs:
path: packages/next-swc/native/next-swc.linux-x64-gnu.node
- name: Clear the cargo caches
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
run: |
cargo install cargo-cache --no-default-features --features ci-autoclean
cargo-cache
......@@ -116,17 +117,18 @@ jobs:
with:
fetch-depth: 25
- run: echo ::set-output name=DOCS_CHANGE::$(node skip-docs-change.js echo 'not-docs-only-change')
- name: Check non-docs only change
run: echo ::set-output name=DOCS_CHANGE::$(node scripts/run-for-change.js --not --type docs --exec echo 'nope')
id: docs-change
- uses: actions/download-artifact@v3
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
with:
name: next-swc-dev-binary
path: packages/next-swc/native
- run: cp -r packages/next-swc/native .github/actions/next-stats-action/native
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
- uses: ./.github/actions/next-stats-action
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs only change' }}
if: ${{ steps.docs-change.outputs.DOCS_CHANGE == 'nope' }}
......@@ -49,19 +49,26 @@ stages:
versionSpec: $(node_version)
displayName: 'Install Node.js'
- bash: |
node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
displayName: 'Check Docs Only Change'
- script: npm i -g pnpm@$(PNPM_VERSION)
condition: eq(variables['isDocsOnly'], 'No')
- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
- script: pnpm store path
- script: |
pnpm install && pnpm run build
- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Install and build'
- script: |
npx playwright install chromium
- script: npx playwright install chromium
condition: eq(variables['isDocsOnly'], 'No')
- script: |
node run-tests.js -c 1 test/integration/production/test/index.test.js test/integration/css-client-nav/test/index.test.js test/integration/rewrites-has-condition/test/index.test.js
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests'
- job: test_unit
......@@ -77,14 +84,20 @@ stages:
versionSpec: $(node_version)
displayName: 'Install Node.js'
- bash: |
node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
displayName: 'Check Docs Only Change'
- script: npm i -g pnpm@$(PNPM_VERSION)
condition: eq(variables['isDocsOnly'], 'No')
- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
- script: pnpm store path
- script: |
pnpm install && pnpm run build
- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Install and build'
- script: |
node run-tests.js --type unit
- script: node run-tests.js --type unit
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests'
const { promisify } = require('util')
const { exec: execOrig, spawn } = require('child_process')
const exec = promisify(execOrig)
const CHANGE_ITEM_GROUPS = {
docs: [
'bench',
'docs',
'errors',
'examples',
'UPGRADING.md',
'contributing.md',
'CODE_OF_CONDUCT.md',
'readme.md',
],
'next-swc': ['packages/next-swc', '.github/workflows/build_test_deploy.yml'],
}
async function main() {
let eventData = {}
try {
eventData = require(process.env.GITHUB_EVENT_PATH)['pull_request'] || {}
} catch (_) {}
const branchName =
eventData?.head?.ref ||
process.env.GITHUB_REF_NAME ||
(await exec('git rev-parse --abbrev-ref HEAD')).stdout
const remoteUrl =
eventData?.head?.repo?.full_name ||
process.env.GITHUB_REPOSITORY ||
(await exec('git remote get-url origin').stdout)
let changedFilesOutput = ''
const isCanary =
branchName.trim() === 'canary' && remoteUrl.includes('vercel/next.js')
try {
await exec('git fetch origin canary')
} catch (err) {
console.error(`Failed to fetch origin/canary`, err)
}
// if we are on the canary branch only diff current commit
const toDiff = isCanary
? `${process.env.GITHUB_SHA || 'canary'}~`
: 'origin/canary...'
const changesResult = await exec(`git diff ${toDiff} --name-only`).catch(
(err) => {
console.error(err)
return { stdout: '' }
}
)
console.error({ branchName, remoteUrl, isCanary, changesResult })
changedFilesOutput = changesResult.stdout
const typeIndex = process.argv.indexOf('--type')
const type = typeIndex > -1 && process.argv[typeIndex + 1]
const isNegated = process.argv.indexOf('--not') > -1
if (!type) {
throw new Error(
`Missing "--type" flag, e.g. "node run-for-change.js --type docs"`
)
}
const execArgIndex = process.argv.indexOf('--exec')
if (execArgIndex < 0) {
throw new Error('no "--exec" flag provided')
}
let hasMatchingChange = false
const changeItems = CHANGE_ITEM_GROUPS[type]
const execArgs = process.argv.slice(execArgIndex + 1)
if (execArgs.length < 1) {
throw new Error('Missing exec arguments after "--exec"')
}
if (!changeItems) {
throw new Error(
`Invalid change type, allowed types are ${Object.keys(
CHANGE_ITEM_GROUPS
).join(', ')}`
)
}
let changedFilesCount = 0
for (let file of changedFilesOutput.split('\n')) {
file = file.trim().replace(/\\/g, '/')
if (file) {
changedFilesCount += 1
// if --not flag is provided we execute for any file changed
// not included in the change items otherwise we only execute
// if a change item is changed
const matchesItem = changeItems.some((item) => file.startsWith(item))
if (!matchesItem && isNegated) {
hasMatchingChange = true
break
}
if (matchesItem && !isNegated) {
hasMatchingChange = true
break
}
}
}
// if we fail to detect the changes run the command
if (changedFilesCount < 1) {
console.error(`No changed files detected:\n${changedFilesOutput}`)
hasMatchingChange = true
}
if (hasMatchingChange) {
const cmd = spawn(execArgs[0], execArgs.slice(1))
cmd.stdout.pipe(process.stdout)
cmd.stderr.pipe(process.stderr)
await new Promise((resolve, reject) => {
cmd.on('exit', (code) => {
if (code !== 0) {
return reject(new Error('command failed with code: ' + code))
}
resolve()
})
cmd.on('error', (err) => reject(err))
})
} else {
console.log(
`No matching changed files for ${isNegated ? 'not ' : ''}"${type}":\n` +
changedFilesOutput.trim()
)
}
}
main().catch((err) => {
console.error('Failed to detect changes', err)
process.exit(1)
})
const { promisify } = require('util')
const { exec: execOrig, spawn } = require('child_process')
const exec = promisify(execOrig)
const DOCS_FOLDERS = [
'bench',
'docs',
'errors',
'examples',
'UPGRADING.md',
'contributing.md',
'CODE_OF_CONDUCT.md',
'readme.md',
]
async function main() {
await exec('git fetch origin canary')
const { stdout: changedFilesOutput } = await exec(
'git diff origin/canary... --name-only'
)
const changedFiles = changedFilesOutput
.split('\n')
.map((file) => file && file.trim())
.filter(Boolean)
let hasNonDocsChange =
!changedFiles.length ||
changedFiles.some((file) => {
return !DOCS_FOLDERS.some((folder) => file.startsWith(folder + '/'))
})
const args = process.argv.slice(process.argv.indexOf(__filename) + 1)
if (args.length === 0) {
console.log(process.argv, args)
console.log('no script provided, exiting...')
}
if (hasNonDocsChange) {
const cmd = spawn(args[0], args.slice(1))
cmd.stdout.pipe(process.stdout)
cmd.stderr.pipe(process.stderr)
await new Promise((resolve, reject) => {
cmd.on('exit', (code) => {
if (code !== 0) {
return reject(new Error('command failed with code: ' + code))
}
resolve()
})
cmd.on('error', (err) => reject(err))
})
} else {
console.log('docs only change')
}
}
main().catch((err) => {
console.error('Failed to detect doc changes', err)
process.exit(1)
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment