Skip to content

chore(deps): bump the all-actions group across 1 directory with 3 updates #236

chore(deps): bump the all-actions group across 1 directory with 3 updates

chore(deps): bump the all-actions group across 1 directory with 3 updates #236

name: Build k8s-service
on:
push:
branches: [ main, dev ]
paths:
- "k8s-service/**"
- ".github/workflows/k8s-service-build.yml"
- ".github/workflows/k8s-service-deploy.yml"
pull_request:
branches: [ main, dev ]
paths:
- "k8s-service/**"
- ".github/workflows/k8s-service-build.yml"
- ".github/workflows/k8s-service-deploy.yml"
types: [ opened, synchronize, reopened ]
workflow_dispatch:
inputs:
environment:
description: "Environment to deploy to"
required: true
default: "dev"
type: choice
options:
- dev
- prod
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-k8s-service
jobs:
build:
# Only run on pull requests that are cross-branch or on direct pushes
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
github.head_ref != 'dev' &&
github.event.pull_request.base.ref != github.event.pull_request.head.ref)
runs-on: blacksmith-4vcpu-ubuntu-2404
strategy:
matrix:
platform: [ linux/amd64 ]
permissions:
contents: read
packages: write
outputs:
image_tag: ${{ steps.image-tag.outputs.image_tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup Blacksmith Builder
uses: useblacksmith/setup-docker-builder@v1
- name: Sanitize branch names
id: sanitize-branch
run: |
RAW_REF="${{ github.head_ref || github.ref_name }}"
SANITIZED=$(echo "$RAW_REF" | tr '[:upper:]' '[:lower:]' | sed 's#[^a-z0-9._-]#-#g' | sed 's/--*/-/g' | sed 's/^-\|-$//g')
echo "name=$SANITIZED" >> $GITHUB_OUTPUT
- name: Log in to Container Registry
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image tag
id: image-tag
run: |
IMAGE_TAG="build-${{ github.run_number }}-${{ github.run_attempt }}"
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "Image tag: $IMAGE_TAG"
- name: Build image (PR - no push)
if: github.event_name == 'pull_request'
uses: useblacksmith/build-push-action@v2
with:
context: ./k8s-service
file: ./k8s-service/Dockerfile
platforms: ${{ matrix.platform }}
push: false
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.image-tag.outputs.image_tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sanitize-branch.outputs.name }}
- name: Build and push Docker image
if: github.event_name != 'pull_request'
uses: useblacksmith/build-push-action@v2
with:
context: ./k8s-service
file: ./k8s-service/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.image-tag.outputs.image_tag }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sanitize-branch.outputs.name }}
- name: Output image details
run: |
if [ "${{ github.event_name }}" != "pull_request" ]; then
echo "## ✅ k8s-service Image Built and Pushed" >> $GITHUB_STEP_SUMMARY
else
echo "## 🔨 k8s-service Image Built (Not Pushed)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "**Image Tag:** ${{ steps.image-tag.outputs.image_tag }}" >> $GITHUB_STEP_SUMMARY
echo "**Event:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
deploy:
needs: build
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: ./.github/workflows/k8s-service-deploy.yml
with:
environment: ${{ github.event_name == 'workflow_dispatch' && inputs.environment || (github.ref_name == 'main' && 'prod' || 'dev') }}
image_tag: build-${{ github.run_number }}-${{ github.run_attempt }}
secrets: inherit