Skip to content

Commit

Permalink
Fix daily-cron failing to bump version (#7129)
Browse files Browse the repository at this point in the history
* Fix daily-cron failing to bump version

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix variable name

Signed-off-by: Sebastian Malton <sebastian@malton.name>

---------

Signed-off-by: Sebastian Malton <sebastian@malton.name>
  • Loading branch information
Nokel81 committed Feb 13, 2023
1 parent c575c7a commit f678bf4
Show file tree
Hide file tree
Showing 7 changed files with 1,011 additions and 5 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/daily-alpha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:

- name: Install deps
run: |
npm i --location=global semver
npm install
yarn install
sudo apt-get install -y ripgrep
cd packages/bump-version-for-cron && yarn build
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version
id: version
run: npm run bump-version-for-cron
run: |
node packages/bump-version-for-cron/dist/index.js --path lerna.json
- name: Check if branch already exists
id: check-branch
run: git ls-remote --exit-code --tags origin v${{ steps.version.outputs.VERSION }}
Expand Down Expand Up @@ -81,7 +81,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "npm"
registry-url: "https://npm.pkg.github.com"
- name: Build package
shell: bash
Expand Down
2 changes: 2 additions & 0 deletions packages/bump-version-for-cron/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
9 changes: 9 additions & 0 deletions packages/bump-version-for-cron/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript"
},
"target": "es2022"
}
}
31 changes: 31 additions & 0 deletions packages/bump-version-for-cron/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@k8slens/bump-version-for-cron",
"version": "6.4.0-cron.4db172da60",
"description": "CLI to bump the version to during a cron daily alpha release",
"license": "MIT",
"scripts": {
"clean": "rimraf dist/",
"build": "swc ./src/index.ts -d ./dist"
},
"type": "module",
"bin": "./dist/index.js",
"files": [
"dist"
],
"private": false,
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"dependencies": {
"arg": "^5.0.2",
"semver": "^7.3.8"
},
"devDependencies": {
"@swc/cli": "^0.1.61",
"@swc/core": "^1.3.32",
"@types/node": "^16.18.11",
"@types/semver": "^7.3.13",
"rimraf": "^4.1.2"
}
}
56 changes: 56 additions & 0 deletions packages/bump-version-for-cron/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as child_process from "child_process";
import { readFile, writeFile } from "fs/promises";
import semver from "semver";
import { promisify } from "util";
import arg from "arg";

const { SemVer } = semver;

const exec = promisify(child_process.exec);

const args = arg({
"--path": String,
});

const versionJsonPath = args["--path"];

if (!versionJsonPath) {
throw new Error("Missing required '--path'");
}

try {
const packageJson = JSON.parse(await readFile(versionJsonPath, "utf-8"));

const { stdout: gitRevParseOutput } = await exec("git rev-parse --short HEAD");
const currentHash = gitRevParseOutput.trim();

const currentVersion = new SemVer(packageJson.version);

const partialVersion = `${currentVersion.major}.${currentVersion.minor}.${currentVersion.patch}`;
const prereleasePart = `cron.${currentHash}`;
const newVersion = `${partialVersion}-${prereleasePart}`;

await writeFile(
versionJsonPath,
JSON.stringify(
{
...packageJson,
version: newVersion,
},
null,
2,
),
);

if (process.env.GITHUB_OUTPUT) {
await writeFile(process.env.GITHUB_OUTPUT, `VERSION=${newVersion}`, {
flag: "a+",
});
}

await exec(`yarn run bump-version --yes ${newVersion}`);
} catch (error) {
console.error(error);
process.exit(1);
}

19 changes: 19 additions & 0 deletions packages/bump-version-for-cron/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"outDir": "dist/",
"paths": {
"*": [
"node_modules/*",
"types/*"
]
},
},
"include": [
"src/**/*",
],
"exclude": [
"node_modules",
]
}

0 comments on commit f678bf4

Please sign in to comment.