Skip to content

Commit

Permalink
[Release to Main] (#2127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Blainegunn authored Apr 9, 2024
2 parents a7ee0a5 + a8127a7 commit c058cea
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 5 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/enforce-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
steps:
- uses: yogevbd/[email protected]
with:
REQUIRED_LABELS_ANY: "verified,trivial,needs-verification"
REQUIRED_LABELS_ANY_DESCRIPTION: "PR must be labeled with 'trivial', 'needs-verification', or 'verified'"
BANNED_LABELS: "do-not-merge,duplicate,invalid,wontfix"
REQUIRED_LABELS_ANY: "verified,trivial,needs-verification,zero-impact"
REQUIRED_LABELS_ANY_DESCRIPTION: "PR must be labeled with 'trivial', 'zero-impact', 'needs-verification', or 'verified'"
BANNED_LABELS: "do not merge,duplicate,invalid,wontfix"
BANNED_LABELS_DESCRIPTION: "This PR has a banned label, if a PR is not ready or should not be merged, please close it and open a new one."
19 changes: 19 additions & 0 deletions .github/workflows/mark-stale-prs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Close stale pull requests"
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR has not been updated recently and will be closed in 7 days if no action is taken. Please ensure all checks are passing, https://github.com/orgs/adobecom/discussions/997 provides instructions. If the PR is ready to be merged, please mark it with the "Ready for Stage" label.'
close-pr-message: 'Closing this PR due to inactivity.'
days-before-stale: 7
days-before-close: 7
exempt-pr-labels: 'Ready for Stage'
operations-per-run: 100
133 changes: 133 additions & 0 deletions .github/workflows/pr-reminders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/pr-reminders.js

const main = async ({ github, context }) => {
const comment = async ({ pr, message, comments }) => {
if (comments.some((c) => c.body.includes(message))) {
console.log(
`PR #${pr.number} Comment exists. Commenting skipped... ${message}`
);
return;
}
process.env.LOCAL_RUN
? console.log(
`PR #${pr.number} Local execution commenting SKIPPED message: ${message}`
)
: await github.rest.issues
.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
body: message,
})
.then(() => console.log(`PR #${pr.number} Commented: ${message}`))
.catch(console.error);
};

const getLatestChecks = async ({ pr }) => {
const { data: checks } = await github.rest.checks
.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: pr.head.sha,
})
.catch((error) => {
console.error(error);
return { data: { check_runs: [] } };
});
const checksByName = checks.check_runs.reduce((map, check) => {
if (
!map.has(check.name) ||
new Date(map.get(check.name).completed_at) <
new Date(check.completed_at)
) {
map.set(check.name, check);
}
return map;
}, new Map());
return Array.from(checksByName.values());
};

try {
const { data: openPRs } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
});

for await (const pr of openPRs) {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});

if (labels.some(({ name } = {}) => name === 'Ready for Stage' || name === 'Stale')) {
console.log(
`PR #${pr.number} has the 'Ready for Stage' or 'Stale' label. Skipping...`
);
continue;
}

const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
});

const latestChecks = await getLatestChecks({ github, context, pr });
if (latestChecks.some((check) => check.conclusion === 'failure')) {
comment({
pr,
comments,
message:
'This pull request is not passing all required checks. Please see [this discussion](https://github.com/orgs/adobecom/discussions/997) for information on how to get all checks passing. Inconsistent checks can be manually retried. If a test absolutely can not pass for a good reason, please add a comment with an explanation to the PR.',
});
continue;
}

const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number,
});

if (reviews.some((review) => review.state === 'CHANGES_REQUESTED')) {
console.log(`PR #${pr.number} has changes requested. Skipping...`);
continue;
}

if (reviews.filter((review) => review.state === 'APPROVED').length < 2) {
console.log(`PR #${pr.number} has less than 2 approvals. Skipping...`);
continue;
}

if(labels.some(({ name } = {}) => name === 'needs-verification')) {
comment({
pr,
comments,
message: 'This PR is currently in the `needs-verification` state. Please assign a QA engineer to verify the changes.'
})
continue;
}

comment({
pr,
comments,
message:
'Reminder to set the `Ready for Stage` label - to queue this to get merged to stage & production.',
});
}
} catch (error) {
console.error(error);
}
};

if (process.env.LOCAL_RUN) {
const { github, context } = require('./localWorkflowConfigs.js')();
main({
github,
context,
});
}

module.exports = main;
23 changes: 23 additions & 0 deletions .github/workflows/pr-reminders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: PR Reminders

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Remind PR initiators
uses: actions/[email protected]
with:
script: |
const main = require('./.github/workflows/pr-reminders.js')
main({ github, context })
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions libs/blocks/preflight/panels/martech.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ function getTable(strings) {
}

async function checkMartechMeta() {
const strings = [...document.querySelectorAll('main :is(h1, h2, h3, h4, h5, h6, a)')]
.filter((el) => !el.closest('[class*="metadata"]') && !el.innerText.startsWith('http'))
const elementList = 'h1, h2, h3, h4, h5, h6, a, .tracking-header, .click-link, .con-button';
const strings = [...document.querySelectorAll(`main :is(${elementList})`)]
.filter((el) => !el.closest('[class*="metadata"]') && !el.innerText.startsWith('http')
&& !el.querySelector(elementList))
.reduce((acc, curr) => {
const str = curr.innerText.trim();
if (str) acc.push(str);
Expand Down

0 comments on commit c058cea

Please sign in to comment.