Merge pull request #356 from BlueArchiveArisHelper/dev #35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto package, tag, release on PR | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - "README.md" # 忽略文档更新,避免不必要的运行 | |
| workflow_dispatch: # 允许手动触发 | |
| jobs: | |
| build-and-release: | |
| runs-on: windows-latest # 使用Windows环境[1](@ref) | |
| env: | |
| PYTHONIOENCODING: "utf-8" | |
| PYTHONUTF8: "1" # 强制使用UTF-8编码[1,3](@ref) | |
| permissions: | |
| contents: write # 允许创建Tag和Release[2](@ref) | |
| steps: | |
| - name: Checkout main branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main # 明确检出main分支[5](@ref) | |
| - name: Set up Miniconda | |
| uses: conda-incubator/setup-miniconda@v3 | |
| with: | |
| miniconda-version: "py310_24.7.1-0" | |
| python-version: "3.10.14" | |
| auto-update-conda: false | |
| activate-environment: "baah" | |
| - name: Check conda env list | |
| run: | | |
| conda env list | |
| - name: Cache pip | |
| uses: actions/cache@v4 | |
| if: startsWith(runner.os, 'Windows') | |
| with: | |
| path: ~\AppData\Local\pip\Cache | |
| key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Upgrade pip and install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements.txt | |
| - name: Extract version number | |
| id: get_version | |
| run: | | |
| $version = python package.py -v | |
| echo "VERSION_NUMBER=$version" >> $env:GITHUB_OUTPUT | |
| # 新增的标签检查步骤 | |
| - name: Check for existing tag | |
| id: check_tag | |
| run: | | |
| $tag = "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" | |
| $result = git ls-remote --tags origin $tag | |
| if ($result) { | |
| Write-Output "::error::Already has this tag: $tag" | |
| exit 1 | |
| } else { | |
| Write-Output "Tag $tag does not exist. Proceeding." | |
| } | |
| - name: Extract version change log | |
| id: get_change_log | |
| run: | | |
| # 将日志输出到文件,确保UTF-8编码和换行符保留 | |
| python package.py -c | Out-File -FilePath changelog.md -Encoding utf8 | |
| - name: Build package | |
| run: python package.py # 执行打包脚本[8](@ref) | |
| - name: Create Git Tag | |
| run: | | |
| git tag "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" | |
| git push origin "BAAH${{ steps.get_version.outputs.VERSION_NUMBER }}" | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # 使用内置令牌[2](@ref) | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 # 功能完整的Release Action[2,10](@ref) | |
| with: | |
| draft: false | |
| prerelease: false | |
| tag_name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }} | |
| name: BAAH${{ steps.get_version.outputs.VERSION_NUMBER }} | |
| body_path: changelog.md # 关键修改:从文件读取内容 | |
| files: ./dist/*.zip # 仅上传ZIP格式的制品[10](@ref) | |
| MirrorChyanUploading: | |
| runs-on: ubuntu-latest | |
| needs: build-and-release | |
| steps: | |
| - name: Get latest tag | |
| id: get_release_tag | |
| shell: bash | |
| run: | | |
| response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/releases/latest) | |
| tag=$(echo "$response" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') | |
| echo "TAG=$tag" >> $GITHUB_OUTPUT | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Trigger MirrorChyanUploading | |
| shell: bash | |
| run: | | |
| gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan.yml -f tag=${{ steps.get_release_tag.outputs.TAG }} | |
| gh workflow run --repo $GITHUB_REPOSITORY mirrorchyan_release_note.yml -f tag=${{ steps.get_release_tag.outputs.TAG }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| SyncCNBCool: | |
| runs-on: ubuntu-latest | |
| needs: build-and-release | |
| steps: | |
| - name: Sync cnb.cool repo | |
| run: | | |
| curl -X 'POST' \ | |
| 'https://api.cnb.cool/BlockHaity/BAAH-releases/-/build/start' \ | |
| -H 'accept: application/json' \ | |
| -H 'Content-Type: application/json' \ | |
| -H 'Authorization: Bearer ${{ secrets.CNB_TOKEN }}' \ | |
| -d '{ "event": "api_trigger" }' |