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.
Merge branch 'stage' of https://github.com/adobecom/milo into pep-geo…
…routing
- Loading branch information
Showing
46 changed files
with
1,032 additions
and
124 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
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
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
Validating CODEOWNERS rules …
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
Oops, something went wrong.