diff --git a/.github/workflows/update_bindings_and_push_to_vulkan.yml b/.github/workflows/update_bindings_and_push_to_vulkan.yml index 9fc522b..eeb3009 100644 --- a/.github/workflows/update_bindings_and_push_to_vulkan.yml +++ b/.github/workflows/update_bindings_and_push_to_vulkan.yml @@ -207,6 +207,12 @@ jobs: RELEASE_VERSION: ${{ needs.versions.outputs.requested }} run: | set -euo pipefail + # A forced regeneration may also produce exactly the default branch. + # In that case there is no branch/PR to create or recover. + if [[ "$(git write-tree)" == "$(git rev-parse 'origin/master^{tree}')" ]]; then + echo 'Generated files already match master; no proposal needed.' + exit 0 + fi existing=$(gh pr list \ --repo "$DEPLOY_TARGET_REPO" \ --base master \ diff --git a/scripts/test_publish_generated_branch.py b/scripts/test_publish_generated_branch.py index 8ef2952..29a6f00 100644 --- a/scripts/test_publish_generated_branch.py +++ b/scripts/test_publish_generated_branch.py @@ -123,7 +123,7 @@ def race(repo, *args): class PullRequestRecoveryTests(unittest.TestCase): - def run_step(self, existing): + def run_step(self, existing, unchanged=False): workflow = (SCRIPT.parents[1] / '.github/workflows/' 'update_bindings_and_push_to_vulkan.yml').read_text() step = workflow.split(' - name: Open pull request if missing\n', 1)[1] @@ -139,14 +139,19 @@ def run_step(self, existing): 'if sys.argv[1:3] == ["pr", "list"]:\n' ' print(os.environ["GH_TEST_EXISTING"])\n') gh.chmod(0o755) + fake_git = root / 'git' + fake_git.write_text('#!/usr/bin/env python3\nimport os, sys\n' + 'print(os.environ["GH_TEST_TREE"] if sys.argv[1] == "write-tree" else "base")\n') + fake_git.chmod(0o755) log = root / 'calls' result = subprocess.run(['bash', '-c', shell], check=True, capture_output=True, text=True, env={**os.environ, 'PATH': str(root) + os.pathsep + os.environ['PATH'], 'GH_TEST_LOG': str(log), 'GH_TEST_EXISTING': existing, + 'GH_TEST_TREE': 'base' if unchanged else 'candidate', 'BRANCH_NAME': BRANCH, 'DEPLOY_TARGET_REPO': 'fixture/module', 'RELEASE_VERSION': 'v1.4.366'}) - return log.read_text().splitlines(), result.stdout + return log.read_text().splitlines() if log.exists() else [], result.stdout def test_existing_pr_is_read_only(self): calls, output = self.run_step('80') @@ -157,6 +162,10 @@ def test_missing_pr_is_created_after_a_noop_push(self): calls, _ = self.run_step('') self.assertEqual(calls, ['pr list', 'pr create']) + def test_forced_regeneration_matching_master_does_not_create_a_pr(self): + calls, _ = self.run_step('', unchanged=True) + self.assertEqual(calls, []) + if __name__ == '__main__': unittest.main()