mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-03-20 08:59:45 +08:00
186 lines
5.4 KiB
YAML
186 lines
5.4 KiB
YAML
name: CI Workflow
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "*" # 所有分支触发
|
|
tags:
|
|
- 'v*'
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
VERSION_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
|
|
LATEST_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:latest
|
|
STABLE_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:stable
|
|
|
|
permissions:
|
|
contents: write
|
|
id-token: write
|
|
|
|
jobs:
|
|
# Job 构建和测试镜像
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
submodules: true
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build Docker images (multi-platform)
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
context: .
|
|
push: false
|
|
outputs: type=local,dest=./output
|
|
tags: ${{ env.VERSION_TAG }}
|
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
|
|
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache,mode=max
|
|
|
|
- name: Package Docker images
|
|
run: |
|
|
cd output
|
|
for platform in linux_amd64 linux_arm64 linux_arm_v7; do
|
|
platform_name=$(echo $platform | sed 's/_/-/g')
|
|
if [ -d "$platform" ]; then
|
|
tar -czf ../xiaomusic-${{ github.ref_name }}-${platform_name#linux-}.tar.gz -C $platform .
|
|
fi
|
|
done
|
|
cd ..
|
|
|
|
- name: Upload Docker images as artifacts
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: docker-images
|
|
path: xiaomusic-*.tar.gz
|
|
retention-days: 1
|
|
|
|
# Job 推送 Docker 镜像
|
|
push-docker:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Publish to Docker Hub main
|
|
if: github.ref_name == 'main'
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
context: .
|
|
push: true
|
|
tags: ${{ env.VERSION_TAG }}
|
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
|
|
|
|
- name: Publish to Docker Hub latest and stable
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
context: .
|
|
push: true
|
|
tags: ${{ env.VERSION_TAG }}, ${{ env.LATEST_TAG }}, ${{ env.STABLE_TAG }}
|
|
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
|
|
|
|
# Job 发布 Release
|
|
publish-release:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: docker-images
|
|
|
|
- name: Install GitHub CLI
|
|
run: |
|
|
sudo apt update
|
|
sudo apt install -y gh
|
|
|
|
- name: Create or update Release tag
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
RELEASE_NAME=${{ github.ref_name }}
|
|
RELEASE_BODY="This release is automatically updated from the ${RELEASE_NAME} branch."
|
|
|
|
EXISTING_RELEASE=$(gh release view "${RELEASE_NAME}" --json id --jq .id || echo "")
|
|
|
|
if [[ -n "${EXISTING_RELEASE}" ]]; then
|
|
echo "release exist"
|
|
else
|
|
gh release create "${RELEASE_NAME}" \
|
|
--prerelease=false \
|
|
--title "${RELEASE_NAME}" \
|
|
--notes "${RELEASE_BODY}"
|
|
fi
|
|
|
|
- name: Upload assets to Release tag
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
RELEASE_NAME=${{ github.ref_name }}
|
|
|
|
FILES=$(find . -type f -name "xiaomusic-*.tar.gz")
|
|
for FILE in ${FILES}; do
|
|
echo "type upload ${FILE}"
|
|
gh release upload "${RELEASE_NAME}" "${FILE}" --clobber
|
|
done
|
|
|
|
# Job 发布 PyPI 版本
|
|
publish-pypi:
|
|
runs-on: ubuntu-latest
|
|
needs: build
|
|
if: startsWith(github.ref, 'refs/tags/v')
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
submodules: true
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
registry-url: https://registry.npmjs.org/
|
|
node-version: lts/*
|
|
|
|
- name: Generate changelog
|
|
run: npx changelogithub
|
|
continue-on-error: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- uses: pdm-project/setup-pdm@v3
|
|
|
|
- name: Publish package distributions to PyPI
|
|
run: pdm publish
|
|
continue-on-error: true
|