fix release

This commit is contained in:
chengyangkj 2025-07-29 11:30:57 +08:00
parent 7e306187fc
commit 743175f41d

View File

@ -23,8 +23,10 @@ jobs:
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
script: | script: |
const allArtifacts = []; const fs = require('fs');
const runs = await github.rest.actions.listWorkflowRuns({
// 获取当前仓库的所有workflow runs
const runs = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
event: 'push', event: 'push',
@ -32,15 +34,28 @@ jobs:
created: `>${new Date(Date.now() - 10 * 60 * 1000).toISOString()}` // 最近10分钟内的运行 created: `>${new Date(Date.now() - 10 * 60 * 1000).toISOString()}` // 最近10分钟内的运行
}); });
console.log(`Found ${runs.data.workflow_runs.length} workflow runs`);
for (const run of runs.data.workflow_runs) { for (const run of runs.data.workflow_runs) {
console.log(`Checking run ${run.id} with SHA ${run.head_sha}, current SHA: ${context.sha}`);
// 只处理与当前commit相关的runs
if (run.head_sha === context.sha) { if (run.head_sha === context.sha) {
console.log(`Processing run ${run.id}`);
try {
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
run_id: run.id run_id: run.id
}); });
console.log(`Found ${artifacts.data.artifacts.length} artifacts in run ${run.id}`);
for (const artifact of artifacts.data.artifacts) { for (const artifact of artifacts.data.artifacts) {
console.log(`Downloading artifact: ${artifact.name}`);
try {
const download = await github.rest.actions.downloadArtifact({ const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
@ -48,8 +63,14 @@ jobs:
archive_format: 'zip' archive_format: 'zip'
}); });
const fs = require('fs');
fs.writeFileSync(`${artifact.name}.zip`, Buffer.from(download.data)); fs.writeFileSync(`${artifact.name}.zip`, Buffer.from(download.data));
console.log(`Successfully downloaded ${artifact.name}.zip`);
} catch (error) {
console.error(`Failed to download artifact ${artifact.name}:`, error.message);
}
}
} catch (error) {
console.error(`Failed to get artifacts for run ${run.id}:`, error.message);
} }
} }
} }
@ -69,7 +90,10 @@ jobs:
run: | run: |
for zip in *.zip for zip in *.zip
do do
if [ -f "$zip" ]; then
echo "Unzipping $zip"
unzip "$zip" || true unzip "$zip" || true
fi
done done
- name: Upload Release Assets - name: Upload Release Assets
@ -81,9 +105,13 @@ jobs:
const fs = require('fs'); const fs = require('fs');
const release_id = '${{ steps.create_release.outputs.id }}'; const release_id = '${{ steps.create_release.outputs.id }}';
console.log('Looking for files to upload...');
const files = fs.readdirSync('.'); const files = fs.readdirSync('.');
for (const file of files) { for (const file of files) {
if (file.endsWith('.tar.gz')) { if (file.endsWith('.tar.gz') || file.endsWith('.zip') || file.endsWith('.deb') || file.endsWith('.rpm')) {
console.log(`Uploading ${file} to release`);
try {
await github.rest.repos.uploadReleaseAsset({ await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
@ -91,5 +119,9 @@ jobs:
name: file, name: file,
data: fs.readFileSync(file) data: fs.readFileSync(file)
}); });
console.log(`Successfully uploaded ${file}`);
} catch (error) {
console.error(`Failed to upload ${file}:`, error.message);
}
} }
} }