Skip to content

Commit

Permalink
updated github actioning & versioning script
Browse files Browse the repository at this point in the history
  • Loading branch information
CEbbinghaus committed Feb 15, 2024
1 parent 6023962 commit b0f320b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Update Version
run: |
echo -n "-$(git rev-parse --short HEAD)" >> backend/version && \
node util/updateVersion.js package.json lib/package.json
node util/versioning.mjs update package.json lib/package.json
- name: Download Decky CLI
run: |
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Update Version
run: |
echo -n "-$(git rev-parse --short HEAD)" >> backend/version && \
node util/updateVersion.js package.json lib/package.json
node util/versioning.mjs update package.json lib/package.json
- uses: actions/setup-node@v3
with:
Expand Down
5 changes: 2 additions & 3 deletions util/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { execSync, spawnSync } from 'child_process';
import { join, resolve } from 'path';
import { existsSync, mkdirSync, copyFileSync, statfsSync } from 'fs';
import { ReadPackageVersion, UpdateVersion, ResetVersion } from './versioning.mjs';
import { Version, UpdateVersion, ResetVersion } from './versioning.mjs';
import { Logger } from './log.mjs';
import { exit } from 'process';

Expand All @@ -29,9 +29,8 @@ async function importJson(file) {
}

const { name: PluginName } = await importJson(join(basePath, "plugin.json"));
const pluginVersion = ReadPackageVersion();

Logger.Log(`Building plugin ${PluginName}@${pluginVersion}`);
Logger.Log(`Building plugin ${PluginName}@${Version}`);

if (!existsSync('plugin.json')) {
console.error('Build script must be run from the root of the repository.');
Expand Down
35 changes: 26 additions & 9 deletions util/versioning.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import { readFileSync, writeFileSync } from "fs";
import { dirname, resolve } from "path";
import { fileURLToPath } from "url";


let ReadPackageVersionCache = null;
export function ReadPackageVersion() {
ReadPackageVersionCache = ReadPackageVersionCache ?? readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../backend/version"), { encoding: "utf8" });
return ReadPackageVersionCache;
export const Version = ReadPackageVersion();
function ReadPackageVersion() {
return readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), "../backend/version"), { encoding: "utf8" });
}

function WriteVersionToPackage(file, version) {
const pkg = JSON.parse(readFileSync(file));
pkg.version = version;
writeFileSync(file, JSON.stringify(pkg, null, " "));

}

/**
Expand All @@ -32,10 +29,30 @@ export function ResetVersion(...packages) {
* @param {...string} packages
*/
export function UpdateVersion(...packages) {
const version = ReadPackageVersion();

for (let pkg of packages || ["package.json"]) {
const packagePath = resolve(pkg);
WriteVersionToPackage(packagePath, version);
WriteVersionToPackage(packagePath, Version);
}
}
if (process.argv[1] === fileURLToPath(import.meta.url)) {
// The script was run directly.

let files = process.argv.slice(3);
if (files.length == 0) {
files = ["package.json"];
}

switch (process.argv[2]) {
case "reset":
console.log(`Resetting ${files.join(", ")}`);
ResetVersion(...files);
break;
case "update":
console.log(`Updating ${files.join(", ")} to version ${Version}`);
UpdateVersion(...files);
break;
default:
console.log("Invalid argument provided. Must be one of 'reset' | 'update'");
process.exit(1);
}
}

0 comments on commit b0f320b

Please sign in to comment.