nightly-sync-to-prod #366
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
name: nightly-sync-to-prod | |
on: | |
schedule: | |
- cron: '0 7 * * *' | |
workflow_dispatch: | |
jobs: | |
nightly-sync-validate: | |
if: endsWith( github.repository, '-sandbox' ) | |
runs-on: self-hosted | |
outputs: | |
status: ${{ steps.jenkins-job-apply.outputs.job_status }} | |
steps: | |
- name: trigger jenkins validation job (plan) | |
id: jenkins-job-apply | |
uses: morganschoen/build-jenkins-job@master | |
with: | |
jenkins-url: "https://jenkins.ncttools.io" | |
jenkins-token: ${{ secrets.JENKINS_API_TOKEN }} | |
jenkins-user: ${{ secrets.JENKINS_API_USERNAME }} | |
# jenkins-job: ${{ github.event.repository.name }}/release | |
jenkins-job: nct-cloud-custodian-sandbox/release | |
jenkins-wait-job: "wait" | |
jenkins-ssl-verify: "true" | |
jenkins-job-params: '{"anyParam": "anyValue"}' | |
- name: notify slack on failure (plan) | |
if: startsWith(steps.jenkins-job-apply.outputs.job_status, 'FAIL') | |
uses: tokorom/action-slack-incoming-webhook@main | |
env: | |
INCOMING_WEBHOOK_URL: ${{ secrets.NIGHTLY_SYNC_SLACK_ALERT_WEBHOOK_URL }} | |
with: | |
text: | |
attachments: | | |
[ | |
{ | |
"color": "danger", | |
"fields": [ | |
{ | |
"title": "${{github.event.repository.name}}: Nightly sandbox validation failed. ", | |
"value": "Skipping sync to prod release branch. Please review errors in build # <https://jenkins.ncttools.io/job/nct-cloud-custodian-sandbox/job/release/${{steps.jenkins-job-apply.outputs.job_build_number}}/console|${{steps.jenkins-job-apply.outputs.job_build_number}}>" | |
} | |
] | |
} | |
] | |
nightly-sync: | |
if: startsWith(needs.nightly-sync-validate.outputs.status, 'SUCCESS') | |
needs: nightly-sync-validate | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout main | |
uses: actions/checkout@v2 | |
with: | |
ref: master | |
# fetch-depth: 0 | |
- name: create temp branch | |
id: temp-branch | |
uses: morganschoen/temporary-branch-action@main | |
with: | |
base: master | |
- name: Fetch branch in Sandbox | |
run: | | |
git fetch | |
git push --set-upstream origin ${{ steps.temp-branch.outputs.branch }} | |
- name: commit changes to temp branch | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
branch: ${{ steps.temp-branch.outputs.branch }} | |
commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | |
- name: sync temp branch to target release branch | |
uses: wei/git-sync@v3 | |
with: | |
source_repo: [email protected]:newscorp-ghfb/cloud-custodian-sandbox.git | |
source_branch: ${{ steps.temp-branch.outputs.branch }} | |
source_ssh_private_key: ${{ secrets.GIT_SYNC_SOURCE_PRIVATE_KEY }} | |
destination_repo: [email protected]:newscorp-ghfb/cloud-custodian.git | |
destination_branch: release | |
destination_ssh_private_key: ${{ secrets.GIT_SYNC_DESTINATION_PRIVATE_KEY }} | |
- name: delete temp branch | |
uses: dawidd6/action-delete-branch@v3 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branches: ${{ steps.temp-branch.outputs.branch }} |