Skip to content

Merge pull request #25 from bcgov/dependabot/github_actions/all-actio… #4

Merge pull request #25 from bcgov/dependabot/github_actions/all-actio…

Merge pull request #25 from bcgov/dependabot/github_actions/all-actio… #4

Workflow file for this run

name: Publish Web
on:
push:
branches:
- main
paths:
- 'web/**'
- 'docker/web/**'
- 'docker/nginx-runtime/**'
- 'docker/vue-on-nginx/**'
- '.github/workflows/publish-web.yml'
workflow_dispatch:
env:
WEB_IMAGE_NAME: web
WEB_RUNTIME_IMAGE_NAME: web-runtime
WEB_ARTIFACTS_IMAGE_NAME: web-artifacts
GITHUB_IMAGE_REPO: ghcr.io/bcgov/unified-scheduling
WEB_BASE_HREF: /unified-scheduling/
permissions:
id-token: write
packages: write
jobs:
build:
name: Build and Push Web Image
runs-on: ubuntu-latest
outputs:
short_sha: ${{ steps.short_sha.outputs.SHORT_SHA }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Log in to the GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short SHA
id: short_sha
run: |
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
driver: docker
- name: Setup Web Image Metadata
id: meta
uses: docker/metadata-action@v6
with:
images: |
${{ env.GITHUB_IMAGE_REPO }}/${{ env.WEB_IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.short_sha.outputs.SHORT_SHA }}
- name: Build and Push Web Image
uses: docker/build-push-action@v7
with:
push: true
context: .
file: ./docker/web/Dockerfile.release
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
NODE_VERSION=22
WEB_BASE_HREF=${{ env.WEB_BASE_HREF }}
NGINX_RUNTIME_SRC=./docker/nginx-runtime
VUE_ON_NGINX_SRC=./docker/vue-on-nginx
WEB_SRC=./web
update-gitops-dev:
name: Update GitOps Dev
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout GitOps repository
uses: actions/checkout@v6
with:
repository: bcgov-c/tenant-gitops-a94b15
ref: develop
token: ${{ secrets.GITOPS_DEPLOY_TOKEN }}
path: gitops
- name: Update Web image tag
working-directory: gitops/services/unified-scheduling
run: |
TAG="${{ needs.build.outputs.short_sha }}"
# Update kustomization.yaml with new Web image tag
sed -i "/name: unified-scheduling-web/,/newTag:/ s|newTag:.*|newTag: ${TAG}|" kustomization.yaml
echo "Updated Web image tag to: ${TAG}"
cat kustomization.yaml
- name: Commit and push changes
working-directory: gitops
run: |
git config user.name "GitHub Actions Bot"
git config user.email "actions@github.com"
git add services/unified-scheduling/kustomization.yaml
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "🚀 Deploy unified-scheduling Web to dev - SHA: ${{ needs.build.outputs.short_sha }}"
# Pull with rebase and retry push logic
max_retries=3
retry_count=0
while [ $retry_count -lt $max_retries ]; do
git pull --rebase origin develop
if git push origin develop; then
echo "GitOps repository updated successfully!"
break
else
retry_count=$((retry_count + 1))
echo "Push failed, retry $retry_count/$max_retries"
sleep 2
fi
if [ $retry_count -eq $max_retries ]; then
echo "Failed to push after $max_retries attempts"
exit 1
fi
done
fi