Merge pull request #12289 from backstage/mob/use-shared-actions

Use the custom cron action for DCO and renovate merges
This commit is contained in:
Ben Lambert
2022-06-28 16:24:04 +02:00
committed by GitHub
3 changed files with 11 additions and 150 deletions
@@ -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));
}
+11
View File
@@ -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
-65
View File
@@ -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("<!-- dco -->")
)
) {
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.
<!-- dco -->`;
await github.rest.issues.createComment({
repo,
owner,
issue_number: pull.number,
body,
});
}