mirror of
https://github.com/hanxi/xiaomusic.git
synced 2025-12-06 14:52:50 +08:00
ci: 优化流程
This commit is contained in:
1
.github/workflows/build-base-image.yml
vendored
1
.github/workflows/build-base-image.yml
vendored
@@ -2,6 +2,7 @@ name: Build Docker Base Image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- 'Dockerfile.builder'
|
||||
- 'Dockerfile.runtime'
|
||||
|
||||
55
.github/workflows/ci.yml
vendored
55
.github/workflows/ci.yml
vendored
@@ -8,12 +8,14 @@ on:
|
||||
|
||||
env:
|
||||
TEST_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
|
||||
|
||||
jobs:
|
||||
# Job 1: 构建镜像
|
||||
# Job 构建镜像
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
@@ -75,7 +77,7 @@ jobs:
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache-new
|
||||
|
||||
# Job 2: 测试镜像
|
||||
# Job 测试镜像
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build # 依赖构建完成
|
||||
@@ -97,11 +99,43 @@ jobs:
|
||||
- name: Test armv7 image
|
||||
run: docker run --rm ${{ env.TEST_TAG }}-linux-arm-v7 /app/.venv/bin/python3 /app/xiaomusic.py -h
|
||||
|
||||
# Job 3: 打包应用, 发布镜像和 Release
|
||||
package:
|
||||
# 发布版本
|
||||
pypi-publish:
|
||||
name: upload release to PyPI
|
||||
# 仅在 ref 为以 v 开头的标签时执行
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
needs: test # 依赖测试完成
|
||||
if: github.ref == 'refs/heads/main' # 仅在 main 分支运行
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
registry-url: https://registry.npmjs.org/
|
||||
node-version: lts/*
|
||||
|
||||
- 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
|
||||
|
||||
|
||||
# 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@v3
|
||||
@@ -148,6 +182,17 @@ 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 开头的标签时执行
|
||||
run: |
|
||||
# Define the commands to push latest and stable tags
|
||||
echo "Pushing latest and stable tags..."
|
||||
docker tag ${{ env.TEST_TAG }} ${{ env.LATEST_TAG }}
|
||||
docker tag ${{ env.TEST_TAG }} ${{ env.STABLE_TAG }}
|
||||
docker push ${{ env.LATEST_TAG }}
|
||||
docker push ${{ env.STABLE_TAG }}
|
||||
|
||||
- name: Docker Hub Description
|
||||
uses: peter-evans/dockerhub-description@v4
|
||||
with:
|
||||
|
||||
@@ -24,7 +24,7 @@ jobs:
|
||||
- name: install ruff
|
||||
run: pip install ruff
|
||||
- name: Format code
|
||||
run: pdm fmt && pdm lint --fix
|
||||
run: pdm lintfmt
|
||||
|
||||
- name: Check for changes
|
||||
id: check_changes
|
||||
60
.github/workflows/release.yml
vendored
60
.github/workflows/release.yml
vendored
@@ -1,60 +0,0 @@
|
||||
name: Release and Build Docker Image
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
pypi-publish:
|
||||
name: upload release to PyPI
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
registry-url: https://registry.npmjs.org/
|
||||
node-version: lts/*
|
||||
|
||||
- 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
|
||||
|
||||
build-image:
|
||||
runs-on: ubuntu-latest
|
||||
# run unless event type is pull_request
|
||||
if: github.event_name != 'pull_request'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
platforms: linux/amd64, linux/arm64, linux/arm/v7
|
||||
push: true
|
||||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:${{ github.ref_name }}, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:latest, ${{ secrets.DOCKERHUB_USERNAME }}/xiaomusic:stable
|
||||
2
.github/workflows/static.yml
vendored
2
.github/workflows/static.yml
vendored
@@ -5,8 +5,6 @@ on:
|
||||
# Runs on pushes targeting the default branch
|
||||
push:
|
||||
branches: ["main"]
|
||||
tags:
|
||||
- "v*"
|
||||
paths:
|
||||
- 'docs/**'
|
||||
- 'README.md'
|
||||
|
||||
Reference in New Issue
Block a user