Skip to content

Commit

Permalink
Improve RCP communication by sending out reminders (#3070)
Browse files Browse the repository at this point in the history
* Improve RCP communication

* Only run this on the adobecom repo

* Wording

* Prettify the file
  • Loading branch information
mokimo authored Oct 24, 2024
1 parent 543ef4d commit 54431f2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@ module.exports = {
slackNotification,
pulls: { addLabels, addFiles, getChecks, getReviews },
isWithinRCP,
RCPDates,
};
2 changes: 1 addition & 1 deletion .github/workflows/merge-to-stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const main = async (params) => {
github = params.github;
owner = params.context.repo.owner;
repo = params.context.repo.repo;
if (isWithinRCP(2)) return console.log('Stopped, within RCP period.');
if (isWithinRCP(process.env.STAGE_RCP_OFFSET_DAYS || 2)) return console.log('Stopped, within RCP period.');

try {
const stageToMainPR = await getStageToMainPR();
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/merge-to-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
SLACK_HIGH_IMPACT_PR_WEBHOOK: ${{ secrets.SLACK_HIGH_IMPACT_PR_WEBHOOK }}
MILO_STAGE_SLACK_WH: ${{secrets.MILO_STAGE_SLACK_WH}}
MAX_PRS_PER_BATCH: ${{secrets.MAX_PRS_PER_BATCH}}
STAGE_RCP_OFFSET_DAYS: ${{secrets.STAGE_RCP_OFFSET_DAYS}}

jobs:
merge-to-stage:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/rcp-notifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const {
slackNotification,
getLocalConfigs,
RCPDates,
} = require('./helpers.js');

const isWithin24Hours = (targetDate) =>
Math.abs(new Date() - targetDate) <= 24 * 60 * 60 * 1000;

const calculateDateOffset = (date, offset) => {
const newDate = new Date(date);
newDate.setDate(newDate.getDate() - offset);
return newDate;
};

// Run from the root of the project for local testing: node --env-file=.env .github/workflows/rcp-notifier.js
const main = async () => {
console.log('Action: RCP Notifier started');
for (const rcp of RCPDates) {
const start = new Date(rcp.start);
const end = new Date(rcp.end);
const tenDaysBefore = calculateDateOffset(start, 10);
const fourDaysBefore = calculateDateOffset(start, 4);
const stageOffset = Number(process.env.STAGE_RCP_OFFSET_DAYS) || 2;
const slackText = (days) =>
`Reminder RCP starts in ${days} days: from ${start.toUTCString()} to ${end.toUTCString()}. Merges to stage will be disabled beginning ${calculateDateOffset(start, stageOffset).toUTCString()}.`;
if (isWithin24Hours(tenDaysBefore)) {
console.log('Is within 24 hours of 10 days before RCP');
await slackNotification(slackText(10), process.env.MILO_DEV_HOOK);
}

if (isWithin24Hours(fourDaysBefore)) {
console.log('Is within 24 hours of 4 days before RCP');
await slackNotification(slackText(4), process.env.MILO_DEV_HOOK);
}
}

console.log('Action: RCP Notifier completed');
};

if (process.env.LOCAL_RUN) {
const { context } = getLocalConfigs();
main({ context });
}

module.exports = main;
24 changes: 24 additions & 0 deletions .github/workflows/rcp-notifier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: RCP Notifier

on:
schedule:
- cron: '43 9 * * *' # 9.43am UTC

env:
STAGE_RCP_OFFSET_DAYS: ${{ secrets.STAGE_RCP_OFFSET_DAYS }}
MILO_DEV_HOOK: ${{ secrets.MILO_DEV_HOOK }}

jobs:
rcp-notification:
if: github.repository_owner == 'adobecom'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Create RCP Notification
uses: actions/github-script@v7
with:
script: |
const main = require('./.github/workflows/rcp-notifier.js')
main({ github, context })

0 comments on commit 54431f2

Please sign in to comment.