Skip to content

Commit f3626c6

Browse files
authored
fix dependabot version update workflow (#2394)
* fix dependabot version update workflow * ignore spellcheck for sha
1 parent 23f1240 commit f3626c6

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

.github/workflows/health_checks.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ jobs:
277277
- resolve_inputs
278278
steps:
279279
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
280+
with:
281+
fetch-depth: 0
280282
- uses: ./.github/actions/setup_node
281283
with:
282284
node-version: 18
@@ -285,10 +287,9 @@ jobs:
285287
node-version: 18
286288
cdk-version: ${{ needs.resolve_inputs.outputs.cdk_version }}
287289
- name: Handle Dependabot version update pull request
288-
run: npx tsx scripts/dependabot_handle_version_update.ts "$BASE_SHA" "$HEAD_SHA"
290+
run: npx tsx scripts/dependabot_handle_version_update.ts "$BASE_SHA"
289291
env:
290292
BASE_SHA: ${{ github.event.pull_request.base.sha }}
291-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
292293
# The dependabot_handler_version_update script needs to add the 'run-e2e' pull request label
293294
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
294295
do_include_e2e:

scripts/components/dependabot_version_update_handler.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ void describe('dependabot version update handler', async () => {
117117
pull_request: {
118118
number: 1,
119119
body: pullRequestBody,
120+
head: {
121+
ref: 'dependabot/test_version_update_branch',
122+
// eslint-disable-next-line spellcheck/spell-checker
123+
sha: 'abcd1234', // used for naming the changeset file
124+
},
120125
},
121126
},
122127
issue: {
@@ -131,15 +136,13 @@ void describe('dependabot version update handler', async () => {
131136
};
132137

133138
// Update package.json files for both packages and commit to match what Dependabot will do for a version update PR
134-
await gitClient.switchToBranch('dependabot/test_update');
139+
await gitClient.switchToBranch('dependabot/test_version_update_branch');
135140
await setPackageDependencies(cantaloupePackagePath, { testDep: '^1.1.0' });
136141
await setPackageDependencies(platypusPackagePath, { testDep: '^1.1.0' });
137142
await gitClient.commitAllChanges('Bump dependencies');
138-
const headRef = await gitClient.getHashForCurrentCommit();
139143

140144
const dependabotVersionUpdateHandler = new DependabotVersionUpdateHandler(
141145
baseRef,
142-
headRef,
143146
gitClient,
144147
githubClient,
145148
testWorkingDir,
@@ -150,7 +153,8 @@ void describe('dependabot version update handler', async () => {
150153

151154
const changesetFilePath = path.join(
152155
testWorkingDir,
153-
`.changeset/dependabot-${headRef}.md`
156+
// eslint-disable-next-line spellcheck/spell-checker
157+
'.changeset/dependabot-abcd1234.md'
154158
);
155159

156160
await assertChangesetFile(

scripts/components/dependabot_version_update_handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class DependabotVersionUpdateHandler {
1616
*/
1717
constructor(
1818
private readonly baseRef: string,
19-
private readonly headRef: string,
2019
private readonly gitClient: GitClient,
2120
private readonly ghClient: GithubClient,
2221
private readonly _rootDir: string = process.cwd(),
@@ -40,7 +39,8 @@ export class DependabotVersionUpdateHandler {
4039
return;
4140
}
4241

43-
const branch = await this.gitClient.getCurrentBranch();
42+
const branch = this._ghContext.payload.pull_request.head.ref;
43+
await this.gitClient.switchToBranch(branch);
4444
if (!branch.startsWith('dependabot/')) {
4545
// if branch is not a dependabot branch, return early
4646
return;
@@ -78,7 +78,7 @@ export class DependabotVersionUpdateHandler {
7878
// Create and commit the changeset file, then add the 'run-e2e' label and force push to the PR
7979
const fileName = path.join(
8080
this._rootDir,
81-
`.changeset/dependabot-${this.headRef}.md`
81+
`.changeset/dependabot-${this._ghContext.payload.pull_request.head.sha}.md`
8282
);
8383
const versionUpdates = await this.getVersionUpdates();
8484
await this.createChangesetFile(fileName, versionUpdates, packageNames);

scripts/dependabot_handle_version_update.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ import { DependabotVersionUpdateHandler } from './components/dependabot_version_
44

55
const baseRef = process.argv[2];
66
if (baseRef === undefined) {
7-
throw new Error('No base ref specified for generate changeset check');
8-
}
9-
10-
const headRef = process.argv[3];
11-
if (headRef === undefined) {
12-
throw new Error('No head ref specified for generate changeset check');
7+
throw new Error(
8+
'No base ref specified for handle dependabot version update check'
9+
);
1310
}
1411

1512
const dependabotVersionUpdateHandler = new DependabotVersionUpdateHandler(
1613
baseRef,
17-
headRef,
1814
new GitClient(),
1915
new GithubClient()
2016
);

0 commit comments

Comments
 (0)