Skip to content

Release

Release #1146

Workflow file for this run

name: Release
on:
workflow_run:
workflows:
- x86_64-pc-linux-gnu
- aarch64-pc-linux-gnu
- x86_64-apple-darwin
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
- x86_64-pc-windows-gnu
- aarch64-pc-windows-gnu
- x86_64-unknown-linux-android
- aarch64-apple-ios
- arm-unknown-linux-gnueabihf
- riscv64-unknown-linux-gnu
- mipsel-unknown-linux-gnu
- mips64el-unknown-linux-gnuabi64
- powerpc64le-unknown-linux-gnu
- s390x-ibm-linux-gnu
- sparc64-unknown-linux-gnu
- powerpc-unknown-linux-gnu
- i386-unknown-linux-gnu
- x86_64-alpine-linux
- i386-alpine-linux
- aarch64-alpine-linux
- armv7-musl-linux
- ppc64le-musl-linux
- s390x-musl-linux
- riscv64-musl-linux
types:
- completed
permissions:
contents: write
pull-requests: read
jobs:
check-and-release:
runs-on: ubuntu-latest
# Only run if the triggering workflow succeeded AND it ran on the release branch
if: ${{ github.event.workflow_run.head_branch == 'release' && github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Log trigger information
run: |
echo "Triggered by workflow: ${{ github.event.workflow_run.name }}"
echo "Workflow status: ${{ github.event.workflow_run.conclusion }}"
echo "Branch: ${{ github.event.workflow_run.head_branch }}"
echo "Commit SHA: ${{ github.event.workflow_run.head_sha }}"
- name: Check all workflow statuses
id: check-all
uses: actions/github-script@v7
with:
script: |
const target_workflows = [
"x86_64-pc-linux-gnu",
"aarch64-pc-linux-gnu",
"x86_64-apple-darwin",
"aarch64-apple-darwin",
"x86_64-pc-windows-msvc",
"aarch64-pc-windows-msvc",
"x86_64-pc-windows-gnu",
"aarch64-pc-windows-gnu",
"x86_64-unknown-linux-android",
"aarch64-apple-ios",
"arm-unknown-linux-gnueabihf",
"riscv64-unknown-linux-gnu",
"mipsel-unknown-linux-gnu",
"mips64el-unknown-linux-gnuabi64",
"powerpc64le-unknown-linux-gnu",
"s390x-ibm-linux-gnu",
"sparc64-unknown-linux-gnu",
"powerpc-unknown-linux-gnu",
"i386-unknown-linux-gnu",
"x86_64-alpine-linux",
"i386-alpine-linux",
"aarch64-alpine-linux",
"armv7-musl-linux",
"ppc64le-musl-linux",
"s390x-musl-linux",
"riscv64-musl-linux"
];
const commit_sha = context.payload.workflow_run.head_sha;
const { owner, repo } = context.repo;
console.log(`Checking workflow statuses for commit: ${commit_sha}`);
// Fetch all runs for this commit
const { data: { workflow_runs } } = await github.rest.actions.listWorkflowRunsForRepo({
owner,
repo,
head_sha: commit_sha,
per_page: 100
});
// Map workflow name to its latest run
const latest_runs = {};
for (const run of workflow_runs) {
if (target_workflows.includes(run.name)) {
// If we haven't seen this workflow yet, or this run is newer
if (!latest_runs[run.name] || new Date(run.created_at) > new Date(latest_runs[run.name].created_at)) {
latest_runs[run.name] = run;
}
}
}
const failed = [];
const pending = [];
const succeeded = [];
for (const name of target_workflows) {
const run = latest_runs[name];
if (!run) {
console.log(` ${name}: NO RUN FOUND`);
pending.push(name);
} else if (run.status !== 'completed') {
console.log(` ${name}: ${run.status}`);
pending.push(name);
} else if (run.conclusion !== 'success') {
console.log(` ${name}: completed with ${run.conclusion}`);
failed.push(name);
} else {
console.log(` ${name}: success`);
succeeded.push(name);
}
}
console.log(`\nSummary: ${succeeded.length} succeeded, ${pending.length} pending, ${failed.length} failed`);
if (pending.length > 0) {
console.log(`Waiting for ${pending.length} workflows to complete: ${pending.join(', ')}`);
core.setOutput("ready", "false");
core.notice(`Release skipped: waiting for ${pending.length} workflows to complete`);
return; // Exit successfully but do nothing; wait for next trigger
}
if (failed.length > 0) {
core.setFailed(`One or more workflows failed: ${failed.join(', ')}`);
core.setOutput("ready", "false");
return;
}
console.log("All target workflows passed successfully!");
core.notice("All required workflows passed - creating release");
core.setOutput("ready", "true");
- name: Perform Release
if: steps.check-all.outputs.ready == 'true'
uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_sha }}
fetch-depth: 0
- name: Get Version
if: steps.check-all.outputs.ready == 'true'
run: |
if [ ! -f VERSION ]; then
echo "ERROR: VERSION file not found"
exit 1
fi
VERSION=$(cat VERSION)
echo "Creating release for version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get Release Details
if: steps.check-all.outputs.ready == 'true'
id: release_details
uses: actions/github-script@v7
with:
script: |
const commit_sha = "${{ github.event.workflow_run.head_sha }}";
const { owner, repo } = context.repo;
// Try to find a PR associated with this commit
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner,
repo,
commit_sha,
});
let title = "";
let body = "";
if (prs.data.length > 0) {
const pr = prs.data[0];
title = pr.title;
body = pr.body || "";
} else {
// Fallback to commit message
const commit = await github.rest.repos.getCommit({
owner,
repo,
ref: commit_sha,
});
const message = commit.data.commit.message;
const lines = message.split('\n');
title = lines[0];
body = lines.slice(1).join('\n').trim();
}
core.setOutput("title", title);
core.setOutput("body", body);
- name: Create Release
if: steps.check-all.outputs.ready == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.VERSION }}
name: v${{ env.VERSION }} - ${{ steps.release_details.outputs.title }}
body: ${{ steps.release_details.outputs.body }}
target_commitish: ${{ github.event.workflow_run.head_sha }}
draft: false
prerelease: false