mirror of
https://github.com/hanxi/xiaomusic.git
synced 2026-03-15 08:13:16 +08:00
update ci
This commit is contained in:
227
.github/workflows/ci.yml
vendored
227
.github/workflows/ci.yml
vendored
@@ -9,7 +9,7 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
TEST_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
|
||||
VERSION_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}
|
||||
LATEST_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:latest
|
||||
STABLE_TAG: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:stable
|
||||
|
||||
@@ -18,7 +18,7 @@ permissions:
|
||||
id-token: write
|
||||
|
||||
jobs:
|
||||
# Job 构建镜像
|
||||
# Job 构建和测试镜像
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -39,138 +39,65 @@ jobs:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build Docker image (linux/amd64)
|
||||
id: build_amd64
|
||||
- name: Build Docker images (multi-platform)
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
platforms: linux/amd64
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
context: .
|
||||
push: false
|
||||
load: true
|
||||
tags: ${{ env.TEST_TAG }}-linux-amd64
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
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: Build Docker image (linux/arm64)
|
||||
id: build_arm64
|
||||
uses: docker/build-push-action@v6
|
||||
- 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:
|
||||
platforms: linux/arm64
|
||||
context: .
|
||||
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: docker-images
|
||||
path: xiaomusic-*.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
- name: Build Docker image (linux/arm/v7)
|
||||
id: build_armv7
|
||||
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
|
||||
# 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: List Docker images
|
||||
run: docker images
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Test amd64 image
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh ${{ env.TEST_TAG }}-linux-amd64 -c "/app/.venv/bin/python3 /app/xiaomusic.py -h"
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Test arm64 image
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh ${{ env.TEST_TAG }}-linux-arm64 -c "/app/.venv/bin/python3 /app/xiaomusic.py -h"
|
||||
|
||||
- name: Test armv7 image
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh ${{ env.TEST_TAG }}-linux-arm-v7 -c "/app/.venv/bin/python3 /app/xiaomusic.py -h"
|
||||
|
||||
- name: Docker Hub Description
|
||||
if: github.ref == 'refs/heads/main'
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
repository: hanxi/xiaomusic
|
||||
|
||||
# 发布 PyPI 版本
|
||||
# 仅在 ref 为以 v 开头的标签时执行
|
||||
- uses: actions/setup-node@v4
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
with:
|
||||
registry-url: https://registry.npmjs.org/
|
||||
node-version: lts/*
|
||||
|
||||
- run: npx changelogithub
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
continue-on-error: true
|
||||
env:
|
||||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
||||
|
||||
- uses: pdm-project/setup-pdm@v3
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
|
||||
- name: Publish package distributions to PyPI
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
run: pdm publish
|
||||
continue-on-error: true
|
||||
|
||||
|
||||
# Job 打包应用, 发布镜像和 Release
|
||||
# 仅在 main 分支或以 v 开头的标签运行
|
||||
- name: Package /app for amd64
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-amd64 -c \
|
||||
"tar czf /workspace/app-amd64.tar.gz -C / app"
|
||||
|
||||
- name: Package /app (lite) for amd64
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-amd64 -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-amd64-lite.tar.gz .[!.]* *"
|
||||
|
||||
- name: Package /app for arm64
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm64 -c \
|
||||
"tar czf /workspace/app-arm64.tar.gz -C / app"
|
||||
|
||||
- name: Package /app (lite) for arm64
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm64 -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm64-lite.tar.gz .[!.]* *"
|
||||
|
||||
- name: Package /app for arm/v7
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm-v7 -c \
|
||||
"tar czf /workspace/app-arm-v7.tar.gz -C / app"
|
||||
|
||||
- name: Package /app (lite) for arm/v7
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
docker run --rm --entrypoint /bin/sh -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm-v7 -c \
|
||||
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm-v7-lite.tar.gz .[!.]* *"
|
||||
|
||||
- name: Publish to Docker Hub main
|
||||
if: github.ref == 'refs/heads/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.TEST_TAG }}
|
||||
cache-from: type=local,src=/tmp/.buildx-cache-new
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
tags: ${{ env.VERSION_TAG }}
|
||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
|
||||
|
||||
# 仅在 ref 为以 v 开头的标签时执行
|
||||
- name: Publish to Docker Hub latest and stable
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: docker/build-push-action@v6
|
||||
@@ -178,38 +105,40 @@ jobs:
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ env.TEST_TAG }}, ${{ env.LATEST_TAG }}, ${{ env.STABLE_TAG }}
|
||||
cache-from: type=local,src=/tmp/.buildx-cache-new
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
tags: ${{ env.VERSION_TAG }}, ${{ env.LATEST_TAG }}, ${{ env.STABLE_TAG }}
|
||||
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:buildcache
|
||||
|
||||
- name: Move cache to limit growth
|
||||
run: |
|
||||
rm -rf /tmp/.buildx-cache
|
||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
||||
# 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
|
||||
|
||||
# 上传文件到 release 页面
|
||||
- name: Install GitHub CLI
|
||||
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y gh
|
||||
|
||||
# 创建或更新 Release
|
||||
- name: Create or update Release main
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref_name == 'main'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
RELEASE_NAME=test
|
||||
RELEASE_BODY="This release is automatically updated from the main branch."
|
||||
|
||||
# 检查是否已有同名 Release
|
||||
EXISTING_RELEASE=$(gh release view "${RELEASE_NAME}" --json id --jq .id || echo "")
|
||||
|
||||
if [[ -n "${EXISTING_RELEASE}" ]]; then
|
||||
echo "release exist"
|
||||
else
|
||||
# 创建新的 Release
|
||||
gh release create "${RELEASE_NAME}" \
|
||||
--prerelease=false \
|
||||
--title "${RELEASE_NAME}" \
|
||||
@@ -219,34 +148,30 @@ jobs:
|
||||
- name: Create or update Release tag
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
RELEASE_NAME=${{ github.ref_name }}
|
||||
RELEASE_BODY="This release is automatically updated from the ${RELEASE_NAME} branch."
|
||||
|
||||
# 检查是否已有同名 Release
|
||||
EXISTING_RELEASE=$(gh release view "${RELEASE_NAME}" --json id --jq .id || echo "")
|
||||
|
||||
if [[ -n "${EXISTING_RELEASE}" ]]; then
|
||||
echo "release exist"
|
||||
else
|
||||
# 创建新的 Release
|
||||
gh release create "${RELEASE_NAME}" \
|
||||
--prerelease=false \
|
||||
--title "${RELEASE_NAME}" \
|
||||
--notes "${RELEASE_BODY}"
|
||||
fi
|
||||
|
||||
|
||||
# 上传多个文件并覆盖
|
||||
- name: Upload assets to Release main
|
||||
if: github.ref == 'refs/heads/main'
|
||||
if: github.ref_name == 'main'
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
RELEASE_NAME=test
|
||||
|
||||
FILES=$(find . -type f -name "app-*.tar.gz")
|
||||
FILES=$(find . -type f -name "xiaomusic-*.tar.gz")
|
||||
for FILE in ${FILES}; do
|
||||
echo "type upload ${FILE}"
|
||||
gh release upload "${RELEASE_NAME}" "${FILE}" --clobber
|
||||
@@ -255,12 +180,40 @@ jobs:
|
||||
- name: Upload assets to Release tag
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 设置 GH_TOKEN 环境变量
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
RELEASE_NAME=${{ github.ref_name }}
|
||||
|
||||
FILES=$(find . -type f -name "app-*.tar.gz")
|
||||
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
|
||||
|
||||
23
.github/workflows/dockerhub-description.yml
vendored
Normal file
23
.github/workflows/dockerhub-description.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Update Docker Hub Description
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'README.md'
|
||||
- '.github/workflows/dockerhub-description.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
update-description:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
repository: hanxi/xiaomusic
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -172,3 +172,4 @@ tmp/
|
||||
xiaomusic.log.txt*
|
||||
node_modules
|
||||
reference/
|
||||
.aone_copilot/
|
||||
|
||||
Reference in New Issue
Block a user