From 00929b2b5e2bc054b6f2e7ee52bacf16f1ef5dda Mon Sep 17 00:00:00 2001 From: Nara Kasbergen Kwon <855115+xiehan@users.noreply.github.com> Date: Thu, 7 Dec 2023 13:11:06 +0100 Subject: [PATCH] chore: replace mergify with automerge workflow (#363) Signed-off-by: team-tf-cdk Co-authored-by: team-tf-cdk Co-authored-by: Daniel Schmidt --- .github/workflows/automerge.yml | 2 +- .projenrc.ts | 2 +- {projenrc => src}/automerge.ts | 2 +- src/index.ts | 49 +---- test/__snapshots__/index.test.ts.snap | 291 ++++++++++---------------- 5 files changed, 114 insertions(+), 232 deletions(-) rename {projenrc => src}/automerge.ts (92%) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 5593a78a..1e3b12f1 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - if: contains(github.event.pull_request.labels.*.name, 'automerge') && github.event.pull_request.draft == false + if: contains(github.event.pull_request.labels.*.name, 'automerge') && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') && github.event.pull_request.draft == false steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 diff --git a/.projenrc.ts b/.projenrc.ts index 3ba8bbf4..ac38dc88 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -5,9 +5,9 @@ import { cdk } from "projen"; import { UpgradeDependenciesSchedule } from "projen/lib/javascript"; -import { Automerge } from "./projenrc/automerge"; import { UpgradeNode } from "./projenrc/upgrade-node"; import { AutoApprove } from "./src/auto-approve"; +import { Automerge } from "./src/automerge"; import { CustomizedLicense } from "./src/customized-license"; import { LockIssues } from "./src/lock-issues"; diff --git a/projenrc/automerge.ts b/src/automerge.ts similarity index 92% rename from projenrc/automerge.ts rename to src/automerge.ts index aec07cca..da2dfbe9 100644 --- a/projenrc/automerge.ts +++ b/src/automerge.ts @@ -33,7 +33,7 @@ export class Automerge { workflow.addJobs({ automerge: { runsOn: ["ubuntu-latest"], - if: "contains(github.event.pull_request.labels.*.name, 'automerge') && github.event.pull_request.draft == false", + if: "contains(github.event.pull_request.labels.*.name, 'automerge') && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') && github.event.pull_request.draft == false", steps: [ { name: "Checkout", diff --git a/src/index.ts b/src/index.ts index 864f8617..72feddef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { UpgradeDependenciesSchedule } from "projen/lib/javascript"; import { AlertOpenPrs } from "./alert-open-prs"; import { AutoApprove } from "./auto-approve"; import { AutoCloseCommunityIssues } from "./auto-close-community-issues"; +import { Automerge } from "./automerge"; import { CdktfConfig } from "./cdktf-config"; import { CopyrightHeaders } from "./copyright-headers"; import { CustomizedLicense } from "./customized-license"; @@ -235,42 +236,6 @@ export class CdktfProviderProject extends cdk.JsiiProject { email: "github-team-tf-cdk@hashicorp.com", }, minMajorVersion: MIN_MAJOR_VERSION, - githubOptions: { - mergify: true, - mergifyOptions: { - rules: [ - { - name: "Automatically approve PRs with automerge label", - actions: { - review: { - type: "APPROVE", - message: "Automatically approved due to label", - }, - }, - conditions: [ - "label=automerge", - "-label~=(do-not-merge)", - "-draft", - "author=team-tf-cdk", - ], - }, - { - name: "Automatically close stale PRs", - actions: { - close: { - message: - "Closing this automatic PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging", - }, - }, - conditions: [ - "author=team-tf-cdk", - "-draft", - "created-at<1 day ago", - ], - }, - ], - }, - }, stale: true, staleOptions: { issues: { @@ -285,13 +250,10 @@ export class CdktfProviderProject extends cdk.JsiiProject { }, pullRequest: { staleLabel: "stale", - daysBeforeStale: 14, - staleMessage: - "14 days have passed since this PR was opened, and I assume other builds have succeeded in the meantime. " + - "If no one removes the `stale` label or comments, I'm going to auto-close this PR in 7 days.", - daysBeforeClose: 7, - closeMessage: - "I'm closing this PR automatically with the assumption that other builds have succeeded in the meantime.", + daysBeforeStale: 1, + staleMessage: `Closing this PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging. If this has been a manual PR, please reopen it and add the \`no-auto-close\` label to prevent this from happening again.`, + daysBeforeClose: 0, + exemptLabels: ["no-auto-close"], }, }, docgen: false, @@ -365,6 +327,7 @@ export class CdktfProviderProject extends cdk.JsiiProject { new GithubIssues(this, { providerName }); new AutoApprove(this); new AutoCloseCommunityIssues(this, { providerName }); + new Automerge(this); new LockIssues(this); new NextVersionPr(this, "${{ secrets.GITHUB_TOKEN }}"); new AlertOpenPrs(this, { diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index 81a92678..3509dc88 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -38,6 +38,7 @@ project { /.github/workflows/auto-approve.yml linguist-generated /.github/workflows/auto-close-community-issues.yml linguist-generated /.github/workflows/auto-close-community-prs.yml linguist-generated +/.github/workflows/automerge.yml linguist-generated /.github/workflows/build.yml linguist-generated /.github/workflows/force-release.yml linguist-generated /.github/workflows/lock.yml linguist-generated @@ -48,7 +49,6 @@ project { /.github/workflows/stale.yml linguist-generated /.github/workflows/upgrade-main.yml linguist-generated /.gitignore linguist-generated -/.mergify.yml linguist-generated /.npmignore linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated @@ -192,6 +192,33 @@ jobs: env: GH_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: gh pr edit \${{ github.event.pull_request.number }} --add-label "invalid,wontfix" +", + ".github/workflows/automerge.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". + +name: automerge +on: + pull_request_target: + types: + - opened + - labeled + - ready_for_review + - reopened + - synchronize +concurrency: \${{ github.workflow }}-\${{ github.ref }} +jobs: + automerge: + runs-on: ubuntu-latest + permissions: + contents: read + if: contains(github.event.pull_request.labels.*.name, 'automerge') && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') && github.event.pull_request.draft == false + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Turn on automerge for this PR by a trusted user or bot + if: github.event.pull_request.user.login == 'team-tf-cdk' || contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) || github.actor == 'dependabot[bot]' + env: + GH_TOKEN: \${{ secrets.PROJEN_GITHUB_TOKEN }} + run: gh pr merge --auto --squash \${{ github.event.pull_request.number }} ", ".github/workflows/build.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". @@ -1055,12 +1082,12 @@ jobs: with: days-before-stale: -1 days-before-close: -1 - days-before-pr-stale: 14 - days-before-pr-close: 7 - stale-pr-message: 14 days have passed since this PR was opened, and I assume other builds have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this PR in 7 days. - close-pr-message: I'm closing this PR automatically with the assumption that other builds have succeeded in the meantime. + days-before-pr-stale: 1 + days-before-pr-close: 0 + stale-pr-message: Closing this PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging. If this has been a manual PR, please reopen it and add the \`no-auto-close\` label to prevent this from happening again. + close-pr-message: Closing this pull request as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "no-auto-close" label. stale-pr-label: stale - exempt-pr-labels: backlog + exempt-pr-labels: no-auto-close days-before-issue-stale: 45 days-before-issue-close: 14 stale-issue-message: 45 days have passed since this issue was opened, and I assume other publishes have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this issue in 14 days. @@ -1165,7 +1192,6 @@ jobs: !/.projen/tasks.json !/.projen/deps.json !/.projen/files.json -!/.mergify.yml !/.github/workflows/pull-request-lint.yml !/.github/workflows/stale.yml !/package.json @@ -1219,6 +1245,7 @@ package-lock.json !/.github/workflows/auto-approve.yml !/.github/workflows/auto-close-community-issues.yml !/.github/workflows/auto-close-community-prs.yml +!/.github/workflows/automerge.yml !/.github/workflows/lock.yml !/.github/workflows/next-cdktf-version-pr.yml !/.github/workflows/alert-open-prs.yml @@ -1228,66 +1255,12 @@ package-lock.json API.md !/docs/*.md !/.copywrite.hcl -", - ".mergify.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". - -queue_rules: - - name: default - update_method: merge - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go -pull_request_rules: - - name: Automatically approve PRs with automerge label - actions: - review: - type: APPROVE - message: Automatically approved due to label - conditions: - - label=automerge - - -label~=(do-not-merge) - - -draft - - author=team-tf-cdk - - name: Automatically close stale PRs - actions: - close: - message: Closing this automatic PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging - conditions: - - author=team-tf-cdk - - -draft - - created-at<1 day ago - - name: Automatic merge on approval and successful build - actions: - delete_head_branch: {} - queue: - method: squash - name: default - commit_message_template: |- - {{ title }} (#{{ number }}) - - {{ body }} - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go ", ".npmignore": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". /.projen/ permissions-backup.acl /dist/changelog.md /dist/version.txt -/.mergify.yml /test/ /tsconfig.dev.json /src/ @@ -1425,6 +1398,7 @@ scripts ".github/workflows/auto-approve.yml", ".github/workflows/auto-close-community-issues.yml", ".github/workflows/auto-close-community-prs.yml", + ".github/workflows/automerge.yml", ".github/workflows/build.yml", ".github/workflows/force-release.yml", ".github/workflows/lock.yml", @@ -1435,7 +1409,6 @@ scripts ".github/workflows/stale.yml", ".github/workflows/upgrade-main.yml", ".gitignore", - ".mergify.yml", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -2743,6 +2716,7 @@ project { /.github/workflows/auto-approve.yml linguist-generated /.github/workflows/auto-close-community-issues.yml linguist-generated /.github/workflows/auto-close-community-prs.yml linguist-generated +/.github/workflows/automerge.yml linguist-generated /.github/workflows/build.yml linguist-generated /.github/workflows/force-release.yml linguist-generated /.github/workflows/lock.yml linguist-generated @@ -2753,7 +2727,6 @@ project { /.github/workflows/stale.yml linguist-generated /.github/workflows/upgrade-main.yml linguist-generated /.gitignore linguist-generated -/.mergify.yml linguist-generated /.npmignore linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated @@ -2897,6 +2870,33 @@ jobs: env: GH_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: gh pr edit \${{ github.event.pull_request.number }} --add-label "invalid,wontfix" +", + ".github/workflows/automerge.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". + +name: automerge +on: + pull_request_target: + types: + - opened + - labeled + - ready_for_review + - reopened + - synchronize +concurrency: \${{ github.workflow }}-\${{ github.ref }} +jobs: + automerge: + runs-on: ubuntu-latest + permissions: + contents: read + if: contains(github.event.pull_request.labels.*.name, 'automerge') && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') && github.event.pull_request.draft == false + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Turn on automerge for this PR by a trusted user or bot + if: github.event.pull_request.user.login == 'team-tf-cdk' || contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) || github.actor == 'dependabot[bot]' + env: + GH_TOKEN: \${{ secrets.PROJEN_GITHUB_TOKEN }} + run: gh pr merge --auto --squash \${{ github.event.pull_request.number }} ", ".github/workflows/build.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". @@ -3811,12 +3811,12 @@ jobs: with: days-before-stale: -1 days-before-close: -1 - days-before-pr-stale: 14 - days-before-pr-close: 7 - stale-pr-message: 14 days have passed since this PR was opened, and I assume other builds have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this PR in 7 days. - close-pr-message: I'm closing this PR automatically with the assumption that other builds have succeeded in the meantime. + days-before-pr-stale: 1 + days-before-pr-close: 0 + stale-pr-message: Closing this PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging. If this has been a manual PR, please reopen it and add the \`no-auto-close\` label to prevent this from happening again. + close-pr-message: Closing this pull request as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "no-auto-close" label. stale-pr-label: stale - exempt-pr-labels: backlog + exempt-pr-labels: no-auto-close days-before-issue-stale: 45 days-before-issue-close: 14 stale-issue-message: 45 days have passed since this issue was opened, and I assume other publishes have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this issue in 14 days. @@ -3921,7 +3921,6 @@ jobs: !/.projen/tasks.json !/.projen/deps.json !/.projen/files.json -!/.mergify.yml !/.github/workflows/pull-request-lint.yml !/.github/workflows/stale.yml !/package.json @@ -3975,6 +3974,7 @@ package-lock.json !/.github/workflows/auto-approve.yml !/.github/workflows/auto-close-community-issues.yml !/.github/workflows/auto-close-community-prs.yml +!/.github/workflows/automerge.yml !/.github/workflows/lock.yml !/.github/workflows/next-cdktf-version-pr.yml !/.github/workflows/alert-open-prs.yml @@ -3984,66 +3984,12 @@ package-lock.json API.md !/docs/*.md !/.copywrite.hcl -", - ".mergify.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". - -queue_rules: - - name: default - update_method: merge - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go -pull_request_rules: - - name: Automatically approve PRs with automerge label - actions: - review: - type: APPROVE - message: Automatically approved due to label - conditions: - - label=automerge - - -label~=(do-not-merge) - - -draft - - author=team-tf-cdk - - name: Automatically close stale PRs - actions: - close: - message: Closing this automatic PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging - conditions: - - author=team-tf-cdk - - -draft - - created-at<1 day ago - - name: Automatic merge on approval and successful build - actions: - delete_head_branch: {} - queue: - method: squash - name: default - commit_message_template: |- - {{ title }} (#{{ number }}) - - {{ body }} - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go ", ".npmignore": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". /.projen/ permissions-backup.acl /dist/changelog.md /dist/version.txt -/.mergify.yml /test/ /tsconfig.dev.json /src/ @@ -4181,6 +4127,7 @@ scripts ".github/workflows/auto-approve.yml", ".github/workflows/auto-close-community-issues.yml", ".github/workflows/auto-close-community-prs.yml", + ".github/workflows/automerge.yml", ".github/workflows/build.yml", ".github/workflows/force-release.yml", ".github/workflows/lock.yml", @@ -4191,7 +4138,6 @@ scripts ".github/workflows/stale.yml", ".github/workflows/upgrade-main.yml", ".gitignore", - ".mergify.yml", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json", @@ -5499,6 +5445,7 @@ project { /.github/workflows/auto-approve.yml linguist-generated /.github/workflows/auto-close-community-issues.yml linguist-generated /.github/workflows/auto-close-community-prs.yml linguist-generated +/.github/workflows/automerge.yml linguist-generated /.github/workflows/build.yml linguist-generated /.github/workflows/force-release.yml linguist-generated /.github/workflows/lock.yml linguist-generated @@ -5509,7 +5456,6 @@ project { /.github/workflows/stale.yml linguist-generated /.github/workflows/upgrade-main.yml linguist-generated /.gitignore linguist-generated -/.mergify.yml linguist-generated /.npmignore linguist-generated /.projen/** linguist-generated /.projen/deps.json linguist-generated @@ -5653,6 +5599,33 @@ jobs: env: GH_TOKEN: \${{ secrets.GITHUB_TOKEN }} run: gh pr edit \${{ github.event.pull_request.number }} --add-label "invalid,wontfix" +", + ".github/workflows/automerge.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". + +name: automerge +on: + pull_request_target: + types: + - opened + - labeled + - ready_for_review + - reopened + - synchronize +concurrency: \${{ github.workflow }}-\${{ github.ref }} +jobs: + automerge: + runs-on: ubuntu-latest + permissions: + contents: read + if: contains(github.event.pull_request.labels.*.name, 'automerge') && !contains(github.event.pull_request.labels.*.name, 'do-not-merge') && github.event.pull_request.draft == false + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Turn on automerge for this PR by a trusted user or bot + if: github.event.pull_request.user.login == 'team-tf-cdk' || contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.pull_request.author_association) || github.actor == 'dependabot[bot]' + env: + GH_TOKEN: \${{ secrets.PROJEN_GITHUB_TOKEN }} + run: gh pr merge --auto --squash \${{ github.event.pull_request.number }} ", ".github/workflows/build.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". @@ -6516,12 +6489,12 @@ jobs: with: days-before-stale: -1 days-before-close: -1 - days-before-pr-stale: 14 - days-before-pr-close: 7 - stale-pr-message: 14 days have passed since this PR was opened, and I assume other builds have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this PR in 7 days. - close-pr-message: I'm closing this PR automatically with the assumption that other builds have succeeded in the meantime. + days-before-pr-stale: 1 + days-before-pr-close: 0 + stale-pr-message: Closing this PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging. If this has been a manual PR, please reopen it and add the \`no-auto-close\` label to prevent this from happening again. + close-pr-message: Closing this pull request as it hasn't seen activity for a while. Please add a comment @mentioning a maintainer to reopen. If you wish to exclude this issue from being marked as stale, add the "no-auto-close" label. stale-pr-label: stale - exempt-pr-labels: backlog + exempt-pr-labels: no-auto-close days-before-issue-stale: 45 days-before-issue-close: 14 stale-issue-message: 45 days have passed since this issue was opened, and I assume other publishes have succeeded in the meantime. If no one removes the \`stale\` label or comments, I'm going to auto-close this issue in 14 days. @@ -6626,7 +6599,6 @@ jobs: !/.projen/tasks.json !/.projen/deps.json !/.projen/files.json -!/.mergify.yml !/.github/workflows/pull-request-lint.yml !/.github/workflows/stale.yml !/package.json @@ -6680,6 +6652,7 @@ package-lock.json !/.github/workflows/auto-approve.yml !/.github/workflows/auto-close-community-issues.yml !/.github/workflows/auto-close-community-prs.yml +!/.github/workflows/automerge.yml !/.github/workflows/lock.yml !/.github/workflows/next-cdktf-version-pr.yml !/.github/workflows/alert-open-prs.yml @@ -6689,66 +6662,12 @@ package-lock.json API.md !/docs/*.md !/.copywrite.hcl -", - ".mergify.yml": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". - -queue_rules: - - name: default - update_method: merge - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go -pull_request_rules: - - name: Automatically approve PRs with automerge label - actions: - review: - type: APPROVE - message: Automatically approved due to label - conditions: - - label=automerge - - -label~=(do-not-merge) - - -draft - - author=team-tf-cdk - - name: Automatically close stale PRs - actions: - close: - message: Closing this automatic PR, if it has not merged there is most likely a CI or CDKTF issue preventing it from merging - conditions: - - author=team-tf-cdk - - -draft - - created-at<1 day ago - - name: Automatic merge on approval and successful build - actions: - delete_head_branch: {} - queue: - method: squash - name: default - commit_message_template: |- - {{ title }} (#{{ number }}) - - {{ body }} - conditions: - - "#approved-reviews-by>=1" - - -label~=(do-not-merge) - - status-success=build - - status-success=package-js - - status-success=package-java - - status-success=package-python - - status-success=package-dotnet - - status-success=package-go ", ".npmignore": "# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen". /.projen/ permissions-backup.acl /dist/changelog.md /dist/version.txt -/.mergify.yml /test/ /tsconfig.dev.json /src/ @@ -6886,6 +6805,7 @@ scripts ".github/workflows/auto-approve.yml", ".github/workflows/auto-close-community-issues.yml", ".github/workflows/auto-close-community-prs.yml", + ".github/workflows/automerge.yml", ".github/workflows/build.yml", ".github/workflows/force-release.yml", ".github/workflows/lock.yml", @@ -6896,7 +6816,6 @@ scripts ".github/workflows/stale.yml", ".github/workflows/upgrade-main.yml", ".gitignore", - ".mergify.yml", ".projen/deps.json", ".projen/files.json", ".projen/tasks.json",