Skip to content

Commit

Permalink
chore: Update Rust dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed May 13, 2024
1 parent 2ff0c2e commit c172207
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 76 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/update-deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,22 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Do updates
run: |
{
echo 'PR_BODY<<EOF'
node ./.github/workflows/update_deps.mjs
node ./.github/workflows/update_deps.mjs ${{ steps.detect_open_pr.outputs.result }}
echo EOF
} >> $GITHUB_ENV
- name: Cargo update
run: cargo update

- name: Open PR
if: steps.detect_open_pr.outputs.result == 'main'
uses: peter-evans/create-pull-request@v6
Expand Down
22 changes: 21 additions & 1 deletion .github/workflows/update_deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { resolve, basename, join, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readdir, readFile, writeFile } from 'node:fs/promises';

const isNewPr = process.argv[2] === 'main';

export async function getUpdates() {
const projectRoot = resolve(fileURLToPath(import.meta.url), '../../..');
const templateRoot = join(projectRoot, 'template_builder/templates');
Expand Down Expand Up @@ -34,6 +36,23 @@ export async function getUpdates() {
return dirty;
}

if (isNewPr) {
const cargoTomlPath = join(projectRoot, 'Cargo.toml');
const cargoToml = await readFile(cargoTomlPath, 'utf8');
const version = cargoToml.match(/version = "(.*)"/)?.[1];
if (!version) {
console.error('Could not find version in Cargo.toml');
process.exit(1);
}
const [major, minor, patch] = version.split('.');
const newVersion = `${major}.${minor}.${parseInt(patch) + 1}`;
await writeFile(
cargoTomlPath,
cargoToml.replace(/version = "(.*)"/, `version = "${newVersion}"`),
);
console.log(`_Bumped version to ${newVersion}_\n\n`);
}

for await (const f of getFiles(templateRoot)) {
if (!/^(\{[^{}]*\})?package\.json$/.test(basename(f))) continue;
const pkg = JSON.parse(await readFile(f, 'utf8'));
Expand All @@ -54,7 +73,6 @@ export async function getUpdates() {
}
}

getUpdates();
async function latestVersion(packageName, tag) {
const url = new URL(
encodeURIComponent(packageName).replace(/^%40/, '@'),
Expand All @@ -81,3 +99,5 @@ async function* getFiles(dir) {
}
}
}

getUpdates();
Loading

0 comments on commit c172207

Please sign in to comment.