Update ci.yml

This commit is contained in:
涵曦 2024-10-30 09:19:41 +08:00 committed by GitHub
parent b49e250488
commit 6995afed16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,21 +1,21 @@
name: ci name: ci
on: on:
push: push:
branches: branches:
- "*" - "*"
workflow_dispatch: workflow_dispatch:
env: env:
TEST_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }} TEST_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
jobs: jobs:
build-image: build-and-test:
runs-on: ubuntu-latest runs-on: ubuntu-latest
# run unless event type is pull_request
if: github.event_name != 'pull_request' if: github.event_name != 'pull_request'
strategy:
matrix:
platform: [linux/amd64, linux/arm64, linux/arm/v7]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
@ -28,49 +28,30 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }} username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} password: ${{ secrets.DOCKERHUB_TOKEN }}
# We have to build each platform separately because when using multi-arch - name: Build Docker image
# builds, only one platform is being loaded into the cache. This would
# prevent us from testing the other platforms.
- name: Build Docker image (linux/amd64)
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
platforms: linux/amd64 platforms: ${{ matrix.platform }}
context: . context: .
push: false push: false
load: true load: true
tags: ${{ env.TEST_TAG }}-linux-amd64 tags: ${{ env.TEST_TAG }}-${{ matrix.platform | replace('/', '-') }}
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Build Docker image (linux/arm64) - name: Test Docker image
uses: docker/build-push-action@v6 run: docker run --rm ${{ env.TEST_TAG }}-${{ matrix.platform | replace('/', '-') }} -h
publish:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with: with:
platforms: linux/arm64 username: ${{ secrets.DOCKERHUB_USERNAME }}
context: . password: ${{ secrets.DOCKERHUB_TOKEN }}
push: false
load: true
tags: ${{ env.TEST_TAG }}-linux-arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Build Docker image (linux/arm/v7)
uses: docker/build-push-action@v6
with:
platforms: linux/arm/v7
context: .
push: false
load: true
tags: ${{ env.TEST_TAG }}-linux-arm-v7
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# We test all the images on amd64 host here. This uses QEMU to emulate
# the other platforms.
- run: docker run --rm ${TEST_TAG}-linux-amd64 -h
- run: docker run --rm ${TEST_TAG}-linux-arm64 -h
- run: docker run --rm ${TEST_TAG}-linux-arm-v7 -h
# This will only push the previously built images.
- name: Publish to Docker Hub - name: Publish to Docker Hub
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with: