mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-09-07 00:27:36 +08:00
fix: update Docker build workflow to streamline variable extraction and tag handling
This commit is contained in:
@@ -19,14 +19,12 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
packages: write
|
packages: write
|
||||||
|
|
||||||
outputs:
|
outputs:
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
version: ${{ steps.args.outputs.version }}
|
version: ${{ steps.vars.outputs.version }}
|
||||||
git_commit: ${{ steps.args.outputs.git_commit }}
|
git_commit: ${{ steps.vars.outputs.git_commit }}
|
||||||
build_time: ${{ steps.args.outputs.build_time }}
|
build_time: ${{ steps.vars.outputs.build_time }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -42,11 +40,13 @@ jobs:
|
|||||||
type=sha
|
type=sha
|
||||||
type=raw,value=latest
|
type=raw,value=latest
|
||||||
|
|
||||||
- name: Extract Dockerfile args
|
- name: Extract Build Vars
|
||||||
id: args
|
id: vars
|
||||||
run: |
|
run: |
|
||||||
|
VERSION=${GITHUB_REF#refs/tags/v}
|
||||||
|
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||||
echo "git_commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
echo "git_commit=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
||||||
echo "build_time=$(git show -s --format=%cI)" >> "$GITHUB_OUTPUT"
|
echo "build_time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
build:
|
build:
|
||||||
needs: prepare
|
needs: prepare
|
||||||
@@ -58,7 +58,6 @@ jobs:
|
|||||||
arch: [amd64, arm64]
|
arch: [amd64, arm64]
|
||||||
type: [default, micro, pico]
|
type: [default, micro, pico]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
|
||||||
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
|
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'ubuntu-24.04-arm' }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
@@ -80,32 +79,22 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [ "${{ matrix.type }}" == "default" ]; then
|
if [ "${{ matrix.type }}" == "default" ]; then
|
||||||
echo "DOCKERFILE=./Dockerfile" >> "$GITHUB_OUTPUT"
|
echo "DOCKERFILE=./Dockerfile" >> "$GITHUB_OUTPUT"
|
||||||
elif [ "${{ matrix.type }}" == "micro" ]; then
|
|
||||||
echo "DOCKERFILE=./Dockerfile.micro" >> "$GITHUB_OUTPUT"
|
|
||||||
else
|
else
|
||||||
echo "DOCKERFILE=./Dockerfile.pico" >> "$GITHUB_OUTPUT"
|
echo "DOCKERFILE=./Dockerfile.${{ matrix.type }}" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Set image tags
|
|
||||||
id: tags
|
|
||||||
run: |
|
|
||||||
if [ "${{ matrix.type }}" == "default" ]; then
|
|
||||||
TAGS=$(echo "${{ needs.prepare.outputs.tags }}" | tr '\n' ' ')
|
|
||||||
elif [ "${{ matrix.type }}" == "micro" ]; then
|
|
||||||
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:micro-${{ needs.prepare.outputs.version }}"
|
|
||||||
else
|
|
||||||
TAGS="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-latest ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pico-${{ needs.prepare.outputs.version }}"
|
|
||||||
fi
|
|
||||||
echo "TAGS=$TAGS" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ${{ steps.dockerfile.outputs.DOCKERFILE }}
|
file: ${{ steps.dockerfile.outputs.DOCKERFILE }}
|
||||||
platforms: ${{ matrix.arch == 'amd64' && 'linux/amd64' || 'linux/arm64' }}
|
platforms: ${{ matrix.arch == 'amd64' && 'linux/amd64' || 'linux/arm64' }}
|
||||||
push: ${{ github.event_name != 'pull_request' }}
|
push: true
|
||||||
tags: ${{ steps.tags.outputs.TAGS }}
|
tags: |
|
||||||
|
${{ matrix.type == 'default' && needs.prepare.outputs.tags || '' }}
|
||||||
|
${{ matrix.type != 'default' && format('{0}/{1}:{2}', env.REGISTRY, env.IMAGE_NAME, matrix.type) || '' }}
|
||||||
|
${{ matrix.type != 'default' && format('{0}/{1}:{2}-latest', env.REGISTRY, env.IMAGE_NAME, matrix.type) || '' }}
|
||||||
|
${{ matrix.type != 'default' && format('{0}/{1}:{2}-{3}', env.REGISTRY, env.IMAGE_NAME, matrix.type, needs.prepare.outputs.version) || '' }}
|
||||||
labels: ${{ needs.prepare.outputs.labels }}
|
labels: ${{ needs.prepare.outputs.labels }}
|
||||||
cache-from: |
|
cache-from: |
|
||||||
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.type }}-latest
|
type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.type }}-latest
|
||||||
|
|||||||
Reference in New Issue
Block a user