From 46274febb6575658c2c37516076e5d66db4d866f Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 3 May 2022 16:11:49 +0200 Subject: [PATCH 1/3] gh actions: Automatically merge lock file dependency bumps Signed-off-by: Johan Haals --- .github/renovate.json5 | 7 +- .../automate_merge_renovate_prs.yaml | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/automate_merge_renovate_prs.yaml diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 000b27018d..ff351a5e0f 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -1,11 +1,6 @@ { labels: ['dependencies'], - extends: [ - 'config:base', - ':disableDependencyDashboard', - ':gitSignOff', - ':automergePatch', - ], + extends: ['config:base', ':disableDependencyDashboard', ':gitSignOff'], rangeStrategy: 'update-lockfile', // @elastic/elasticsearch is ignored due to licensing issues. See #10992 ignoreDeps: ['@elastic/elasticsearch'], diff --git a/.github/workflows/automate_merge_renovate_prs.yaml b/.github/workflows/automate_merge_renovate_prs.yaml new file mode 100644 index 0000000000..ded3a1a4b9 --- /dev/null +++ b/.github/workflows/automate_merge_renovate_prs.yaml @@ -0,0 +1,85 @@ +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(name: "backstage", owner: "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 approve 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)); + } From ac9614c422b41c9fed15b814db32a7ab44c9eaf5 Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 3 May 2022 16:25:53 +0200 Subject: [PATCH 2/3] reshuffle arguments Signed-off-by: Johan Haals Co-authored-by: Patrik Oldsberg --- .github/workflows/automate_merge_renovate_prs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/automate_merge_renovate_prs.yaml b/.github/workflows/automate_merge_renovate_prs.yaml index ded3a1a4b9..998c04dcdc 100644 --- a/.github/workflows/automate_merge_renovate_prs.yaml +++ b/.github/workflows/automate_merge_renovate_prs.yaml @@ -15,7 +15,7 @@ jobs: const owner = "backstage"; const repo = "backstage"; const query = `{ - repository(name: "backstage", owner: "backstage") { + repository(owner: "backstage", name: "backstage") { pullRequests(labels: ["dependencies"], last: 10, states: [OPEN]) { nodes { title From 101d118eb1e73fb54a84da963701d80af24f5ffd Mon Sep 17 00:00:00 2001 From: Johan Haals Date: Tue, 3 May 2022 16:26:05 +0200 Subject: [PATCH 3/3] fix wording Signed-off-by: Johan Haals Co-authored-by: Patrik Oldsberg --- .github/workflows/automate_merge_renovate_prs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/automate_merge_renovate_prs.yaml b/.github/workflows/automate_merge_renovate_prs.yaml index 998c04dcdc..8de488cf05 100644 --- a/.github/workflows/automate_merge_renovate_prs.yaml +++ b/.github/workflows/automate_merge_renovate_prs.yaml @@ -54,7 +54,7 @@ jobs: const date = new Date(); if (date.getDay() === 2) { - console.log("Skipping auto approve because Tuesday is release day"); + console.log("Skipping auto merge because Tuesday is release day"); return; }