1
0
mirror of https://github.com/hanxi/xiaomusic.git synced 2025-12-06 14:52:50 +08:00

ci: 调试

This commit is contained in:
涵曦
2024-12-17 14:47:43 +08:00
parent 9bae1397ba
commit b32aca16bc

View File

@@ -13,6 +13,7 @@ env:
permissions:
contents: write
id-token: write
jobs:
# Job 构建镜像
@@ -21,14 +22,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: |
/tmp/.buildx-cache
/tmp/.buildx-cache-new
key: ${{ runner.os }}-buildx-${{ github.sha }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
@@ -77,117 +70,94 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Job 测试镜像
test:
runs-on: ubuntu-latest
needs: build # 依赖构建完成
steps:
- name: Cache Docker layers for testing
uses: actions/cache@v4
with:
path: |
/tmp/.buildx-cache
/tmp/.buildx-cache-new
key: ${{ runner.os }}-buildx-${{ github.sha }}
- name: List Docker images
run: docker images
- name: Test amd64 image
run: |
echo ${{ env.TEST_TAG }}-linux-amd64 | docker load
docker run --rm ${{ env.TEST_TAG }}-linux-amd64 /app/.venv/bin/python3 /app/xiaomusic.py -h
- name: Test arm64 image
run: |
echo ${{ env.TEST_TAG }}-linux-arm64 | docker load
docker run --rm ${{ env.TEST_TAG }}-linux-arm64 /app/.venv/bin/python3 /app/xiaomusic.py -h
- name: Test armv7 image
run: |
echo ${{ env.TEST_TAG }}-linux-arm-v7 | docker load
docker run --rm ${{ env.TEST_TAG }}-linux-arm-v7 /app/.venv/bin/python3 /app/xiaomusic.py -h
# 发布版本
pypi-publish:
name: upload release to PyPI
# 仅在 ref 为以 v 开头的标签时执行
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: test # 依赖测试完成
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Docker Hub Description
if: github.ref == 'refs/heads/main'
uses: peter-evans/dockerhub-description@v4
with:
fetch-depth: 0
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
# Job 打包应用, 发布镜像和 Release
package:
runs-on: ubuntu-latest
# 仅在 main 分支或以 v 开头的标签运行
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
needs: test # 依赖测试完成
steps:
- name: Cache Docker layers for packaging
uses: actions/cache@v4
with:
path: |
/tmp/.buildx-cache
/tmp/.buildx-cache-new
key: ${{ runner.os }}-buildx-${{ github.sha }}
# Job 打包应用, 发布镜像和 Release
# 仅在 main 分支或以 v 开头的标签运行
- name: Package /app for amd64
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
run: |
echo ${{ env.TEST_TAG }}-linux-amd64 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-amd64 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: |
echo ${{ env.TEST_TAG }}-linux-amd64 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-amd64 bash -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: |
echo ${{ env.TEST_TAG }}-linux-arm64 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm64 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: |
echo ${{ env.TEST_TAG }}-linux-arm64 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm64 bash -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: |
echo ${{ env.TEST_TAG }}-linux-arm-v7 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm-v7 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: |
echo ${{ env.TEST_TAG }}-linux-arm-v7 | docker load
docker run --rm -v $PWD:/workspace ${{ env.TEST_TAG }}-linux-arm-v7 bash -c \
"cd /app && tar --exclude='ffmpeg' -czf /workspace/app-arm-v7-lite.tar.gz .[!.]* *"
- name: Publish to Docker Hub
- name: Publish to Docker Hub main
if: github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
@@ -197,9 +167,9 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache-new
cache-to: type=local,dest=/tmp/.buildx-cache-new
# 额外步骤以处理标签
- name: Push latest and stable tags if current ref is a tag with 'v' prefix
if: startsWith(github.ref, 'refs/tags/v') # 仅在 ref 为以 v 开头的标签时执行
# 仅在 ref 为以 v 开头的标签时执行
- name: Publish to Docker Hub latest and stable
if: startsWith(github.ref, 'refs/tags/v')
run: |
# Define the commands to push latest and stable tags
echo "Pushing latest and stable tags..."
@@ -208,24 +178,20 @@ jobs:
docker push ${{ env.LATEST_TAG }}
docker push ${{ env.STABLE_TAG }}
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: hanxi/xiaomusic
- name: Move cache to limit growth
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
# 上传文件到 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
- name: Create or update Release
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |