Build #125
This file contains 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: Build | |
permissions: write-all | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: "Tag version to release" | |
required: false | |
push: | |
branches: | |
- master | |
tags: | |
- v* | |
paths-ignore: | |
- 'README.md' | |
- '.github/ISSUE_TEMPLATE/**' | |
- '.github/workflows/issues.yml' | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [windows-latest, ubuntu-latest, macos-latest] | |
arch: [x64, arm64] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup pnpm | |
run: npm install -g pnpm | |
- name: Determine and Update Version | |
shell: bash | |
run: | | |
GIT_COMMIT_HASH=$(git rev-parse --short HEAD) | |
VERSION=$(jq -r '.version' package.json) | |
if [ "${{ github.event.inputs.version }}" == "" ]; then | |
BASE_VERSION=$(echo $VERSION | awk -F. '{print $1"."$2"."$3+1}') | |
VERSION_PREFIX=${VERSION_PREFIX:-beta} | |
RELEASE_VERSION="${BASE_VERSION}-${VERSION_PREFIX}-${GIT_COMMIT_HASH}" | |
else | |
INPUT_VERSION="${{ github.event.inputs.version }}" | |
CLEAN_VERSION=$(echo "$INPUT_VERSION" | sed 's/^v//') | |
if [[ ! "$CLEAN_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Invalid version format: $INPUT_VERSION" | |
exit 1 | |
fi | |
RELEASE_VERSION="$CLEAN_VERSION" | |
fi | |
jq --arg version "$RELEASE_VERSION" '.version = $version' package.json > tmp.json && mv tmp.json package.json | |
- name: Install Dependencies and Prepare | |
env: | |
npm_config_arch: ${{ matrix.arch }} | |
npm_config_target_arch: ${{ matrix.arch }} | |
run: | | |
pnpm install | |
pnpm add @mihomo-party/sysproxy-${{ matrix.os == 'windows-latest' && 'win32' || matrix.os == 'ubuntu-latest' && 'linux' || 'darwin' }}-${{ matrix.arch }}${{ matrix.os == 'ubuntu-latest' && '-gnu' || matrix.os == 'windows-latest' && '-msvc' || '' }} | |
pnpm prepare --${{ matrix.arch }} | |
- name: Build | |
env: | |
npm_config_arch: ${{ matrix.arch }} | |
npm_config_target_arch: ${{ matrix.arch }} | |
run: | | |
chmod +x build/pkg-scripts/postinstall | |
pnpm build:${{ matrix.os == 'windows-latest' && 'win' || matrix.os == 'ubuntu-latest' && 'linux' || 'mac' }} --${{ matrix.arch }} | |
- name: Add Portable Flag | |
if: matrix.os == 'windows-latest' | |
run: | | |
New-Item -Path "PORTABLE" -ItemType File | |
Get-ChildItem dist/*portable.7z | ForEach-Object { | |
7z a $_.FullName PORTABLE | |
} | |
- name: Generate latest.yml | |
run: pnpm updater | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.os }}-${{ matrix.arch }} | |
path: | | |
dist/mihomo-party* | |
!dist/mihomo-party*blockmap | |
latest.yml | |
changelog.md | |
pre-release: | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Download Artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: bin/ | |
merge-multiple: true | |
- name: Delete Pre-release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
if ! gh release delete pre-release --yes; then | |
echo "Failed to delete release, but continuing..." | |
fi | |
git log -1 --pretty=format:"%s%n%b" > changelog.md | |
- name: Publish Prerelease | |
if: success() | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: pre-release | |
body_path: changelog.md | |
files: | | |
bin/dist/* | |
prerelease: true | |
release: | |
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.version != '') | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate Changelog | |
env: | |
API_URL: ${{ secrets.API_URL }} | |
API_KEY: ${{ secrets.API_KEY }} | |
run: | | |
git pull | |
git fetch --tags | |
TEXT=$(git log v$(jq -r .version package.json)..HEAD --pretty=format:%s | grep -v '^[0-9]\+\.[0-9]\+\.[0-9]\+$' | sed ':a;N;$!ba;s/\n/\\n/g') | |
echo $TEXT | |
QUESTION="Translate into Chinese:\n"""\n$TEXT\n"""" | |
PAYLOAD=$(cat <<EOF | |
{ | |
"stream": false, | |
"model": "gpt-4o", | |
"messages": [ | |
{ | |
"role": "system", | |
"content": "You are a professional translation engine, please translate the text into a colloquial, professional, elegant and fluent content, without the style of machine translation. You must only translate the text content, never interpret it." | |
}, | |
{ | |
"role": "user", | |
"content": "$QUESTION" | |
} | |
] | |
} | |
EOF | |
) | |
RESPONSE=$(curl -s -X POST "$API_URL/v1/chat/completions" \ | |
-H "Authorization: Bearer $API_KEY" \ | |
-H "Content-Type: application/json" \ | |
-d "$PAYLOAD" \ | |
--max-time 30) | |
echo '# 更新日志' > changelog.md | |
echo $RESPONSE | jq .choices[0].message.content -r | sed 's/\\n/\n/g' | |
echo $RESPONSE | jq .choices[0].message.content -r | sed 's/\\n/\n/g' >> changelog.md | |
- name: Setup Debug Session | |
uses: csexton/debugger-action@master | |
- name: Update Version | |
run: | | |
INPUT_VERSION="${{ github.event.inputs.version }}" | |
CLEAN_VERSION=$(echo "$INPUT_VERSION" | sed 's/^v//') | |
if [[ ! "$CLEAN_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Invalid version format: $INPUT_VERSION" | |
exit 1 | |
fi | |
jq --arg version "$CLEAN_VERSION" '.version = $version' package.json > tmp.json && mv tmp.json package.json | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git add package.json | |
git commit -m "Update version to $CLEAN_VERSION" | |
git push | |
echo "version: $CLEAN_VERSION" > latest.yml | |
- uses: actions/download-artifact@v4 | |
with: | |
path: bin/ | |
merge-multiple: true | |
- name: Delete Current | |
uses: 8Mi-Tech/delete-release-assets-action@main | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.event.inputs.version != '' && github.event.inputs.version || github.ref }} | |
deleteOnlyFromDrafts: false | |
- name: Publish Release | |
if: success() | |
uses: softprops/action-gh-release@v2 | |
with: | |
tag_name: ${{ github.event.inputs.version != '' && github.event.inputs.version || github.ref }} | |
body_path: changelog.md | |
files: | | |
latest.yml | |
bin/dist/* |