diff --git a/.github/workflows/tests-pr.yml b/.github/workflows/tests-pr.yml index c66b856c774..f613dd717cf 100644 --- a/.github/workflows/tests-pr.yml +++ b/.github/workflows/tests-pr.yml @@ -119,8 +119,33 @@ jobs: run: pnpm graphql-codegen - name: Run git diff run: git diff - - name: Fail if any changes were made - run: 'test -z "$(git status --porcelain)" || { echo -e "Run pnpm graphql-codegen when queries are changed, committing any fixes and generated files" ; exit 1; }' + # The schemas come from the servers' latest code, so the generated files can differ on a pull request + # that doesn't touch GraphQL. bin/graphql-codegen/check-drift.js fails only on differences the pull + # request or merge group could have caused, and warns about the rest. A mirror pull request brings + # changes that the upstream repository's CI has already checked, so a difference there comes from a + # schema change made since, and the upstream repository regenerates the files. + - name: Fail if the change left the generated files out of date + env: + MIRROR_PULL_REQUEST: ${{ github.event.pull_request.head.ref == 'world-mirror/main' && github.event.pull_request.head.repo.full_name == github.repository }} + PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} + MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }} + run: | + if [ -z "$(git status --porcelain)" ]; then + echo "The generated GraphQL files are up to date." + elif [ "$MIRROR_PULL_REQUEST" = true ]; then + echo "::warning title=Generated GraphQL files are out of date::The upstream repository's CI has already checked this mirror pull request, so a schema change made since caused the difference." + git status --porcelain + else + changed_files="$RUNNER_TEMP/changed-files.txt" + if [ -n "$MERGE_GROUP_BASE_SHA" ]; then + git fetch --no-tags --depth=1 origin "$MERGE_GROUP_BASE_SHA" + git diff --name-only "$MERGE_GROUP_BASE_SHA" HEAD > "$changed_files" + else + gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PULL_REQUEST_NUMBER/files" \ + --jq '.[] | .filename, (.previous_filename // empty)' > "$changed_files" + fi + node bin/graphql-codegen/check-drift.js --changed-files "$changed_files" + fi oclif-checks: name: 'Check OCLIF manifests & readme & docs'