generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
75 changed files
with
2,688 additions
and
1,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { | ||
slackNotification, | ||
getLocalConfigs, | ||
} = require('./helpers.js'); | ||
|
||
const main = async (params) => { | ||
const { context } = params; | ||
|
||
try { | ||
if (context.payload.label.name !== 'high-impact') { | ||
console.log('No high impact label detected'); | ||
return; | ||
} | ||
|
||
const { html_url, number, title } = context.payload.pull_request; | ||
console.log('High impact label detected, sending Slack notification'); | ||
slackNotification(`:alert: High Impact PR has been opened: <${html_url}|#${number}: ${title}>.` + | ||
` Please prioritize testing the proposed changes.`, process.env.SLACK_HIGH_IMPACT_PR_WEBHOOK); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
if (process.env.LOCAL_RUN) { | ||
const { context } = getLocalConfigs(); | ||
main({ context }); | ||
} | ||
|
||
module.exports = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: High Impact Alert | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- labeled | ||
|
||
env: | ||
SLACK_HIGH_IMPACT_PR_WEBHOOK: ${{ secrets.SLACK_HIGH_IMPACT_PR_WEBHOOK }} | ||
|
||
jobs: | ||
send_alert: | ||
if: github.repository_owner == 'adobecom' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4.1.4 | ||
|
||
- name: Send Slack message for high impact PRs | ||
uses: actions/github-script@v7.0.1 | ||
with: | ||
script: | | ||
const main = require('./.github/workflows/high-impact-alert.js') | ||
main({ github, context }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const { | ||
slackNotification, | ||
getLocalConfigs, | ||
isWithinRCP, | ||
pulls: { addLabels, addFiles, getChecks, getReviews }, | ||
} = require('./helpers.js'); | ||
|
||
// Run from the root of the project for local testing: node --env-file=.env .github/workflows/merge-to-main.js | ||
const PR_TITLE = '[Release] Stage to Main'; | ||
const STAGE = 'stage'; | ||
const PROD = 'main'; | ||
|
||
let github, owner, repo; | ||
|
||
const getStageToMainPR = () => | ||
github.rest.pulls | ||
.list({ owner, repo, state: 'open', base: PROD, head: STAGE }) | ||
.then(({ data } = {}) => data.find(({ title } = {}) => title === PR_TITLE)) | ||
.then((pr) => pr && addLabels({ pr, github, owner, repo })); | ||
|
||
const workingHours = () => { | ||
const now = new Date(); | ||
const day = now.getUTCDay(); | ||
const hour = now.getUTCHours(); | ||
const isSunday = day === 0; | ||
const isSaturday = day === 6; | ||
const isFriday = day === 5; | ||
return hour >= 8 && hour <= 20 && !isFriday && !isSaturday && !isSunday; | ||
}; | ||
|
||
const main = async (params) => { | ||
github = params.github; | ||
owner = params.context.repo.owner; | ||
repo = params.context.repo.repo; | ||
|
||
if (isWithinRCP()) return console.log('Stopped, within RCP period.'); | ||
if (!workingHours()) return console.log('Stopped, outside working hours.'); | ||
|
||
try { | ||
const stageToMainPR = await getStageToMainPR(); | ||
const signOffs = stageToMainPR?.labels.filter((l) => l.includes('SOT')); | ||
console.log(`${signOffs.length} SOT labels on PR ${stageToMainPR.number}`); | ||
if (signOffs.length >= 4) { | ||
console.log('Stage to Main PR has all required labels. Merging...'); | ||
await github.rest.pulls.merge({ | ||
owner, | ||
repo, | ||
pull_number: stageToMainPR.number, | ||
merge_method: 'merge', | ||
}); | ||
|
||
await slackNotification( | ||
`:rocket: Production release <${stageToMainPR.html_url}|${stageToMainPR.number}>` | ||
); | ||
|
||
await github.rest.repos.createDispatchEvent({ | ||
owner, | ||
repo, | ||
event_type: 'merge-to-stage', | ||
}); | ||
} | ||
|
||
console.log('Process successfully executed.'); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
if (process.env.LOCAL_RUN) { | ||
const { github, context } = getLocalConfigs(); | ||
main({ | ||
github, | ||
context, | ||
}); | ||
} | ||
|
||
module.exports = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Merge to main | ||
|
||
on: | ||
pull_request: | ||
types: [labeled] | ||
schedule: | ||
- cron: '0 9 * * *' # Run every day at 9am UTC | ||
workflow_dispatch: # Allow manual trigger | ||
|
||
env: | ||
MILO_RELEASE_SLACK_WH: ${{ secrets.MILO_RELEASE_SLACK_WH }} | ||
|
||
jobs: | ||
merge-to-main: | ||
runs-on: ubuntu-latest | ||
environment: milo_pr_merge | ||
# Run this when manually triggered or on a schedule | ||
# Otherwise run this only on PRs that are merged from stage to main | ||
if: github.repository_owner == 'adobecom' && (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.ref == 'stage')) | ||
|
||
steps: | ||
- uses: actions/create-github-app-token@v1.10.0 | ||
id: milo-pr-merge-token | ||
with: | ||
app-id: ${{ secrets.MILO_PR_MERGE_APP_ID }} | ||
private-key: ${{ secrets.MILO_PR_MERGE_PRIVATE_KEY }} | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4.1.4 | ||
|
||
- name: Merge to main | ||
uses: actions/github-script@v7.0.1 | ||
with: | ||
github-token: ${{ steps.milo-pr-merge-token.outputs.token }} | ||
script: | | ||
const main = require('./.github/workflows/merge-to-main.js') | ||
main({ github, context }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.