From 366da0a409ef8cc5ae524c752e116cc27dfe8c7e Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 16 Jan 2024 19:10:56 +0100 Subject: [PATCH] meta: add `output-watcher` GHA to help check output diff --- .github/workflows/output-watcher.yml | 135 +++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 .github/workflows/output-watcher.yml diff --git a/.github/workflows/output-watcher.yml b/.github/workflows/output-watcher.yml new file mode 100644 index 00000000000..298a359678e --- /dev/null +++ b/.github/workflows/output-watcher.yml @@ -0,0 +1,135 @@ +name: Compare JS output + +on: + push: + branches: [main] + pull_request: + # We want all branches so we configure types to be the GH default again + types: [opened, synchronize, reopened] + paths: + - 'packages/@uppy/*/src/**/*' + - 'bin/*' + - '.github/workflows/output-watcher.yml' + +env: + YARN_ENABLE_GLOBAL_CACHE: false + +jobs: + build_new_version: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: + echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node-version}} + - name: Install dependencies + run: + corepack yarn workspaces focus $(corepack yarn workspaces list --json + | jq -r .name | awk '/^@uppy-example/{ next } { if ($0!="uppy.io") + print $0 }') + env: + # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation + CYPRESS_INSTALL_BINARY: 0 + - run: corepack yarn build:lib + - name: Store output file + run: + find packages/@uppy -path '*/lib' -type d -exec tar cf + /tmp/newVersion.tar -C {} . \; + - name: Upload artifact + if: success() + uses: actions/upload-artifact@v3 + with: + name: newVersion.tar + path: /tmp/newVersion.tar + + build_previous_version: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v3 + with: + fetch-depth: 2 + - run: git reset HEAD^ --hard + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: + echo "dir=$(corepack yarn config get cacheFolder)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{matrix.node-version}} + - name: Install dependencies + run: + corepack yarn workspaces focus $(corepack yarn workspaces list --json + | jq -r .name | awk '/^@uppy-example/{ next } { if ($0!="uppy.io") + print $0 }') + env: + # https://docs.cypress.io/guides/references/advanced-installation#Skipping-installation + CYPRESS_INSTALL_BINARY: 0 + - run: corepack yarn build:lib + - name: Store output file + run: + find packages/@uppy -path '*/lib' -type d -exec tar cf + /tmp/previousVersion.tar -C {} . \; + - name: Upload artifact + if: success() + uses: actions/upload-artifact@v3 + with: + name: previousVersion.tar + path: /tmp/previousVersion.tar + + compare: + needs: [build_new_version, build_previous_version] + name: Compare output files for both versions + runs-on: ubuntu-latest + steps: + - name: Download tarballs + uses: actions/download-artifact@v3 + with: + path: /tmp/ + - name: Setup git + run: | + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + git init /tmp/uppy + - name: Extract previous version + run: cd /tmp/uppy && tar xf /tmp/previousVersion.tar/previousVersion.tar + - name: Commit previous version + run: cd /tmp/uppy && git add -A . && git commit -m 'previous version' + - name: Extract new version + run: cd /tmp/uppy && tar xf /tmp/newVersion.tar/newVersion.tar + - name: Commit new version + run: + cd /tmp/uppy && git add -A . && git commit -m 'new version' + --allow-empty + - name: Show diff + run: cd /tmp/uppy && git --no-pager diff HEAD^..HEAD + - run: cd /tmp/uppy && git format-patch HEAD^ -o /tmp/patch + - name: Upload artifact + if: success() + uses: actions/upload-artifact@v3 + with: + name: diff + path: /tmp/patch