Skip to content

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

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 #657

Workflow file for this run

name: Build API
on:
push:
branches: [main, dev]
paths:
- "api/**"
- ".github/workflows/api-build.yml"
- ".github/workflows/api-deploy.yml"
pull_request:
branches: [main, dev]
paths:
- "api/**"
- ".github/workflows/api-build.yml"
- ".github/workflows/api-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 }}-api
jobs:
lint:
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-2vcpu-ubuntu-2404
permissions:
contents: read
actions: write
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Setup pnpm
uses: pnpm/action-setup@v6
with:
version: 10
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 25
cache: "pnpm"
cache-dependency-path: api/pnpm-lock.yaml
- name: Install dependencies
working-directory: ./api
run: pnpm install --frozen-lockfile
- name: Lint code
working-directory: ./api
run: |
pnpm lint
git diff --exit-code ..
- name: Cancel workflow on failure
if: failure()
run: gh run cancel ${{ github.run_id }}
env:
GH_TOKEN: ${{ github.token }}
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
actions: 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: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr,prefix=pr-
type=raw,value=build-${{ github.run_number }}-${{ github.run_attempt }}
- 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: ./api
file: ./api/Dockerfile
platforms: ${{ matrix.platform }}
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image
if: github.event_name != 'pull_request'
uses: useblacksmith/build-push-action@v2
with:
context: ./api
file: ./api/Dockerfile
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Output image details
run: |
if [ "${{ github.event_name }}" != "pull_request" ]; then
echo "## ✅ API Image Built and Pushed" >> $GITHUB_STEP_SUMMARY
else
echo "## 🔨 API Image Built (Not Pushed)" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "**Tags:** ${{ steps.meta.outputs.tags }}" >> $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
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "ℹ️ **Note:** Image was built for testing but not pushed to registry (only pushes on direct commits to main/dev)" >> $GITHUB_STEP_SUMMARY
fi
- name: Cancel workflow on failure
if: failure()
run: gh run cancel ${{ github.run_id }}
env:
GH_TOKEN: ${{ github.token }}
# Deploy job - only runs on push events or manual dispatch
deploy:
needs: [lint, build]
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: ./.github/workflows/api-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