Skip to content
Open
87 changes: 83 additions & 4 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,89 @@ jobs:
- name: Push updated main branch
run: git push origin main

# Bump minor version on main
bump-minor-version:
runs-on: ubuntu-latest
needs: sync-dev-to-main
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
Comment thread
aditeyabaral marked this conversation as resolved.
permissions:
contents: write
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: main
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: Bump minor version
run: |
python3 - <<'EOF'
import re

with open("pyproject.toml") as f:
content = f.read()

match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE)
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3))
new_version = f"{major}.{minor + 1}.0"

new_content = re.sub(
r'^version = "\d+\.\d+\.\d+"',
f'version = "{new_version}"',
content,
count=1,
flags=re.MULTILINE,
)

with open("pyproject.toml", "w") as f:
f.write(new_content)

print(f"Bumped: {major}.{minor}.{patch} -> {new_version}")
EOF

- name: Commit and push
run: |
git add pyproject.toml
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
git diff --cached --quiet && exit 0
git commit -m "chore: bump minor version [skip ci]"
Comment thread
aditeyabaral marked this conversation as resolved.
Comment thread
aditeyabaral marked this conversation as resolved.
git push origin main
Comment thread
aditeyabaral marked this conversation as resolved.

# Sync minor version bump back to dev so dev and main stay on the same commit
sync-minor-to-dev:
runs-on: ubuntu-latest
needs: bump-minor-version
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
permissions:
contents: write
steps:
- name: Checkout dev
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: dev
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: Fast-forward dev to main
run: |
git fetch origin main
git merge --ff-only origin/main
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
git push origin dev

# Build and push Docker images
push-to-dockerhub:
runs-on: ubuntu-latest
needs: sync-dev-to-main
needs: bump-minor-version
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
Expand Down Expand Up @@ -84,7 +163,7 @@ jobs:
# Push to GitHub Container Registry
push-to-ghcr:
runs-on: ubuntu-latest
needs: sync-dev-to-main
needs: bump-minor-version
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
permissions:
contents: read
Expand Down Expand Up @@ -119,7 +198,7 @@ jobs:
# Deploy to Staging
deploy-to-staging:
runs-on: ubuntu-latest
needs: [sync-dev-to-main, push-to-dockerhub, push-to-ghcr]
needs: [bump-minor-version, push-to-dockerhub, push-to-ghcr]
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
env:
RENDER_DEPLOY_HOOK_URL_DEV: ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }}
Expand All @@ -143,7 +222,7 @@ jobs:
# Deploy to Production
deploy-to-prod:
runs-on: ubuntu-latest
needs: [sync-dev-to-main, push-to-dockerhub, push-to-ghcr, deploy-to-staging]
needs: [bump-minor-version, push-to-dockerhub, push-to-ghcr, deploy-to-staging, sync-minor-to-dev]
if: ${{ contains(fromJson(vars.PROD_DEPLOYMENT_ALLOWED_USERS), github.actor) }}
env:
RENDER_DEPLOY_HOOK_URL_PROD: ${{ secrets.RENDER_DEPLOY_HOOK_URL_PROD }}
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/deploy-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ on:
types:
- completed

concurrency:
group: deploy-staging-${{ github.event.workflow_run.head_branch }}
cancel-in-progress: false

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' }}
permissions:
contents: write
env:
RENDER_DEPLOY_HOOK_URL_DEV: ${{ secrets.RENDER_DEPLOY_HOOK_URL_DEV }}
steps:
Expand All @@ -21,6 +27,54 @@ jobs:
exit 1
fi

- name: Checkout dev
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: dev
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: Pull latest dev
run: git pull --rebase origin dev
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated

- name: Bump patch version
run: |
python3 - <<'EOF'
import re

with open("pyproject.toml") as f:
content = f.read()

match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', content, re.MULTILINE)
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
major, minor, patch = int(match.group(1)), int(match.group(2)), int(match.group(3))
new_version = f"{major}.{minor}.{patch + 1}"

new_content = re.sub(
r'^version = "\d+\.\d+\.\d+"',
f'version = "{new_version}"',
content,
count=1,
flags=re.MULTILINE,
)

with open("pyproject.toml", "w") as f:
f.write(new_content)

print(f"Bumped: {major}.{minor}.{patch} -> {new_version}")
EOF

- name: Commit and push
run: |
git add pyproject.toml
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated
git diff --cached --quiet && exit 0
git commit -m "chore: bump patch version [skip ci]"
Comment thread
aditeyabaral marked this conversation as resolved.
git push origin dev
Comment thread
aditeyabaral marked this conversation as resolved.
Outdated

- name: Deploy to Staging Environment
Comment thread
aditeyabaral marked this conversation as resolved.
run: |
echo "🚀 Deploying to Staging..."
Expand Down
Loading