Skip to content

chore: update beta.yml #11

chore: update beta.yml

chore: update beta.yml #11

Workflow file for this run

name: Build and Release fideo
on:
push:
branches:
- beta
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install PNPM
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Get version from package.json
id: get_version
run: echo "VERSION=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
shell: bash
- name: Build Electron App
run: |
if [ "${{ runner.os }}" == "Windows" ]; then
pnpm build:win
elif [ "${{ runner.os }}" == "macOS" ]; then
pnpm build:mac
fi
shell: bash
- name: Upload Windows build artifact
if: ${{ runner.os == 'Windows' }}
uses: actions/upload-artifact@v4
with:
name: build-win-${{ env.VERSION }}-beta
path: dist/fideo-${{ env.VERSION }}.exe
- name: Upload macOS build artifacts (x64)
if: ${{ runner.os == 'macOS' }}
uses: actions/upload-artifact@v4
with:
name: build-mac-x64-${{ env.VERSION }}-beta
path: dist/fideo-${{ env.VERSION }}-x64.dmg
- name: Upload macOS build artifacts (arm)
if: ${{ runner.os == 'macOS' }}
uses: actions/upload-artifact@v4
with:
name: build-mac-arm-${{ env.VERSION }}-beta
path: dist/fideo-${{ env.VERSION }}-arm64.dmg
create_release:
needs: [build] # 确保在所有构建完成后运行
runs-on: ubuntu-latest # 使用一个固定的环境
steps:
- uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create release on GitLab
env:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
GITLAB_PROJECT_ID: ${{ secrets.GITLAB_PROJECT_ID }}
run: |
# 获取版本号
VERSION=$(node -p -e "require('./package.json').version")
# 定义变量
RELEASE_TAG="$VERSION-beta"
RELEASE_NAME="Release $RELEASE_TAG"
RELEASE_DESCRIPTION="Automated release for version $RELEASE_TAG"
# 上传并获取资产URL的函数
upload_asset() {
local file=$1
local name=$2
local url=$(curl --fail --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--form "file=@$file" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/uploads" | jq -r '.url')
if [ -z "$url" ]; then
echo "Failed to upload $name"
exit 1
fi
echo "$name=$url"
}
# 上传资产
WIN_ASSET_URL=$(upload_asset "artifacts/build-win-$VERSION-beta/fideo-$VERSION.exe" "Windows")
MAC_X64_ASSET_URL=$(upload_asset "artifacts/build-mac-x64-$VERSION-beta/fideo-$VERSION-x64.dmg" "macOS x64")
MAC_ARM_ASSET_URL=$(upload_asset "artifacts/build-mac-arm-$VERSION-beta/fideo-$VERSION-arm64.dmg" "macOS ARM")
# 创建GitLab发布
response=$(curl --fail --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--data "name=$RELEASE_NAME" \
--data "tag_name=$RELEASE_TAG" \
--data "description=$RELEASE_DESCRIPTION" \
--data "assets[links][][name]=Windows" \
--data "assets[links][][url]=$WIN_ASSET_URL" \
--data "assets[links][][name]=macOS x64" \
--data "assets[links][][url]=$MAC_X64_ASSET_URL" \
--data "assets[links][][name]=macOS ARM" \
--data "assets[links][][url]=$MAC_ARM_ASSET_URL" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/releases")
if [ $? -ne 0 ]; then
echo "Failed to create GitLab release"
echo "$response"
exit 1
fi
echo "GitLab release created successfully"