Skip to content

Commit

Permalink
automerge workflow - split and fix
Browse files Browse the repository at this point in the history
fix HEAD_REF -> GITHUB_HEAD_REF
split into condition checks script and a wait for tests script
  pr title is checked in condition checks only
  branch is used in wait checks
stop ignoring patternfly bumps - we have screenshot tests now

No-Issue
  • Loading branch information
himdel committed May 9, 2024
1 parent 6116e76 commit dcbe79c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 55 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/automerge-condition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// get these values from env instead of cli args due to RCE issues
const actor = process.env.GITHUB_ACTOR;
const branch = process.env.GITHUB_HEAD_REF;
const prTitle = process.env.PR_TITLE;

console.log({ actor, branch, prTitle });

if (actor != 'dependabot[bot]') {
console.log('Actor incorrect (GITHUB_ACTOR)');
process.exit(1);
}

if (!branch) {
console.log('Branch name not set (GITHUB_HEAD_REF)');
process.exit(1);
}

if (!prTitle) {
console.log('PR title not set (PR_TITLE)');
process.exit(1);
}

if (prTitle.includes('@types/node') && !prTitle.match(/from (\d+)\.\d+\.\d+ to \1\.\d+\.\d+/)) {
console.log('Not automerging major @types/node version bump');
process.exit(1);
}

process.exit(0);
Original file line number Diff line number Diff line change
@@ -1,66 +1,20 @@
const { exec } = require('node:child_process');
const [ _node, _automerge ] = process.argv;

// get these values from env instead of cli args due to RCE issues
let branch = null;
let prTitle = null;
let actor = null;
if (process.env.HEAD_REF) {
branch = process.env.HEAD_REF;
}
if (process.env.PR_TITLE) {
prTitle = process.env.PR_TITLE;
}
if (process.env.GITHUB_ACTOR) {
actor = process.env.GITHUB_ACTOR;
}

console.log({ branch, prTitle, actor });
const branch = process.env.GITHUB_HEAD_REF;

if (!branch) {
console.log('Branch name argument (first) was not specified');
process.exit(1);
}

if (!prTitle) {
console.log('PR title argument (second) was not specified');
process.exit(1);
}

if (!actor) {
console.log('Actor argument (third) was not specified');
process.exit(1);
}

if (actor != 'dependabot[bot]') {
console.log('Automerge works only for PRs created by dependabot.');
process.exit(1);
}

if (prTitle.includes('patternfly')) {
console.log('Automerge can\'t merge patternfly PRs.');
console.log('Branch name not set (GITHUB_HEAD_REF)');
process.exit(1);
}

if (prTitle.includes('@types/node')) {
console.log('Checking for @types/node version.');
const pattern = /from (\d+)\.\d+\.\d+ to \1\.\d+\.\d+/;
if (pattern.test(prTitle)) {
console.log('Version does match the pattern ' + pattern);
} else {
console.log('Version does not match the pattern ' + pattern);
process.exit(1);
}
}

console.log('Waiting for checks');

let waitCount = 0;

function waitForAll() {
waitCount++;
// dont cycle more that 50x (that is 50 minutes)
if (waitCount > 50) {

// fail after 30 minutes
if (waitCount > 30) {
console.log('Waiting limit reached. Exiting.');
process.exit(1);
}
Expand Down Expand Up @@ -141,6 +95,7 @@ function waitForAll() {
process.exit(1);
}

// retry after a minute
setTimeout(waitForAll, 60000);
},
);
Expand Down
13 changes: 9 additions & 4 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ jobs:
with:
node-version: '18'

- name: "Run automerge.js"
- name: "Check automerge conditions"
working-directory: ".github/workflows"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: "${{ github.event.pull_request.title }}"
run: |
node automerge.js
node automerge-condition.js
- name: "Wait for other tests"
working-directory: ".github/workflows"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node automerge-wait.js
- name: "Automerge the PR"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Automerge of PR"
gh pr merge "${{ github.event.pull_request.number }}" -s --auto

0 comments on commit dcbe79c

Please sign in to comment.