Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix dependabot version update workflow #2394

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 8 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,11 @@ void describe('dependabot version update handler', async () => {
pull_request: {
number: 1,
body: pullRequestBody,
head: {
ref: 'dependabot/test_version_update_branch',
// eslint-disable-next-line spellcheck/spell-checker
sha: 'abcd1234', // used for naming the changeset file
},
},
},
issue: {
Expand All @@ -131,15 +136,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 +153,8 @@ void describe('dependabot version update handler', async () => {

const changesetFilePath = path.join(
testWorkingDir,
`.changeset/dependabot-${headRef}.md`
// eslint-disable-next-line spellcheck/spell-checker
'.changeset/dependabot-abcd1234.md'
);

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
Loading