Skip to content

feat: 千人千面定价变更站内通知与历史 #20

feat: 千人千面定价变更站内通知与历史

feat: 千人千面定价变更站内通知与历史 #20

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main
tags:
- 'v*'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.check.outputs.should_build }}
steps:
- uses: actions/checkout@v4
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/')
with:
fetch-depth: 0
- name: Check if commit has release tag
id: check
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == refs/heads/* ]] && git tag --points-at HEAD | grep -q '^v'; then
echo "should_build=false" >> $GITHUB_OUTPUT
echo "::notice::Skipping beta build: commit already has a release tag"
else
echo "should_build=true" >> $GITHUB_OUTPUT
fi
build:
needs: pre-check
if: needs.pre-check.outputs.should_build == 'true'
runs-on: ${{ matrix.runner }}
outputs:
version: ${{ steps.version.outputs.version }}
is_beta: ${{ steps.version.outputs.is_beta }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-22.04-arm
arch: arm64
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Determine version
id: version
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
echo "is_beta=false" >> $GITHUB_OUTPUT
else
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-6)
echo "version=beta-${SHORT_SHA}" >> $GITHUB_OUTPUT
echo "is_beta=true" >> $GITHUB_OUTPUT
fi
- name: Write VERSION file
run: echo "${{ steps.version.outputs.version }}" > VERSION
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: true
provenance: false
cache-from: type=gha,scope=build-${{ matrix.arch }}
cache-to: type=gha,scope=build-${{ matrix.arch }},mode=max
tags: ghcr.io/${{ github.repository_owner }}/longjin-api:${{ steps.version.outputs.version }}-${{ matrix.arch }}
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
manifest:
needs: build
runs-on: ubuntu-latest
steps:
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Create and push multi-arch manifest
run: |
VERSION="${{ needs.build.outputs.version }}"
IS_BETA="${{ needs.build.outputs.is_beta }}"
IMAGE="ghcr.io/${{ github.repository_owner }}/longjin-api"
docker manifest create ${IMAGE}:${VERSION} \
${IMAGE}:${VERSION}-amd64 \
${IMAGE}:${VERSION}-arm64
docker manifest push ${IMAGE}:${VERSION}
if [ "${IS_BETA}" = "true" ]; then
ALIAS="beta"
else
ALIAS="latest"
fi
docker manifest create ${IMAGE}:${ALIAS} \
${IMAGE}:${VERSION}-amd64 \
${IMAGE}:${VERSION}-arm64
docker manifest push ${IMAGE}:${ALIAS}