Skip to content

Commit

Permalink
add promotion github actions
Browse files Browse the repository at this point in the history
will automatically promote setup a PR to promote charts from dev-staging and staging-prod
  • Loading branch information
anish-mudaraddi committed Feb 11, 2025
1 parent 8ea7df8 commit 5469528
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/promote_to_prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Promote Staging to Prod

on:
schedule:
- cron: '0 12 * * 3' # Wednesday at 12pm UTC
workflow_dispatch:

jobs:
create-promotion-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Set branch and PR names
id: env-vars
run: |
echo "branch_name=staging-to-prod-${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT
echo "pr_title=Promote Staging to Prod - ${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT
- name: Create temporary copy for comparison
run: |
mkdir -p temp_compare
cp -r charts/prod temp_compare/
- name: Copy files
run: |
rm -rf charts/prod
cp -r charts/staging charts/prod
- name: Check for changes
id: check-changes
run: |
if diff -r temp_compare/prod charts/prod > /dev/null; then
echo "changes_detected=false" >> $GITHUB_OUTPUT
else
echo "changes_detected=true" >> $GITHUB_OUTPUT
fi
- name: Create promotion branch
if: steps.check-changes.outputs.changes_detected == 'true'
run: git checkout -b ${{ steps.env-vars.outputs.branch_name }}

- name: Commit changes
if: steps.check-changes.outputs.changes_detected == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add charts/prod
git commit -m "${{ steps.env-vars.outputs.pr_title }}"
- name: Push changes
if: steps.check-changes.outputs.changes_detected == 'true'
run: git push origin ${{ steps.env-vars.outputs.branch_name }}

- name: Create Pull Request
if: steps.check-changes.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: ${{ steps.env-vars.outputs.pr_title }}
body: |
Automated promotion PR to copy contents from `staging` to `prod`.
This PR was automatically created by the environment promotion workflow.
branch: ${{ steps.env-vars.outputs.branch_name }}
base: main
labels: |
automated
environment-promotion
- name: Log no changes
if: steps.check-changes.outputs.changes_detected == 'false'
run: echo "No changes detected between staging and prod. Skipping PR creation."
78 changes: 78 additions & 0 deletions .github/workflows/promote_to_staging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Promote Dev to Staging

on:
schedule:
- cron: '0 12 * * 2' # Tuesday at 12pm UTC
workflow_dispatch:

jobs:
create-promotion-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Set branch and PR names
id: env-vars
run: |
echo "branch_name=dev-to-staging-${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT
echo "pr_title=Promote Dev to Staging - ${{ steps.date.outputs.date }}" >> $GITHUB_OUTPUT
- name: Create temporary copy for comparison
run: |
mkdir -p temp_compare
cp -r charts/staging temp_compare/
- name: Copy files
run: |
rm -rf charts/staging
cp -r charts/dev charts/staging
- name: Check for changes
id: check-changes
run: |
if diff -r temp_compare/staging charts/staging > /dev/null; then
echo "changes_detected=false" >> $GITHUB_OUTPUT
else
echo "changes_detected=true" >> $GITHUB_OUTPUT
fi
- name: Create promotion branch
if: steps.check-changes.outputs.changes_detected == 'true'
run: git checkout -b ${{ steps.env-vars.outputs.branch_name }}

- name: Commit changes
if: steps.check-changes.outputs.changes_detected == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add charts/staging
git commit -m "${{ steps.env-vars.outputs.pr_title }}"
- name: Push changes
if: steps.check-changes.outputs.changes_detected == 'true'
run: git push origin ${{ steps.env-vars.outputs.branch_name }}

- name: Create Pull Request
if: steps.check-changes.outputs.changes_detected == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: ${{ steps.env-vars.outputs.pr_title }}
body: |
Automated promotion PR to copy contents from `dev` to `staging`.
This PR was automatically created by the environment promotion workflow.
branch: ${{ steps.env-vars.outputs.branch_name }}
base: main
labels: |
automated
environment-promotion
- name: Log no changes
if: steps.check-changes.outputs.changes_detected == 'false'
run: echo "No changes detected between dev and staging. Skipping PR creation."

0 comments on commit 5469528

Please sign in to comment.