Skip to content

更改工具執行邏輯 #27

更改工具執行邏輯

更改工具執行邏輯 #27

Workflow file for this run

name: commit-build
on:
push:
paths-ignore:
- 'README.md'
- 'READMEs/**'
- '.vscode/**'
- 'TODO.md'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout code
uses: actions/checkout@v6
# - name: Install Rust Toolchain
# uses: actions-rs/toolchain@v1
# with:
# toolchain: stable
# override: true
- name: install rustup (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
Invoke-WebRequest -Uri "https://win.rustup.rs" -OutFile "rustup-init.exe"
ls
.\rustup-init.exe -y --profile minimal
- name: install rustup (Linux)
if: runner.os == 'Linux'
run: |
curl https://sh.rustup.rs -o rust-init.sh
sh rust-init.sh -y
- name: check rust Install
run: |
rustc --version
cargo --version
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: check uv install
run: |
uv self version
- name: debug build
run: cargo build
- name: release build
run: cargo build --release
- name: zip files (Linux)
id: zip_files_linux
if: runner.os == 'Linux'
run: |
file=$(uv run ci/zip_files.py)
echo "zip_path=$file" >> $GITHUB_OUTPUT
- name: zip files (Windows)
id: zip_files_windows
if: runner.os == 'Windows'
run: |
$file = (uv run ci/zip_files.py)
echo "zip_path=$file" >> $env:GITHUB_OUTPUT
- name: Upload exe artifact (Linux)
uses: actions/upload-artifact@v6
if: runner.os == 'Linux'
with:
name: ${{ steps.zip_files_linux.outputs.zip_path }}
path: ${{ steps.zip_files_linux.outputs.zip_path }}
- name: Upload exe artifact (Windows)
uses: actions/upload-artifact@v6
if: runner.os == 'Windows'
with:
name: ${{ steps.zip_files_windows.outputs.zip_path }}
path: ${{ steps.zip_files_windows.outputs.zip_path }}
upload:
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Prepare CI Venv
run: |
cd ci
uv venv --python cpython-3.13
cd ..
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Get datetime
id: get_datetime
run: |
cd ci
datetime=$(uv run get_datetime.py)
echo "datetime=$datetime" >> $GITHUB_OUTPUT
cd ..
- name: Get package get_version
id: get_version
run: |
cd ci
version=$(uv run get_version.py)
cd ..
echo "version=$version" >> $GITHUB_OUTPUT
- name: List Dir (for debug)
run: |
ls .
echo '--------'
ls artifacts
echo '--------'
ls -la artifacts
- name: Create Prerelease via GitHub CLI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo '----create_release----'
gh release create "ci-pre-v${{ steps.get_version.outputs.version }}-${{ github.sha }}" \
--title "ci-PTB_pre-release+${{ steps.get_version_linux.outputs.version }}+${{ steps.get_datetime.outputs.datetime }} (${{ github.sha }})" \
--notes "**這是使用Github Action製作的測試版**
- 版本: ${{ steps.get_version.outputs.version }}
- 臺北時間: ${{ steps.get_datetime.outputs.datetime }}
> UTC時間:臺北時間-8
- github_sha: ${{ github.sha }}" \
--prerelease \
--repo="${{ github.repository }}"
echo '----Get Upload Url----'
upload_url_base=$(gh api \
repos/{owner}/{repo}/releases/tags/ci-pre-v${{ steps.get_version.outputs.version }}-${{ github.sha }} \
--jq '.upload_url')
echo 'upload_url_base=$upload_url_base'
echo '----upload----'
set -euo pipefail
upload_url="${upload_url_base%\{*}"
echo "Uploading artifacts to $upload_url"
shopt -s globstar || true
for f in artifacts/**; do
if [ -f "$f" ]; then
echo "Uploading $f"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"$f" \
"$upload_url?name=$(basename "$f")"
fi
done