portal/.github/workflows/build-push-ghcr-image.yml
2026-04-02 18:08:43 +08:00

90 lines
2.7 KiB
YAML

name: Build And Push GHCR Image
on:
push:
branches:
- main
paths:
- '.github/workflows/build-push-ghcr-image.yml'
- 'Dockerfile'
- 'package.json'
- 'yarn.lock'
- 'scripts/github-actions/build-and-push-frontend-image.sh'
- 'scripts/github-actions/compute-frontend-release-metadata.sh'
- 'scripts/github-actions/render-frontend-build-args.sh'
- 'scripts/github-actions/prepare-frontend-build-context.sh'
- 'scripts/prebuild.sh'
- 'contentlayer.config.ts'
- 'next.config.js'
- 'next.config.mjs'
- 'src/**'
- 'public/**'
workflow_call:
inputs:
image_tag:
description: Optional image tag. Defaults to the current commit SHA.
required: false
type: string
push_latest:
description: Also publish the `latest` tag.
required: false
default: false
type: boolean
workflow_dispatch:
inputs:
image_tag:
description: Optional image tag. Defaults to the current commit SHA.
required: false
type: string
push_latest:
description: Also publish the `latest` tag.
required: false
default: false
type: boolean
permissions:
contents: read
packages: write
concurrency:
group: build-push-ghcr-image-console-${{ github.ref_name }}
cancel-in-progress: false
jobs:
build-and-push:
runs-on: ubuntu-latest
env:
PRIMARY_DOMAIN: console.svc.plus
NEXT_PUBLIC_RUNTIME_ENVIRONMENT: prod
NEXT_PUBLIC_RUNTIME_REGION: cn
steps:
- name: Check Out Repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
- name: Set Up Docker Buildx
run: |
docker buildx create --name console-builder --use >/dev/null 2>&1 || docker buildx use console-builder
docker buildx inspect --bootstrap
- name: Log In To GHCR
env:
GHCR_USERNAME: ${{ vars.GHCR_USERNAME || github.repository_owner }}
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN || github.token }}
run: |
echo "${GHCR_TOKEN}" | docker login ghcr.io -u "${GHCR_USERNAME}" --password-stdin
- name: Compute Image Metadata
id: metadata
env:
IMAGE_TAG_INPUT: ${{ inputs.image_tag }}
run: |
bash scripts/github-actions/compute-frontend-release-metadata.sh "${IMAGE_TAG_INPUT}"
- name: Publish Frontend Image
env:
IMAGE_REF: ${{ steps.metadata.outputs.image_ref }}
IMAGE_LATEST_REF: ${{ steps.metadata.outputs.image_latest_ref }}
PUSH_LATEST: ${{ inputs.push_latest }}
run: |
bash scripts/github-actions/build-and-push-frontend-image.sh