Skip to content

发布

发布 #36

Workflow file for this run

name: 发布
on:
workflow_run:
workflows: ["构建"]
types:
- completed
workflow_dispatch:
inputs:
tag: # 保留但改为可选参数
description: "手动指定日期标签(格式:yyyyMMdd)"
required: false
default: ${{ github. }} # 添加默认值

Check failure on line 13 in .github/workflows/release.yml

View workflow run for this annotation

GitHub Actions / 发布

Invalid workflow file

The workflow is not valid. .github/workflows/release.yml (Line: 13, Col: 18): Unrecognized named-value: 'github'. Located at position 1 within expression: github. .github/workflows/release.yml (Line: 25, Col: 14): Unrecognized named-value: 'Get-Date'. Located at position 29 within expression: github.event.inputs.tag || (Get-Date).ToString('yyyyMMdd')
jobs:
release:
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} # 修改判断逻辑
runs-on: windows-latest
permissions:
contents: write
actions: read
steps:
- name: 获取构建时间
id: date
run: |
# 添加手动触发时的tag处理逻辑
$date = if (${{ github.event_name == 'workflow_dispatch' }}) {
${{ github.event.inputs.tag || (Get-Date).ToString('yyyyMMdd') }}
} else {
(Get-Date).ToString('yyyyMMdd')
}
echo "tag=$date" >> $env:GITHUB_OUTPUT
echo "release_date=$(Get-Date -Format 'yyyy.M.d')" >> $env:GITHUB_OUTPUT
- name: 下载构建产物
uses: actions/download-artifact@v4
with:
path: artifacts
- name: 提取Python版本
id: version
run: |
$file=(Get-ChildItem artifacts/*.7z | Select-Object -First 1).Name
$version=$file -replace '.*(v\d+\.\d+\.\d+).*','$1'
echo "version=$version" >> $env:GITHUB_OUTPUT
- name: 生成Markdown表格
id: generate_table
run: |
$content=@()
Get-ChildItem artifacts/*.7z | ForEach-Object {
$filename = $_.Name
$parts = $filename -split '-'
$arch = $parts[3]
$optimization = $parts[4]
$link_type = ($parts[5] -replace '.7z','') -replace 'static','静态' -replace 'dynamic','动态'
$content += "| $arch | $optimization | $link_type | [下载]($filename) |"
}
echo "markdown_table<<EOF" >> $env:GITHUB_OUTPUT
echo ($content -join "`n") >> $env:GITHUB_OUTPUT
echo "EOF" >> $env:GITHUB_OUTPUT
- name: 创建Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.date.outputs.tag }}
name: "Python-${{ steps.version.outputs.version }}-${{ steps.date.outputs.release_date }}-MinGW"
body: |
### 构建详情
| 架构 | 优化级别 | 链接类型 | 下载 |
|------|---------|---------|-----|
${{ steps.generate_table.outputs.markdown_table }}
draft: false
prerelease: false
skip_if_tag_exists: true
files: |
artifacts/*.7z
- name: 清理旧Release
if: success()
uses: actions/github-script@v7
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const sortedReleases = releases
.filter(release => !release.draft && !release.prerelease)
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
for (const release of sortedReleases.slice(50)) {
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id
});
// 同时删除对应标签
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${release.tag_name}`
});
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}