Files
2026-07-20 12:23:20 +08:00

61 lines
2.0 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: build-and-release
run-name: Build #${{ github.run_number }}
on:
push:
branches: [main]
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
# runner 到 github.com 网络不稳定,不使用 actions/checkout@v4
# 改为直接从本 Gitea 实例克隆代码
- name: Checkout
shell: pwsh
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$url = "${{ gitea.server_url }}/${{ github.repository }}.git" -replace '^https://', "https://x-access-token:$env:GITEA_TOKEN@"
git clone $url .
git checkout ${{ github.sha }}
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Smoke test
run: node dist/app.js
- name: Package
shell: pwsh
run: |
$tag = "v0.1.${{ github.run_number }}"
Compress-Archive -Path dist\* -DestinationPath "test-runner-$tag.zip"
echo "TAG=$tag" >> $env:GITHUB_ENV
- name: Create Gitea release with artifact
shell: pwsh
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$repo = "${{ github.repository }}"
$tag = $env:TAG
$server = "${{ gitea.server_url }}"
$headers = @{ Authorization = "token $env:GITEA_TOKEN" }
$body = @{
tag_name = $tag
name = "Test build $tag"
target_commitish = "${{ github.sha }}"
draft = $false
prerelease = $true
} | ConvertTo-Json
$release = Invoke-RestMethod -Method Post -Uri "$server/api/v1/repos/$repo/releases" -Headers $headers -Body $body -ContentType "application/json"
Write-Host "Created release id=$($release.id) tag=$tag"
$zip = Get-Item "test-runner-$tag.zip"
Invoke-RestMethod -Method Post -Uri "$server/api/v1/repos/$repo/releases/$($release.id)/assets?name=$($zip.Name)" -Headers $headers -Form @{ attachment = $zip }
Write-Host "Uploaded asset $($zip.Name)"