Skip to content

update to v0.2.4-dev-build1 #21

update to v0.2.4-dev-build1

update to v0.2.4-dev-build1 #21

Workflow file for this run

name: 构建
on:
push:
branches: [ 'main' ]
paths: [ 'version.txt' ]
env:
APP_NAME: taoSync
DOCKER_USER: dr34m
DOCKER_NAME: tao-sync
jobs:
get-version:
name: 获取版本号
runs-on: ubuntu-latest
outputs:
TAG_LIST: ${{ steps.getVersion.outputs.TAG_LIST }}
VERSION: ${{ steps.getVersion.outputs.VERSION }}
steps:
- name: 检出仓库代码
uses: actions/checkout@v4
- id: getVersion
name: 获取版本号
run: |
versions=$(head -n 1 version.txt)
tagList=""
IFS=',' read -ra versionList <<< "$versions"
cuVersion="${versionList[0]}"
for version in "${versionList[@]}"; do
tagList+="-t $DOCKER_USER/$DOCKER_NAME:$version "
done
echo "TAG_LIST=$tagList" >> "$GITHUB_OUTPUT"
echo "VERSION=$cuVersion" >> "$GITHUB_OUTPUT"
build-frontend:
name: 构建前端
runs-on: ubuntu-latest
needs: [ get-version ]
env:
VERSION: ${{ needs.get-version.outputs.VERSION }}
steps:
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 安装Node.js 14.x
uses: actions/setup-node@v4
with:
node-version: "14.x"
- name: 安装依赖并构建前端
run: |
sed -i "s/__version_placeholder__/$VERSION/g" frontend/src/views/page/setting/index.vue
cd frontend
npm install
npm run build
- name: 上传artifact
uses: actions/upload-artifact@v4
with:
name: frontend-dist
path: frontend/dist
retention-days: 1
build-docker:
name: 构建Docker与linux
runs-on: ubuntu-latest
needs: [ get-version, build-frontend ]
env:
VERSION: ${{ needs.get-version.outputs.VERSION }}
strategy:
matrix:
platform:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/386
- linux/arm/v6
- linux/s390x
- linux/ppc64le
steps:
- name: 替换平台名称中的斜杠为横杠
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: 设置QEMU
uses: docker/setup-qemu-action@v3
- name: 设置Docker BuildX
uses: docker/setup-buildx-action@v3
- name: 登录到DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 下载前端
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- id: build-image
name: 构建docker镜像
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
outputs: |
type=docker
type=image,name=${{ env.DOCKER_USER }}/${{ env.DOCKER_NAME }},push-by-digest=true,name-canonical=true,push=true
- name: 导出digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build-image.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: 上传digest到artifact
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
retention-days: 1
- name: 从镜像中提取可执行文件
run: |
docker create --name tmp ${{ steps.build-image.outputs.imageid }} /bin/true
docker cp tmp:/app/${{ env.APP_NAME }} ${{ env.APP_NAME }}
tar czf "$APP_NAME-$VERSION-$PLATFORM_PAIR.tar.gz" ${{ env.APP_NAME }}
- name: 上传可执行文件到artifact
uses: actions/upload-artifact@v4
with:
name: dist-${{ env.PLATFORM_PAIR }}
path: ${{ env.APP_NAME }}-${{ env.VERSION }}-${{ env.PLATFORM_PAIR }}.tar.gz
retention-days: 1
merge-docker:
name: 合并Docker镜像
runs-on: ubuntu-latest
needs: [get-version, build-docker]
env:
TAG_LIST: ${{ needs.get-version.outputs.TAG_LIST }}
steps:
- name: 下载digest
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: 设置Docker BuildX
uses: docker/setup-buildx-action@v3
- name: 登录到DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 创建清单并推送
working-directory: /tmp/digests
run: |
docker buildx imagetools create ${{ env.TAG_LIST }}$(printf '${{ env.DOCKER_USER }}/${{ env.DOCKER_NAME }}@sha256:%s ' *)
build-windows-amd64:
name: 构建windows amd64
runs-on: windows-latest
needs: [get-version, build-frontend]
env:
VERSION: ${{needs.get-version.outputs.VERSION}}
steps:
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 下载前端
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: 设置python环境
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: 安装依赖并构建打包
run: |
python -m pip install 'pyinstaller>=6,<7'
python -m pip install -r requirements.txt
python -m PyInstaller ${{ env.APP_NAME }}.spec
cd dist && 7z a ${{ env.APP_NAME }}-${{ env.VERSION }}-windows-amd64.zip *
- name: 上传artifact
uses: actions/upload-artifact@v4
with:
name: dist-windows-amd64
path: dist/*.zip
retention-days: 1
build-darwin:
name: 构建darwin
strategy:
matrix:
os:
- macos-13
- macos-14
runs-on: ${{ matrix.os }}
needs: [get-version, build-frontend]
env:
VERSION: ${{needs.get-version.outputs.VERSION}}
steps:
- name: 判断平台
run: |
os=${{ matrix.os }}
if [ "$os" = "macos-13" ]; then
PLATFORM="amd64"
else
PLATFORM="arm64"
fi
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 下载前端
uses: actions/download-artifact@v4
with:
name: frontend-dist
path: frontend/dist
- name: 设置python环境
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: 安装依赖并构建打包
run: |
python -m pip install 'pyinstaller>=6,<7'
python -m pip install -r requirements.txt
python -m PyInstaller "$APP_NAME.spec"
cd dist
tar czf "$APP_NAME-$VERSION-darwin-$PLATFORM.tar.gz" .
- name: 上传artifact
uses: actions/upload-artifact@v4
with:
name: dist-darwin-${{ env.PLATFORM }}
path: dist/*.tar.gz
retention-days: 1
create-release:
name: 发布release
runs-on: ubuntu-latest
needs: [get-version, build-windows-amd64, build-darwin, build-docker]
env:
VERSION: ${{needs.get-version.outputs.VERSION}}
steps:
- name: 检出仓库代码
uses: actions/checkout@v4
- name: 下载构建结果
uses: actions/download-artifact@v4
with:
pattern: dist-*
path: dist
merge-multiple: true
- name: 没有版本日志文件自动创建
run: |
version_first=$(echo $VERSION | cut -d'-' -f1)
LOG_FILE="doc/changelog/$version_first.md"
if [ ! -f "$LOG_FILE" ]; then
touch "$LOG_FILE"
echo "$VERSION" > "$LOG_FILE"
fi
echo "LOG_FILE=$LOG_FILE" >> "$GITHUB_ENV"
- name: 创建release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.VERSION }}
files: dist/*
body_path: ${{ env.LOG_FILE }}
prerelease: ${{ contains(env.VERSION, 'dev') || contains(env.VERSION, 'pre') }}