Skip to content

Deploy Staging Environment #4

Deploy Staging Environment

Deploy Staging Environment #4

name: Deploy Staging Environment
on:
workflow_run:
workflows: ["Build and Push Jenkins Image"]
types:
- completed
branches:
- main
jobs:
update-staging:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Update staging values
run: |
echo "Updating staging/values.yaml to use latest image tag"
# Determine registry based on repository
if [[ "${{ github.repository }}" == "lfit/jenkins-gitops" ]]; then
REGISTRY="ghcr.io/lfit/jenkins"
else
REGISTRY="ghcr.io/${{ github.repository_owner }}/jenkins"
fi
# Update repository but keep tag as "latest" for staging
sed -i "s|repository: \".*\"|repository: \"$REGISTRY\"|g" staging/values.yaml
sed -i "s|tag: \".*\"|tag: \"latest\"|g" staging/values.yaml
echo "Updated staging/values.yaml to use latest tag:"
cat staging/values.yaml
- name: Check if changes are needed
id: check-changes
run: |
if git diff --quiet staging/values.yaml; then
echo "No changes needed - staging already configured correctly"
echo "needs-update=false" >> $GITHUB_OUTPUT
else
echo "Changes detected - staging needs update"
echo "needs-update=true" >> $GITHUB_OUTPUT
fi
- name: Create pull request
if: steps.check-changes.outputs.needs-update == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: |
chore: ensure staging uses latest Jenkins image
Triggered by successful image build: ${{ github.event.workflow_run.head_sha }}
Staging intentionally uses 'latest' tag to test newest builds.
title: "chore: ensure staging uses latest Jenkins image"
body: |
## Automated staging configuration update
Ensures staging environment uses `latest` tag to test newest image builds.
**Triggered by:** ${{ github.event.workflow_run.html_url }}
**Strategy:** Staging uses `latest`, production uses stable tags
**Build SHA:** ${{ github.event.workflow_run.head_sha }}
branch: update-staging-latest
delete-branch: true