From 652c64684e3aa54127457c12b7a61e0350a0dc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 28 Jun 2022 16:18:32 +0200 Subject: [PATCH] Use the custom cron action for DCO and renovate merges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Patrik Oldsberg Co-authored-by: blam Co-authored-by: Johan Haals Signed-off-by: Fredrik Adelöw --- .../automate_merge_renovate_prs.yaml | 85 ------------------- .github/workflows/cron.yml | 11 +++ .github/workflows/verify_dco.yaml | 65 -------------- 3 files changed, 11 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/automate_merge_renovate_prs.yaml create mode 100644 .github/workflows/cron.yml delete mode 100644 .github/workflows/verify_dco.yaml diff --git a/.github/workflows/automate_merge_renovate_prs.yaml b/.github/workflows/automate_merge_renovate_prs.yaml deleted file mode 100644 index 8de488cf05..0000000000 --- a/.github/workflows/automate_merge_renovate_prs.yaml +++ /dev/null @@ -1,85 +0,0 @@ -name: Automate Merge Renovate PRs - -on: - workflow_dispatch: - schedule: - - cron: '*/10 * * * *' - -jobs: - diff: - runs-on: ubuntu-latest - steps: - - uses: actions/github-script@v6 - with: - script: | - const owner = "backstage"; - const repo = "backstage"; - const query = `{ - repository(owner: "backstage", name: "backstage") { - pullRequests(labels: ["dependencies"], last: 10, states: [OPEN]) { - nodes { - title - author { - login - } - number - mergeable - files(first: 1) { - nodes { - path - } - } - changedFiles - commits(last: 1) { - nodes { - commit { - statusCheckRollup { - state - } - } - } - } - reviewDecision - reviews(first: 10) { - nodes { - author { - login - } - } - } - } - } - } - }`; - - const date = new Date(); - if (date.getDay() === 2) { - console.log("Skipping auto merge because Tuesday is release day"); - return; - } - - const r = await github.graphql(query); - const mergable = r.repository.pullRequests.nodes.filter( - (pr) => - pr.author.login === "renovate" && - pr.mergeable === "MERGEABLE" && - pr.changedFiles === 1 && - pr.files.nodes[0].path.split("/").slice(-1)[0] === "yarn.lock" && - pr.commits.nodes[0].commit.statusCheckRollup.state === "SUCCESS" && - pr.reviewDecision === "APPROVED" - ); - - if (mergable.length === 0) { - console.log("no mergable PRs"); - return; - } - - for (const pr of mergable) { - console.log(`Merging #${pr.number} - ${pr.title}`); - await github.rest.pulls.merge({ - owner, - repo, - pull_number: pr.number, - }); - await new Promise((r) => setTimeout(r, 2000)); - } diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml new file mode 100644 index 0000000000..394d726fef --- /dev/null +++ b/.github/workflows/cron.yml @@ -0,0 +1,11 @@ +name: Cron +on: + workflow_dispatch: + schedule: + - cron: '*/5 * * * *' + +jobs: + cron: + runs-on: ubuntu-latest + steps: + - uses: backstage/actions/cron@v0.1.3 diff --git a/.github/workflows/verify_dco.yaml b/.github/workflows/verify_dco.yaml deleted file mode 100644 index 2094327d23..0000000000 --- a/.github/workflows/verify_dco.yaml +++ /dev/null @@ -1,65 +0,0 @@ -name: Verify DCO -on: - schedule: - - cron: '*/15 * * * *' - -jobs: - dco-helper: - runs-on: ubuntu-latest - steps: - - name: Verify DCO status for open pull requests - uses: actions/github-script@v6 - with: - script: | - const owner = "backstage"; - const repo = "backstage"; - const pulls = await github.paginate(github.rest.pulls.list, { - state: "open", - owner, - repo, - }); - - for (const pull of pulls) { - // Pick out the PRs that have the DCO check - const checks = await github.rest.checks.listForRef({ - owner, - repo, - ref: pull.head.sha, - check_name: "DCO", - status: "completed", - }); - // Skip if there are no checks - if (!checks.data.check_runs.length) { - continue; - } - // Skip if the conclusion is not action_required - if (checks.data.check_runs[0].conclusion !== "action_required") { - console.log(`No checks found for PR #${pull.number}, skipping`); - continue; - } - - const comments = await github.paginate(github.rest.issues.listComments, { - owner, - repo, - issue_number: pull.number, - }); - if (comments.find((c) => - c.user.login === "github-actions[bot]" && - c.body.includes("") - ) - ) { - console.log(`already commented on PR #${pull.number}, skipping`); - continue; - } - console.log(`creating comment on PR #${pull.number}`); - const body = ` - Thanks for the contribution! - All commits need to be DCO signed before they are reviewed. Please refer to the the [DCO section in CONTRIBUTING.md](https://github.com/backstage/backstage/blob/master/CONTRIBUTING.md#developer-certificate-of-origin) or the [DCO](${checks.data.check_runs[0].html_url}) status for more info. - `; - await github.rest.issues.createComment({ - repo, - owner, - issue_number: pull.number, - body, - }); - }