From 54431f2a95687616a4277c27971a5f8b77d12b63 Mon Sep 17 00:00:00 2001 From: Okan Sahin <39759830+mokimo@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:47:10 +0200 Subject: [PATCH] Improve RCP communication by sending out reminders (#3070) * Improve RCP communication * Only run this on the adobecom repo * Wording * Prettify the file --- .github/workflows/helpers.js | 1 + .github/workflows/merge-to-stage.js | 2 +- .github/workflows/merge-to-stage.yaml | 1 + .github/workflows/rcp-notifier.js | 46 +++++++++++++++++++++++++++ .github/workflows/rcp-notifier.yml | 24 ++++++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/rcp-notifier.js create mode 100644 .github/workflows/rcp-notifier.yml diff --git a/.github/workflows/helpers.js b/.github/workflows/helpers.js index 056ac563f4..dcc7b0025d 100644 --- a/.github/workflows/helpers.js +++ b/.github/workflows/helpers.js @@ -149,4 +149,5 @@ module.exports = { slackNotification, pulls: { addLabels, addFiles, getChecks, getReviews }, isWithinRCP, + RCPDates, }; diff --git a/.github/workflows/merge-to-stage.js b/.github/workflows/merge-to-stage.js index e615c96538..e10feb89d7 100644 --- a/.github/workflows/merge-to-stage.js +++ b/.github/workflows/merge-to-stage.js @@ -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(); diff --git a/.github/workflows/merge-to-stage.yaml b/.github/workflows/merge-to-stage.yaml index 689fc6d85b..ee491407eb 100644 --- a/.github/workflows/merge-to-stage.yaml +++ b/.github/workflows/merge-to-stage.yaml @@ -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: diff --git a/.github/workflows/rcp-notifier.js b/.github/workflows/rcp-notifier.js new file mode 100644 index 0000000000..ad5bdd2cde --- /dev/null +++ b/.github/workflows/rcp-notifier.js @@ -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; diff --git a/.github/workflows/rcp-notifier.yml b/.github/workflows/rcp-notifier.yml new file mode 100644 index 0000000000..e9bbae768d --- /dev/null +++ b/.github/workflows/rcp-notifier.yml @@ -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 })