Skip to content

Commit

Permalink
ci: 优化流程
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Dec 17, 2024
1 parent 93ea4c9 commit 998e13c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 67 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Build Docker Base Image

on:
push:
branches: ["main"]
paths:
- 'Dockerfile.builder'
- 'Dockerfile.runtime'
Expand Down
53 changes: 49 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 # 依赖构建完成
Expand All @@ -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
# 发布版本
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
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 # 依赖测试完成
if: github.ref == 'refs/heads/main' # 仅在 main 分支运行
steps:
- name: Cache Docker layers for packaging
uses: actions/cache@v3
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fmt.yaml → .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 0 additions & 60 deletions .github/workflows/release.yml

This file was deleted.

2 changes: 0 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
tags:
- "v*"
paths:
- 'docs/**'
- 'README.md'
Expand Down

0 comments on commit 998e13c

Please sign in to comment.