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

Dependabot/test version update #2393

Closed
wants to merge 8 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@aws-amplify/form-generator': patch
---

Updates `prettier` from 2.8.8 to 3.4.2
Updates `@types/prettier` from 2.7.3 to 3.0.0
7 changes: 4 additions & 3 deletions .github/workflows/health_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,15 @@ jobs:
mkdir api-validation-projects
npx tsx scripts/check_api_changes.ts base-branch-content api-validation-projects
handle_dependabot_version_update:
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs:
- install
- 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
75 changes: 45 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@shopify/eslint-plugin": "^43.0.0",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.15.11",
"@types/prettier": "^2.7.3",
"@types/prettier": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"c8": "^7.13.0",
Expand All @@ -91,7 +91,7 @@
"glob": "^10.1.0",
"husky": "^8.0.3",
"lint-staged": "^15.2.10",
"prettier": "^2.8.7",
"prettier": "^3.4.2",
"rimraf": "^5.0.0",
"semver": "^7.5.4",
"tsx": "^4.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/form-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"@graphql-codegen/typescript": "^2.8.3",
"graphql": "^15.8.0",
"node-fetch": "^3.3.2",
"prettier": "^2.8.7"
"prettier": "^3.4.2"
}
}
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`
);

await assertChangesetFile(
Expand Down
9 changes: 7 additions & 2 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 @@ -37,18 +36,24 @@ export class DependabotVersionUpdateHandler {
handleVersionUpdate = async () => {
if (!this._ghContext.payload.pull_request) {
// event is not a pull request, return early
console.log('Event is not a pull request');
return;
}

await this.gitClient.switchToBranch(
this._ghContext.payload.pull_request.head.ref
);
const branch = await this.gitClient.getCurrentBranch();
if (!branch.startsWith('dependabot/')) {
// if branch is not a dependabot branch, return early
console.log(`${branch} is not a dependabot branch`);
return;
}

const changedFiles = await this.gitClient.getChangedFiles(this.baseRef);
if (changedFiles.find((file) => file.startsWith('.changeset'))) {
// if changeset file already exists, return early
console.log('Changeset file already exists');
return;
}

Expand Down Expand Up @@ -78,7 +83,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