Skip to content

Commit

Permalink
auto update version
Browse files Browse the repository at this point in the history
  • Loading branch information
jigsawye committed Nov 10, 2024
1 parent 592644f commit 5d12894
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
id: changesets
uses: changesets/action@v1
with:
version: node .github/workflows/version.js
publish: |
pnpm publish -r
cargo publish
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'fs';
import { exec } from 'child_process';

// read changesets version info
async function getNewVersion() {
return new Promise((resolve, reject) => {
exec('node_modules/.bin/changeset status', (error, stdout) => {
if (error) {
reject(error);
return;
}

const versionMatch = stdout.match(/Version: (.+)/);
if (versionMatch) {
resolve(versionMatch[1].trim());
} else {
resolve(null);
}
});
});
}

async function main() {
const newVersion = await getNewVersion();
if (!newVersion) return;

// read Cargo.toml
const cargoPath = './Cargo.toml';
let cargoContent = fs.readFileSync(cargoPath, 'utf8');

// update version
cargoContent = cargoContent.replace(
/version = "(.*?)"/,
`version = "${newVersion}"`
);

// write back to file
fs.writeFileSync(cargoPath, cargoContent);
}

main().catch(console.error);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "swagit-workspace",
"version": "0.0.0",
"private": true,
"type": "module",
"description": "A swag tool to use git with interactive cli",
"author": "Evan Ye <jigsaw.ye@gmail.com>",
"license": "MIT",
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::process;

fn main() {
let matches = Command::new("swagit")
.version("1.0.0")
.author("Evan Ye <jigsaw.ye@gmail.com>")
.about("A swag tool to use git with interactive cli")
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.arg(
Arg::new("delete")
.short('d')
Expand Down

0 comments on commit 5d12894

Please sign in to comment.