-
Notifications
You must be signed in to change notification settings - Fork 20
Setup new workflow for dev and prod #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
350b88e
setup new workflow for dev and prod
achyu-dev edf4e58
added new job for syncing dev and main
achyu-dev 715409c
minor fix
achyu-dev 813b5a1
Update workflow triggers
aditeyabaral 625df11
Create staging workflow
aditeyabaral e26b25a
Update staging and prod workflow
aditeyabaral 62a41a9
Update workflow names
aditeyabaral 8496338
Update pre-commit workflow
aditeyabaral 0ede044
Update pre-commit workflow
aditeyabaral File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
120 changes: 83 additions & 37 deletions
120
.github/workflows/deploy.yaml β .github/workflows/deploy-prod.yaml
This file contains hidden or 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 |
|---|---|---|
| @@ -1,121 +1,167 @@ | ||
| name: Deploy | ||
| name: Deploy to Production | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: [ "Pre-Commit Checks" ] | ||
| types: | ||
| - completed | ||
| workflow_dispatch: | ||
|
|
||
| env: | ||
| # Array of usernames allowed to trigger production deploys | ||
| ALLOWED_USERS: '["aditeyabaral", "achyu-dev", "ndigvijay"]' | ||
|
|
||
| jobs: | ||
| # Docker build and push (main only) | ||
| # Sync dev branch to main before deployment | ||
| sync-dev-to-main: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ contains(fromJson(env.ALLOWED_USERS), github.actor) }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Configure Git | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| - name: Fetch all branches | ||
| run: | | ||
| git fetch origin dev | ||
| git fetch origin main | ||
| - name: Checkout main branch | ||
| run: git checkout main | ||
|
|
||
| - name: Merge dev into main | ||
| run: | | ||
| git merge --ff-only origin/dev || { | ||
| echo "β Fast-forward merge failed. Manual conflict resolution required." | ||
| echo "Please ensure dev branch is ahead of main with no conflicts." | ||
| git merge --abort | ||
| exit 1 | ||
| } | ||
| - name: Push updated main branch | ||
| run: git push origin main | ||
|
|
||
| # Build and push Docker images | ||
| push-to-dockerhub: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.conclusion == 'success' }} | ||
| needs: sync-dev-to-main | ||
| if: ${{ contains(fromJson(env.ALLOWED_USERS), github.actor) }} | ||
| env: | ||
| DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | ||
| DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
|
|
||
| - name: Check Docker credentials | ||
| run: | | ||
| if [ -z "${{ secrets.DOCKER_USERNAME }}" ] || [ -z "${{ secrets.DOCKER_PASSWORD }}" ]; then | ||
| echo "Secrets missing, skipping push" | ||
| echo "β Docker credentials missing, skipping Docker Hub push" | ||
| exit 1 | ||
| fi | ||
| - name: Get short commit hash | ||
| id: vars | ||
| run: echo "tag=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Log in to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Build and tag image | ||
| run: | | ||
| docker build . --tag ${{ secrets.DOCKER_USERNAME }}/pesu-auth:${{ steps.vars.outputs.tag }} | ||
| docker tag ${{ secrets.DOCKER_USERNAME }}/pesu-auth:${{ steps.vars.outputs.tag }} ${{ secrets.DOCKER_USERNAME }}/pesu-auth:latest | ||
| - name: Push image to Docker Hub | ||
| run: | | ||
| docker push ${{ secrets.DOCKER_USERNAME }}/pesu-auth:${{ steps.vars.outputs.tag }} | ||
| docker push ${{ secrets.DOCKER_USERNAME }}/pesu-auth:latest | ||
| # GHCR build and push (main only) | ||
| # Push to GitHub Container Registry | ||
| push-to-ghcr: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.conclusion == 'success' }} | ||
| needs: sync-dev-to-main | ||
| if: ${{ contains(fromJson(env.ALLOWED_USERS), github.actor) }} | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
|
|
||
| - name: Get short commit hash | ||
| id: vars | ||
| run: echo "tag=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and tag image for GHCR | ||
| run: | | ||
| docker build . --tag ghcr.io/${{ github.repository_owner }}/pesu-auth:${{ steps.vars.outputs.tag }} | ||
| docker tag ghcr.io/${{ github.repository_owner }}/pesu-auth:${{ steps.vars.outputs.tag }} ghcr.io/${{ github.repository_owner }}/pesu-auth:latest | ||
| - name: Push image to GitHub Container Registry | ||
| run: | | ||
| docker push ghcr.io/${{ github.repository_owner }}/pesu-auth:${{ steps.vars.outputs.tag }} | ||
| docker push ghcr.io/${{ github.repository_owner }}/pesu-auth:latest | ||
| # Deploy both environments on main | ||
| # Deploy to both Production and Staging | ||
| deploy-prod-and-staging: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.head_branch == 'main' && github.event.workflow_run.conclusion == 'success' }} | ||
| needs: [sync-dev-to-main, push-to-dockerhub, push-to-ghcr] | ||
aditeyabaral marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if: ${{ contains(fromJson(env.ALLOWED_USERS), github.actor) }} | ||
| env: | ||
| RENDER_DEPLOY_HOOK_URL_PROD: ${{ secrets.RENDER_DEPLOY_HOOK_URL_PROD }} | ||
| RENDER_DEPLOY_HOOK_URL_DEV: ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} | ||
| steps: | ||
| - name: Check Deploy Hook URLs | ||
| run: | | ||
| if [ -z "${{ secrets.RENDER_DEPLOY_HOOK_URL_PROD }}" ]; then | ||
| echo "Production deploy hook missing!" | ||
| echo "β Production deploy hook missing!" | ||
| exit 1 | ||
| fi | ||
| if [ -z "${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }}" ]; then | ||
| echo "Staging deploy hook missing!" | ||
| echo "β Staging deploy hook missing!" | ||
| exit 1 | ||
| fi | ||
| - name: Deploy to Production | ||
| run: | | ||
| echo "π Deploying to Production..." | ||
| curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL_PROD }} || { | ||
| echo "β Production deploy failed!" | ||
| exit 1 | ||
| } | ||
| - name: Sync Staging with Production | ||
| run: | | ||
| echo "π Deploying to Staging (mirror prod)..." | ||
| curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} || { | ||
| echo "β Staging deploy failed!" | ||
| exit 1 | ||
| } | ||
| echo "β Production deployment completed successfully!" | ||
| # Deploy only to staging on dev | ||
| deploy-staging-only: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.head_branch == 'dev' && github.event.workflow_run.conclusion == 'success' }} | ||
| env: | ||
| RENDER_DEPLOY_HOOK_URL_DEV: ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} | ||
| steps: | ||
| - name: Check Staging Deploy Hook URL | ||
| run: | | ||
| if [ -z "${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }}" ]; then | ||
| echo "Staging deploy hook missing!" | ||
| exit 1 | ||
| fi | ||
| - name: Deploy to Staging (Dev branch) | ||
| - name: Deploy to Staging | ||
| run: | | ||
| echo "π Deploying to Staging..." | ||
| curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} || { | ||
| echo "β Staging deploy failed!" | ||
| exit 1 | ||
| } | ||
| echo "β Staging deployment completed successfully!" | ||
| - name: Deployment Summary | ||
| run: | | ||
| echo "π All deployments completed successfully!" | ||
| echo "β Branch sync: dev β main" | ||
| echo "β Docker images: pushed to Docker Hub and GHCR" | ||
| echo "β Production: deployed" | ||
| echo "β Staging: deployed" | ||
This file contains hidden or 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,31 @@ | ||
| name: Deploy to Staging | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: [ "Pre-Commit Checks" ] | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| # Deploy to staging environment | ||
| deploy-staging: | ||
| runs-on: ubuntu-latest | ||
| if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'dev' }} | ||
| env: | ||
| RENDER_DEPLOY_HOOK_URL_DEV: ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} | ||
| steps: | ||
| - name: Check Staging Deploy Hook URL | ||
| run: | | ||
| if [ -z "${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }}" ]; then | ||
| echo "β Staging deploy hook missing!" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Deploy to Staging Environment | ||
| run: | | ||
| echo "π Deploying to Staging..." | ||
| curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }} || { | ||
| echo "β Staging deploy failed!" | ||
| exit 1 | ||
| } | ||
| echo "β Staging deployment completed successfully!" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.