diff --git a/.github/workflows/health_checks.yml b/.github/workflows/health_checks.yml index bf2d63289b..c461f282b7 100644 --- a/.github/workflows/health_checks.yml +++ b/.github/workflows/health_checks.yml @@ -277,6 +277,8 @@ jobs: - resolve_inputs steps: - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4 + with: + fetch-depth: 0 - uses: ./.github/actions/setup_node with: node-version: 18 @@ -285,10 +287,9 @@ jobs: node-version: 18 cdk-version: ${{ needs.resolve_inputs.outputs.cdk_version }} - name: Handle Dependabot version update pull request - run: npx tsx scripts/dependabot_handle_version_update.ts "$BASE_SHA" "$HEAD_SHA" + run: npx tsx scripts/dependabot_handle_version_update.ts "$BASE_SHA" env: BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} # The dependabot_handler_version_update script needs to add the 'run-e2e' pull request label GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} do_include_e2e: diff --git a/scripts/components/dependabot_version_update_handler.test.ts b/scripts/components/dependabot_version_update_handler.test.ts index 8d9b612f1e..bfd6e8410c 100644 --- a/scripts/components/dependabot_version_update_handler.test.ts +++ b/scripts/components/dependabot_version_update_handler.test.ts @@ -117,6 +117,10 @@ void describe('dependabot version update handler', async () => { pull_request: { number: 1, body: pullRequestBody, + head: { + ref: 'dependabot/test_version_update_branch', + sha: 'abcd1234', // used for naming the changeset file + }, }, }, issue: { @@ -131,15 +135,13 @@ void describe('dependabot version update handler', async () => { }; // Update package.json files for both packages and commit to match what Dependabot will do for a version update PR - await gitClient.switchToBranch('dependabot/test_update'); + await gitClient.switchToBranch('dependabot/test_version_update_branch'); await setPackageDependencies(cantaloupePackagePath, { testDep: '^1.1.0' }); await setPackageDependencies(platypusPackagePath, { testDep: '^1.1.0' }); await gitClient.commitAllChanges('Bump dependencies'); - const headRef = await gitClient.getHashForCurrentCommit(); const dependabotVersionUpdateHandler = new DependabotVersionUpdateHandler( baseRef, - headRef, gitClient, githubClient, testWorkingDir, @@ -150,7 +152,7 @@ void describe('dependabot version update handler', async () => { const changesetFilePath = path.join( testWorkingDir, - `.changeset/dependabot-${headRef}.md` + '.changeset/dependabot-abcd1234.md' ); await assertChangesetFile( diff --git a/scripts/components/dependabot_version_update_handler.ts b/scripts/components/dependabot_version_update_handler.ts index 6e8739c805..08dd347724 100644 --- a/scripts/components/dependabot_version_update_handler.ts +++ b/scripts/components/dependabot_version_update_handler.ts @@ -16,7 +16,6 @@ export class DependabotVersionUpdateHandler { */ constructor( private readonly baseRef: string, - private readonly headRef: string, private readonly gitClient: GitClient, private readonly ghClient: GithubClient, private readonly _rootDir: string = process.cwd(), @@ -40,7 +39,8 @@ export class DependabotVersionUpdateHandler { return; } - const branch = await this.gitClient.getCurrentBranch(); + const branch = this._ghContext.payload.pull_request.head.ref; + await this.gitClient.switchToBranch(branch); if (!branch.startsWith('dependabot/')) { // if branch is not a dependabot branch, return early return; @@ -78,7 +78,7 @@ export class DependabotVersionUpdateHandler { // Create and commit the changeset file, then add the 'run-e2e' label and force push to the PR const fileName = path.join( this._rootDir, - `.changeset/dependabot-${this.headRef}.md` + `.changeset/dependabot-${this._ghContext.payload.pull_request.head.sha}.md` ); const versionUpdates = await this.getVersionUpdates(); await this.createChangesetFile(fileName, versionUpdates, packageNames); diff --git a/scripts/dependabot_handle_version_update.ts b/scripts/dependabot_handle_version_update.ts index da9c92de1b..c24012d51a 100644 --- a/scripts/dependabot_handle_version_update.ts +++ b/scripts/dependabot_handle_version_update.ts @@ -4,17 +4,13 @@ import { DependabotVersionUpdateHandler } from './components/dependabot_version_ const baseRef = process.argv[2]; if (baseRef === undefined) { - throw new Error('No base ref specified for generate changeset check'); -} - -const headRef = process.argv[3]; -if (headRef === undefined) { - throw new Error('No head ref specified for generate changeset check'); + throw new Error( + 'No base ref specified for handle dependabot version update check' + ); } const dependabotVersionUpdateHandler = new DependabotVersionUpdateHandler( baseRef, - headRef, new GitClient(), new GithubClient() );