Skip to content

Commit bd43eca

Browse files
committed
ci:docker tags
1 parent c504985 commit bd43eca

File tree

1 file changed

+40
-25
lines changed

1 file changed

+40
-25
lines changed

.github/workflows/build.yml

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
branches:
1919
- Alpha
2020
concurrency:
21-
group: ${{ github.workflow }}-${{ github.ref }}
21+
group: "${{ github.workflow }}-${{ github.ref }}"
2222
cancel-in-progress: true
2323

2424
env:
@@ -270,7 +270,7 @@ jobs:
270270
- name: Archive production artifacts
271271
uses: actions/upload-artifact@v4
272272
with:
273-
name: ${{ matrix.jobs.goos }}-${{ matrix.jobs.output }}
273+
name: "${{ matrix.jobs.goos }}-${{ matrix.jobs.output }}"
274274
path: |
275275
mihomo*.gz
276276
mihomo*.deb
@@ -415,35 +415,35 @@ jobs:
415415
uses: docker/setup-buildx-action@v3
416416
with:
417417
version: latest
418-
419-
- name: Set Docker tags and labels based on trigger
420-
id: set-meta
421-
run: |
422-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
423-
echo "tags=${{ github.event.inputs.version }}" >> $GITHUB_ENV
424-
echo "labels=org.opencontainers.image.version=${{ github.event.inputs.version }}" >> $GITHUB_ENV
425-
else
426-
echo "tags=${{ steps.meta.outputs.tags }}" >> $GITHUB_ENV
427-
echo "labels=${{ steps.meta.outputs.labels }}" >> $GITHUB_ENV
428-
fi
429-
430-
418+
431419
# Extract metadata (tags, labels) for Docker
432420
# https://github.com/docker/metadata-action
433421
- name: Extract Docker metadata
434-
id: meta
422+
if: ${{ github.event_name != 'workflow_dispatch' }}
423+
id: meta_alpha
435424
uses: docker/metadata-action@v5
436425
with:
437-
images: ${{ env.REGISTRY }}/${{ github.repository }}
438-
tags: ${{ env.tags }}
439-
labels: ${{ env.labels }}
440-
441-
426+
images: '${{ env.REGISTRY }}/${{ github.repository }}'
427+
428+
# Extract metadata (tags, labels) for Docker
429+
# https://github.com/docker/metadata-action
430+
- name: Extract Docker metadata
431+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }}
432+
id: meta_release
433+
uses: docker/metadata-action@v5
434+
with:
435+
images: '${{ env.REGISTRY }}/${{ github.repository }}'
436+
tags: |
437+
${{ github.event.inputs.version }}
438+
flavor: |
439+
latest=true
440+
labels: org.opencontainers.image.version=${{ github.event.inputs.version }}
441+
442442
- name: Show files
443443
run: |
444444
ls .
445445
ls bin/
446-
446+
447447
- name: login to docker REGISTRY
448448
uses: docker/login-action@v3
449449
with:
@@ -454,7 +454,22 @@ jobs:
454454
# Build and push Docker image with Buildx (don't push on PR)
455455
# https://github.com/docker/build-push-action
456456
- name: Build and push Docker image
457-
id: build-and-push
457+
if: ${{ github.event_name != 'workflow_dispatch' }}
458+
uses: docker/build-push-action@v5
459+
with:
460+
context: .
461+
file: ./Dockerfile
462+
push: ${{ github.event_name != 'pull_request' }}
463+
platforms: |
464+
linux/386
465+
linux/amd64
466+
linux/arm64
467+
linux/arm/v7
468+
tags: ${{ steps.meta_alpha.outputs.tags }}
469+
labels: ${{ steps.meta_alpha.outputs.labels }}
470+
471+
- name: Build and push Docker image
472+
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version != '' }}
458473
uses: docker/build-push-action@v5
459474
with:
460475
context: .
@@ -465,5 +480,5 @@ jobs:
465480
linux/amd64
466481
linux/arm64
467482
linux/arm/v7
468-
tags: ${{ steps.meta.outputs.tags }}
469-
labels: ${{ steps.meta.outputs.labels }}
483+
tags: ${{ steps.meta_release.outputs.tags }}
484+
labels: ${{ steps.meta_release.outputs.labels }}

0 commit comments

Comments
 (0)