Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix daily-cron failing to bump version #7129

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did this come from before?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came from the extensions which have this as a script instead of a package.

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",
]
}