Optimize CI

This commit is contained in:
ryan
2026-06-20 13:53:54 +08:00
parent ef5d5b46af
commit 6e6bce6a03
+22 -15
View File
@@ -16,6 +16,10 @@ permissions:
attestations: write attestations: write
id-token: write id-token: write
env:
IMAGE_NAME: wavelet
DOCKERFILE: docker/Dockerfile
jobs: jobs:
build: build:
name: Build (${{ matrix.arch }}) name: Build (${{ matrix.arch }})
@@ -46,7 +50,8 @@ jobs:
POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)"
INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}" INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}"
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" OWNER="${GITHUB_REPOSITORY_OWNER,,}"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME}" VERSION="${GITHUB_REF_NAME}"
elif [[ -n "$INPUT_VERSION" ]]; then elif [[ -n "$INPUT_VERSION" ]]; then
@@ -76,28 +81,27 @@ jobs:
uses: docker/build-push-action@v7 uses: docker/build-push-action@v7
with: with:
context: . context: .
file: ./docker/Dockerfile file: ${{ env.DOCKERFILE }}
platforms: ${{ matrix.platform }} platforms: ${{ matrix.platform }}
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
build-args: | build-args: |
VERSION=${{ env.VERSION }} VERSION=${{ env.VERSION }}
BUILD_DATE=${{ env.BUILD_DATE }} cache-from: type=gha,scope=docker-${{ env.IMAGE_NAME }}-${{ matrix.arch }}
cache-from: type=gha,scope=docker-server-${{ matrix.arch }} cache-to: type=gha,mode=max,ignore-error=true,timeout=20m,scope=docker-${{ env.IMAGE_NAME }}-${{ matrix.arch }}
cache-to: type=gha,mode=max,ignore-error=true,timeout=20m,scope=docker-server-${{ matrix.arch }}
- name: Export digest - name: Export digest
shell: bash shell: bash
run: | run: |
mkdir -p /tmp/server-digests mkdir -p "/tmp/${{ env.IMAGE_NAME }}-digests"
touch "/tmp/server-digests/${DIGEST#sha256:}" touch "/tmp/${{ env.IMAGE_NAME }}-digests/${DIGEST#sha256:}"
env: env:
DIGEST: ${{ steps.build.outputs.digest }} DIGEST: ${{ steps.build.outputs.digest }}
- name: Upload digest - name: Upload digest
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: server-digests-${{ matrix.arch }} name: ${{ env.IMAGE_NAME }}-digests-${{ matrix.arch }}
path: /tmp/server-digests/* path: /tmp/${{ env.IMAGE_NAME }}-digests/*
if-no-files-found: error if-no-files-found: error
retention-days: 1 retention-days: 1
@@ -128,7 +132,8 @@ jobs:
POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)" POINTED_TAG="$(git tag --points-at HEAD --list 'v*' | sort -V | tail -n1)"
INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}" INPUT_VERSION="${INPUT_VERSION//[[:space:]]/}"
echo "IMAGE=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV" OWNER="${GITHUB_REPOSITORY_OWNER,,}"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME}" VERSION="${GITHUB_REF_NAME}"
elif [[ -n "$INPUT_VERSION" ]]; then elif [[ -n "$INPUT_VERSION" ]]; then
@@ -145,8 +150,8 @@ jobs:
- name: Download digests - name: Download digests
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
with: with:
path: /tmp/server-digests path: /tmp/${{ env.IMAGE_NAME }}-digests
pattern: server-digests-* pattern: ${{ env.IMAGE_NAME }}-digests-*
merge-multiple: true merge-multiple: true
- name: Set up Docker Buildx - name: Set up Docker Buildx
@@ -160,7 +165,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifest list - name: Create and push manifest list
working-directory: /tmp/server-digests working-directory: /tmp/${{ env.IMAGE_NAME }}-digests
shell: bash shell: bash
run: | run: |
shopt -s nullglob shopt -s nullglob
@@ -170,7 +175,7 @@ jobs:
done done
if [ ${#references[@]} -eq 0 ]; then if [ ${#references[@]} -eq 0 ]; then
echo "No digests found in /tmp/server-digests" >&2 echo "No digests found in /tmp/${{ env.IMAGE_NAME }}-digests" >&2
exit 1 exit 1
fi fi
@@ -184,9 +189,11 @@ jobs:
-t "${IMAGE}:${VERSION}" \ -t "${IMAGE}:${VERSION}" \
-t "${IMAGE}:${FLOATING_TAG}" \ -t "${IMAGE}:${FLOATING_TAG}" \
"${references[@]}" "${references[@]}"
env:
IMAGE: ${{ env.IMAGE }}
- name: Inspect image - name: Inspect image
run: docker buildx imagetools inspect "${IMAGE}:${VERSION}" run: docker buildx imagetools inspect "${{ env.IMAGE }}:${{ env.VERSION }}"
- name: Trigger webhook - name: Trigger webhook
env: env: