Skip to content

Commit

Permalink
chore: update beta.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
chenfan0 committed Aug 28, 2024
1 parent c189ac6 commit 1e8f598
Showing 1 changed file with 47 additions and 21 deletions.
68 changes: 47 additions & 21 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,66 @@ jobs:
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: |
# Define variables
RELEASE_TAG=${{ env.VERSION }}-beta
# 获取版本号
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"
# Upload Windows artifact to GitLab as a release asset
WIN_ASSET_URL=$(curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--form "file=@dist/fideo-${{ env.VERSION }}.exe" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/uploads" | jq -r '.url')
# Upload macOS x64 artifact to GitLab as a release asset
MAC_X64_ASSET_URL=$(curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--form "file=@dist/fideo-${{ env.VERSION }}-x64.dmg" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/uploads" | jq -r '.url')
# 上传并获取资产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"
}
# Upload macOS arm artifact to GitLab as a release asset
MAC_ARM_ASSET_URL=$(curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--form "file=@dist/fideo-${{ env.VERSION }}-arm64.dmg" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/uploads" | jq -r '.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")
# Create a release on GitLab
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
# 创建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]=https://gitlab.com/$GITLAB_PROJECT_ID/uploads/$WIN_ASSET_URL" \
--data "assets[links][][url]=$WIN_ASSET_URL" \
--data "assets[links][][name]=macOS x64" \
--data "assets[links][][url]=https://gitlab.com/$GITLAB_PROJECT_ID/uploads/$MAC_X64_ASSET_URL" \
--data "assets[links][][url]=$MAC_X64_ASSET_URL" \
--data "assets[links][][name]=macOS ARM" \
--data "assets[links][][url]=https://gitlab.com/$GITLAB_PROJECT_ID/uploads/$MAC_ARM_ASSET_URL" \
"https://gitlab.com/api/v4/projects/$GITLAB_PROJECT_ID/releases"
--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"

0 comments on commit 1e8f598

Please sign in to comment.