Skip to content

Release

Release #8

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
- aarch64-unknown-linux-gnu
- 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
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: 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",
"aarch64-unknown-linux-gnu",
"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"
];
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 = [];
for (const name of target_workflows) {
const run = latest_runs[name];
if (!run || run.status !== 'completed') {
pending.push(name);
} else if (run.conclusion !== 'success') {
failed.push(name);
}
}
if (pending.length > 0) {
console.log(`Waiting for other workflows to complete: ${pending.join(', ')}`);
return; // Exit successfully but do nothing; wait for next trigger
}
if (failed.length > 0) {
core.setFailed(`One or more workflows failed: ${failed.join(', ')}`);
return;
}
console.log("All target workflows passed successfully!");
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: echo "VERSION=$(cat 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
- name: Update prerelease version
if: steps.check-all.outputs.ready == 'true'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git fetch origin prerelease
git checkout prerelease
# Increment version
chmod +x scripts/increment_version.sh
./scripts/increment_version.sh
# Commit and push
git add VERSION
NEW_VER=$(cat VERSION)
git commit -m "Bump version to $NEW_VER [skip ci]"
git push origin prerelease