Skip to content

Commit

Permalink
Draft release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
amacneil committed Feb 6, 2025
1 parent 48791a0 commit 7634e49
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Draft Release

on:
workflow_dispatch:
inputs:
version:
description: "Version (must start with 'v')"
required: true

jobs:
draft-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- run: corepack enable

- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- run: yarn install --immutable
- run: yarn bump-sdk-version ${{ inputs.version }}

- name: Create draft release
run: |
gh release create "sdk/${{ inputs.version }}" \
--draft \
--generate-notes \
--title "sdk/${{ inputs.version }}"
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --report-unused-disable-directives --fix .",
"test": "jest",
"bump-sdk-version": "ts-node ./scripts/bumpSdkVersion.ts",
"update-generated-files": "ts-node --files --project tsconfig.json ./scripts/updateGeneratedFiles.ts --out-dir schemas --ros-out-dir ros_foxglove_msgs && yarn test --updateSnapshot"
},
"devDependencies": {
"@foxglove/eslint-plugin": "2.0.0",
"@foxglove/omgidl-parser": "^0.2.0",
"@foxglove/rosmsg": "^4.0.0",
"@foxglove/tsconfig": "2.0.0",
"@types/glob": "^8.1.0",
"@types/jest": "29.5.14",
"@types/node": "22.13.0",
"@typescript-eslint/eslint-plugin": "8.22.0",
Expand All @@ -30,6 +32,7 @@
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jest": "28.11.0",
"eslint-plugin-prettier": "5.2.3",
"glob": "^10.3.10",
"globals": "^15.14.0",
"jest": "29.7.0",
"prettier": "^3.4.2",
Expand Down
76 changes: 76 additions & 0 deletions scripts/bumpSdkVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env tsx

import { glob } from "glob";
import fs from "fs/promises";

Check failure on line 4 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

`fs/promises` import should occur before import of `glob`
import path from "path";
import { spawn } from "child_process";

Check failure on line 6 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

`child_process` import should occur before import of `glob`

const versionRegex = /^version\s*=\s*"[^"]*"/m;

async function main() {
const newVersion = process.argv[2];
if (!newVersion?.startsWith("v")) {

Check failure on line 12 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

Unexpected nullable boolean value in conditional. Please handle the nullish case explicitly
console.log("Usage: bumpSdkVersion.ts <version>");
console.log("Version must start with 'v'");
process.exit(1);
}

// Remove the 'v' prefix for the actual version string
const versionNumber = newVersion.slice(1);

// Find all Cargo.toml files from workspace root
const workspaceRoot = path.resolve(__dirname, "..");
const cargoFiles = await glob("**/Cargo.toml", {
ignore: ["**/target/**", "**/node_modules/**"],
cwd: workspaceRoot,
absolute: true,
});

let success = true;
for (const cargoFile of cargoFiles) {
console.log(`Checking ${cargoFile}...`);
const content = await fs.readFile(cargoFile, "utf8");

if (!versionRegex.test(content)) {
console.log(` ℹ️ Skipped, does not contain version field`);
continue;
}

// Only update the main version field, not dependencies
const updatedContent = content.replace(versionRegex, `version = "${versionNumber}"`);

if (content === updatedContent) {
const oldVersion = content.match(versionRegex)?.[0];

Check failure on line 43 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

Use the `RegExp#exec()` method instead
console.error(` ❌ Version could not be updated from ${oldVersion} to "${versionNumber}"`);

Check failure on line 44 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

Invalid type "string | undefined" of template literal expression
success = false;
} else {
await fs.writeFile(cargoFile, updatedContent);
console.log(` ✅ Updated version in ${cargoFile} to ${versionNumber}`);
}
}

if (!success) {
console.error("\n❌ Some versions could not be updated");
process.exit(1);
}

// run cargo check
console.log("\nRunning cargo check...");
const cargoCheck = spawn("cargo", ["check"], {
cwd: workspaceRoot,
stdio: "inherit",
});

const exitCode = await new Promise<number>((resolve) => {
cargoCheck.on("close", resolve);
});

if (exitCode !== 0) {
process.exit(exitCode);
}
}

main().catch((err) => {

Check failure on line 73 in scripts/bumpSdkVersion.ts

View workflow job for this annotation

GitHub Actions / typescript

Prefer the safe `: unknown` for a `catch` callback variable
console.error(err);
process.exit(1);
});
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,16 @@ __metadata:
languageName: node
linkType: hard

"@types/glob@npm:^8.1.0":
version: 8.1.0
resolution: "@types/glob@npm:8.1.0"
dependencies:
"@types/minimatch": "npm:^5.1.2"
"@types/node": "npm:*"
checksum: 10c0/ded07aa0d7a1caf3c47b85e262be82989ccd7933b4a14712b79c82fd45a239249811d9fc3a135b3e9457afa163e74a297033d7245b0dc63cd3d032f3906b053f
languageName: node
linkType: hard

"@types/graceful-fs@npm:^4.1.3":
version: 4.1.5
resolution: "@types/graceful-fs@npm:4.1.5"
Expand Down Expand Up @@ -1480,6 +1490,13 @@ __metadata:
languageName: node
linkType: hard

"@types/minimatch@npm:^5.1.2":
version: 5.1.2
resolution: "@types/minimatch@npm:5.1.2"
checksum: 10c0/83cf1c11748891b714e129de0585af4c55dd4c2cafb1f1d5233d79246e5e1e19d1b5ad9e8db449667b3ffa2b6c80125c429dbee1054e9efb45758dbc4e118562
languageName: node
linkType: hard

"@types/node@npm:*, @types/node@npm:>=13.7.0":
version: 17.0.31
resolution: "@types/node@npm:17.0.31"
Expand Down Expand Up @@ -3413,6 +3430,7 @@ __metadata:
"@foxglove/omgidl-parser": "npm:^0.2.0"
"@foxglove/rosmsg": "npm:^4.0.0"
"@foxglove/tsconfig": "npm:2.0.0"
"@types/glob": "npm:^8.1.0"
"@types/jest": "npm:29.5.14"
"@types/node": "npm:22.13.0"
"@typescript-eslint/eslint-plugin": "npm:8.22.0"
Expand All @@ -3426,6 +3444,7 @@ __metadata:
eslint-plugin-import: "npm:2.31.0"
eslint-plugin-jest: "npm:28.11.0"
eslint-plugin-prettier: "npm:5.2.3"
glob: "npm:^10.3.10"
globals: "npm:^15.14.0"
jest: "npm:29.7.0"
prettier: "npm:^3.4.2"
Expand Down

0 comments on commit 7634e49

Please sign in to comment.