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 7, 2025
1 parent 48791a0 commit 7c1695c
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
exclude:
authors:
- dependabot
labels:
- ignore-for-changelog
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on:
push:
branches: [main]
tags: ["**"]
pull_request:
branches: ["*"]
pull_request: {}

jobs:
rust:
Expand Down Expand Up @@ -33,7 +32,7 @@ jobs:
timeout-minutes: 10
- run: cargo publish --package foxglove --dry-run
- run: cargo publish --package foxglove
if: startsWith(github.ref, 'refs/tags/rust/v')
if: startsWith(github.ref, 'refs/tags/sdk/v')
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Draft Release

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

env:
SDK_VERSION: ${{ github.event.inputs.version || 'v0.2.0' }}
SDK_TAG: sdk/${{ github.event.inputs.version || 'v0.2.0' }}
SDK_BRANCH: release/sdk/${{ github.event.inputs.version || 'v0.2.0' }}

jobs:
draft:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # needed to get the previous release tag

- run: corepack enable

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

- name: Check for existing ${{ env.SDK_TAG }} release
env:
GH_TOKEN: ${{ github.token }}
run: |
if gh release view "${{ env.SDK_TAG }}" --json "name,url"; then
echo "Release ${SDK_TAG} already exists!"
exit 1
fi
- run: yarn install --immutable
- run: yarn bump-sdk-version "${{ env.SDK_VERSION }}"

- name: Detect previous version
id: previous-release
run: |
tag=$(git describe --tags --abbrev=0 --match "sdk/v*")
echo "tag=$tag" | tee -a $GITHUB_OUTPUT
- name: Commit and push branch
run: |
git config user.name "Foxglove"
git config user.email "[email protected]"
git checkout -b "${{ env.SDK_BRANCH }}"
git add .
git commit -m "Release SDK version ${{ env.SDK_VERSION }}"
git push -f origin "${{ env.SDK_BRANCH }}"
- name: Create draft release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "${{ env.SDK_TAG }}" \
--title "${{ env.SDK_TAG }}" \
--target "${{ env.SDK_BRANCH }}" \
--generate-notes \
--notes-start-tag "${{ steps.previous-release.outputs.tag }}" \
--draft
27 changes: 27 additions & 0 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Post Release

on:
release:
types: [released]

env:
SDK_TAG: ${{ github.event.release.tag_name }}

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.SDK_TAG }}
fetch-depth: 0

- name: Git merge into main
run: |
git config user.name "Foxglove"
git config user.email "[email protected]"
git checkout -b main --track origin/main
git merge --no-ff ${{ github.ref }}
git push origin main
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ jobs:
# them unless the maturin API changes substantially.
release:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/python/foxglove-sdk/v')
if: startsWith(github.ref, 'refs/tags/sdk/v')
needs: [linux, musllinux, windows, macos, sdist]
permissions:
id-token: write
Expand Down
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
"reportUnusedDisableDirectives": "error"
},
"jest.jestCommandLine": "yarn test",

"python.analysis.typeCheckingMode": "strict",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
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 { spawn } from "child_process";
import fs from "fs/promises";
import { glob } from "glob";
import path from "path";

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

async function main() {
const newVersion = process.argv[2];
if (newVersion?.startsWith("v") !== true) {
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 = versionRegex.exec(content)?.[0] ?? '""';
console.error(` ❌ Version could not be updated from ${oldVersion} to "${versionNumber}"`);
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: unknown) => {
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 7c1695c

Please sign in to comment.