Release 2026-01-18 05:12:00 UTC #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Must bump version for release | |
| on: | |
| pull_request: | |
| branches: | |
| - release | |
| permissions: | |
| contents: read | |
| jobs: | |
| version-check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Ensure Cargo.toml version increased from release | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const pr = context.payload.pull_request; | |
| const baseRef = pr.base.ref; | |
| const headSha = pr.head.sha; | |
| async function getCargoToml(ref) { | |
| const { data } = await github.rest.repos.getContent({ | |
| owner, | |
| repo, | |
| path: 'Cargo.toml', | |
| ref, | |
| }); | |
| return Buffer.from(data.content, data.encoding).toString('utf8'); | |
| } | |
| function extractPackageVersion(toml) { | |
| const lines = toml.split(/\r?\n/); | |
| let inPackage = false; | |
| for (const line of lines) { | |
| const trimmed = line.trim(); | |
| if (trimmed.startsWith('[') && trimmed.endsWith(']')) { | |
| inPackage = trimmed === '[package]'; | |
| continue; | |
| } | |
| if (!inPackage) continue; | |
| const match = trimmed.match(/^version\s*=\s*"([^"]+)"/); | |
| if (match) return match[1]; | |
| } | |
| return null; | |
| } | |
| function parseVersion(version) { | |
| const [core, pre] = version.split('-', 2); | |
| const parts = core.split('.').map((part) => parseInt(part, 10)); | |
| while (parts.length < 3) parts.push(0); | |
| return { parts, pre: pre || null }; | |
| } | |
| function compareVersions(a, b) { | |
| const av = parseVersion(a); | |
| const bv = parseVersion(b); | |
| for (let i = 0; i < 3; i += 1) { | |
| if (av.parts[i] !== bv.parts[i]) { | |
| return av.parts[i] > bv.parts[i] ? 1 : -1; | |
| } | |
| } | |
| if (av.pre === bv.pre) return 0; | |
| if (av.pre === null) return 1; | |
| if (bv.pre === null) return -1; | |
| return av.pre > bv.pre ? 1 : -1; | |
| } | |
| const headToml = await getCargoToml(headSha); | |
| const baseToml = await getCargoToml(baseRef); | |
| const headVersion = extractPackageVersion(headToml); | |
| const baseVersion = extractPackageVersion(baseToml); | |
| if (!headVersion || !baseVersion) { | |
| core.setFailed(`Failed to read version from Cargo.toml (head: ${headVersion}, base: ${baseVersion}).`); | |
| return; | |
| } | |
| if (compareVersions(headVersion, baseVersion) <= 0) { | |
| core.setFailed(`Cargo.toml version must be increased before merging into ${baseRef}. head=${headVersion}, base=${baseVersion}`); | |
| } |