Skip to content

Auto Package and Release #13

Auto Package and Release

Auto Package and Release #13

name: Auto Package and Release
on:
workflow_dispatch:
push:
paths:
- 'package/config.yml'
jobs:
release:
name: release
runs-on: windows-latest
outputs: # 新增 outputs 部分
release_id: ${{ steps.create_release.outputs.id }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取所有历史记录以便生成标签
- name: Generate version tag
id: version
run: |
# 使用 UTC 时间确保一致性
$date = (Get-Date).ToUniversalTime().ToString("yy.MM.dd")
$tag = "v$date"
$release = "Release $date"
echo "tag=$tag" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
echo "release_name=$release" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1 # 使用更活跃维护的 release 操作
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag }}
name: ${{ steps.version.outputs.release_name }}
generate_release_notes: true
draft: false
prerelease: false
package:
needs: release
name: package
strategy:
matrix:
os: [ubuntu-latest, ubuntu-24.04-arm, windows-latest, windows-11-arm]
runs-on: ${{ matrix.os }}
# 添加必要的权限
permissions:
contents: write # 允许创建发布和上传资源
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # 获取所有历史记录以便生成标签
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: UPX Setup(Windows amd64)
if: ${{ matrix.os == 'windows-latest' }}
run: |
mkdir upx
curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/upx.exe
- name: UPX Setup(Linux amd64)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
mkdir upx
curl -o upx/upx https://assets.ksable.top/github/upx/upx/v5.0.1/linux-amd64/upx
- name: UPX Setup(Linux arm64)
if: ${{ matrix.os == 'ubuntu-24.04-arm' }}
run: |
mkdir upx
curl -o upx/upx https://assets.ksable.top/github/upx/upx/v5.0.1/linux-arm64/upx
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pyinstaller pyyaml
- name: Fix Python encoding (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
# 设置Python使用UTF-8编码
[System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process')
# 设置控制台编码为UTF-8
chcp.com 65001
- name: Run packaging script
run: |
cd package
python build.py config.yml
- name: Check
run: |
python ./package/md5.py dist
# 检查 ./dist/ 是否存在文件(Linux)
- name: Check if ./dist exists and has files
if: ${{ matrix.os == 'ubuntu-latest' or matrix.os == 'ubuntu-24.04-arm' }}

Check failure on line 109 in .github/workflows/auto_package_and_release.yml

View workflow run for this annotation

GitHub Actions / Auto Package and Release

Invalid workflow file

The workflow is not valid. .github/workflows/auto_package_and_release.yml (Line: 109, Col: 11): Unexpected symbol: 'or'. Located at position 30 within expression: matrix.os == 'ubuntu-latest' or matrix.os == 'ubuntu-24.04-arm' .github/workflows/auto_package_and_release.yml (Line: 130, Col: 11): Unexpected symbol: 'or'. Located at position 22 within expression: env.havefilew == '1' or env.havefilel =='1'
run: |
if [ -d "./dist" ] && [ -n "$(ls -A ./dist)" ]; then
echo "havefilel=1" >> $GITHUB_ENV
else
echo "havefilel=0" >> $GITHUB_ENV
fi
- name: Check if ./dist exists and has files (CMD)
run: |
if exist dist\ (
cd dist
for /f "delims=" %%a in ('dir /b 2^>nul') do (
echo havefilew=1 >> "%GITHUB_ENV%"
exit /b 0
)
)
echo havefile=0 >> "%GITHUB_ENV%"
- name: Upload Release Assets
if: ${{ env.havefilew == '1' or env.havefilel =='1'}}
uses: xresloader/upload-to-github-release@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: "./dist/*.exe;./dist/*/*.exe;./dist/*"
release_id: ${{ needs.release.outputs.release_id }} # 修正引用路径
verbose: false
overwrite: true