Skip to content

Commit

Permalink
fix dependabot version update workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rtpascual committed Jan 2, 2025
1 parent 38b5da3 commit 173bda2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/health_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions scripts/components/dependabot_version_update_handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
Expand All @@ -150,7 +152,7 @@ void describe('dependabot version update handler', async () => {

const changesetFilePath = path.join(
testWorkingDir,
`.changeset/dependabot-${headRef}.md`
'.changeset/dependabot-abcd1234.md'

Check warning on line 155 in scripts/components/dependabot_version_update_handler.test.ts

View workflow job for this annotation

GitHub Actions / lint

You have a misspelled word: abcd1234 on String
);

await assertChangesetFile(
Expand Down
6 changes: 3 additions & 3 deletions scripts/components/dependabot_version_update_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions scripts/dependabot_handle_version_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down

0 comments on commit 173bda2

Please sign in to comment.