Files
MyGoNavi/.github/workflows/publish-release.yml
Syngnat 3e9335d6ad 🐛 fix(ci): 修复草稿发布分页结果解析 [skip ci]
- 直接读取 Release workflow 与 release 列表响应
- 避免 paginate 映射回调产生空元素导致校验异常
- 保持目标提交和完整资产校验不变
2026-07-19 01:06:47 +08:00

134 lines
4.4 KiB
YAML

name: Publish Draft Release
on:
push:
branches:
- 'publish/v*'
workflow_dispatch:
inputs:
tag:
description: Release tag to publish (for example, v0.8.7)
required: true
type: string
permissions:
actions: read
contents: write
concurrency:
group: publish-release-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
publish:
name: Validate and publish draft
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
steps:
- name: Validate assets and publish
uses: actions/github-script@v8
with:
script: |
const requestedTag = String(process.env.RELEASE_TAG || '').trim();
const tag = requestedTag.startsWith('publish/')
? requestedTag.slice('publish/'.length)
: requestedTag;
if (!/^v\d+\.\d+\.\d+$/.test(tag)) {
core.setFailed(`Invalid release tag: ${tag}`);
return;
}
const { owner, repo } = context.repo;
const tagRef = await github.rest.git.getRef({
owner,
repo,
ref: `tags/${tag}`,
});
let commitSha = tagRef.data.object.sha;
if (tagRef.data.object.type === 'tag') {
const annotatedTag = await github.rest.git.getTag({
owner,
repo,
tag_sha: tagRef.data.object.sha,
});
commitSha = annotatedTag.data.object.sha;
}
const workflowRuns = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id: 'release.yml',
event: 'push',
branch: tag,
per_page: 100,
});
const runs = workflowRuns.data.workflow_runs;
const successfulRun = runs.find((run) => (
run.head_sha === commitSha
&& run.status === 'completed'
&& run.conclusion === 'success'
));
if (!successfulRun) {
core.setFailed(`No successful Release workflow found for ${tag} at ${commitSha}`);
return;
}
const releaseList = await github.rest.repos.listReleases({
owner,
repo,
per_page: 100,
});
const releases = releaseList.data;
const release = releases.find((item) => item.tag_name === tag);
if (!release) {
core.setFailed(`Draft release not found for ${tag}`);
return;
}
if (!release.draft) {
core.setFailed(`Release ${tag} is already published`);
return;
}
const version = tag.slice(1);
const expectedAssets = [
'LICENSE',
'NOTICE',
'SHA256SUMS',
'latest.json',
`GoNavi-${version}-Linux-Amd64-WebKit41.tar.gz`,
`GoNavi-${version}-Linux-Amd64.tar.gz`,
`GoNavi-${version}-Linux-Arm64.tar.gz`,
`GoNavi-${version}-MacOS-Amd64.dmg`,
`GoNavi-${version}-MacOS-Arm64.dmg`,
`GoNavi-${version}-Windows-Amd64-Installer.msi`,
`GoNavi-${version}-Windows-Amd64-Portable.exe`,
`GoNavi-${version}-Windows-Arm64-Installer.msi`,
`GoNavi-${version}-Windows-Arm64-Portable.exe`,
];
const assetsByName = new Map(release.assets.map((asset) => [asset.name, asset]));
const missingAssets = expectedAssets.filter((name) => {
const asset = assetsByName.get(name);
return !asset || asset.state !== 'uploaded' || asset.size <= 0;
});
if (missingAssets.length > 0) {
core.setFailed(`Release assets are incomplete: ${missingAssets.join(', ')}`);
return;
}
const published = await github.rest.repos.updateRelease({
owner,
repo,
release_id: release.id,
draft: false,
prerelease: false,
make_latest: 'true',
});
if (published.data.draft || !published.data.published_at) {
core.setFailed(`Release ${tag} was not published successfully`);
return;
}
core.notice(`Published ${tag}: ${published.data.html_url}`);