-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: OPTIC-489: Enable version.json creation whenever the correspondi…
…ng FE source changes (#5535) * fix: OPTIC-489: Enable version.json creation whenever the corresponding FE source changes * enable versioning against only changed source, run it with sample output. * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8148704358 * enable postbuild * use origin/develop * use different arg syntax * make the version.mjs generator available as a binary and update ci frontend-build.yml to directly use version:affected to ensure other yarn builds do not trigger this. * fix action.yml * fix action.yml * let CI set the base branch * let CI set the base branch * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8156783878 * only fetch develop in addition to the PR branch * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8156904605 * build version on change * remove error and console reporting * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8177622887 * use rev-list and show to get latest affected commit info * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8178473301 * get the log info more accurately * get the log info more accurately * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8178976383 * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8179332128 * checking branch output of log info * updating version script name * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8179543959 * removing unnecessary extra steps just for debug * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8179721910 * update the version.mjs script to be compatible and used within LSE as well * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8196310545 * Removing from docker build step as the committed file version.json is not the one we want, its the release time version.json that we require. * ci: Build frontend Workflow run: https://github.com/HumanSignal/label-studio/actions/runs/8196378391 --------- Co-authored-by: robot-ci-heartex <robot-ci-heartex@users.noreply.github.com> Co-authored-by: bmartel <bmartel@users.noreply.github.com>
- Loading branch information
1 parent
b08b623
commit e0bdde2
Showing
14 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@humansignal/version", | ||
"version": "0.0.1", | ||
"description": "Version generator for internal libraries", | ||
"main": "version.mjs", | ||
"bin": "version", | ||
"license": "MIT", | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
import './version.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import path from 'node:path'; | ||
import {spawn} from 'node:child_process'; | ||
import fs from 'node:fs/promises'; | ||
|
||
const git = async (command, options) => { | ||
// create a promise based git wrapper around a spawned process | ||
return new Promise((resolve, reject) => { | ||
const currentPwd = process.cwd(); | ||
const child = spawn('git', [command, ...options], { | ||
cwd: currentPwd, | ||
stdio: ['ignore', 'pipe', 'pipe'] | ||
}); | ||
let stdout = ''; | ||
let stderr = ''; | ||
|
||
child.stdout.on('data', (data) => { | ||
stdout += data; | ||
}); | ||
|
||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
|
||
child.on('close', (code) => { | ||
if (code === 0) { | ||
resolve(stdout); | ||
} else { | ||
reject(stderr); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the commits affecting the current project | ||
* @param options | ||
* @returns {Promise<string>} | ||
*/ | ||
const gitLog = async (options = []) => { | ||
const log = await git('log', options); | ||
return log.trim(); | ||
} | ||
|
||
/** | ||
* Get the branch info of the current project | ||
* @param options | ||
* @returns {Promise<string>} | ||
*/ | ||
const gitBranch = async (options = []) => { | ||
const branch = await git('branch', options); | ||
return branch.trim(); | ||
} | ||
|
||
|
||
/** | ||
* @typedef {Object} CommitVersion | ||
* @property {string} message - The commit message of the latest commit to affect the current project | ||
* @property {string} commit - The commit hash of the latest commit to affect the current project | ||
* @property {string} date - The date of the latest commit to affect the current project | ||
* @property {string} branch - The current branch | ||
*/ | ||
|
||
/** | ||
* Get the last commit data to have affected the current project | ||
* @returns {Promise<CommitVersion>} | ||
*/ | ||
const getVersionData = async () => { | ||
const latestCommitInfo = await gitLog(['-n 1', '-p', 'src/*']); | ||
const commitInfo = latestCommitInfo.split('\n'); | ||
let commit = commitInfo.find((line) => line.startsWith('commit'))?.trim().replace('commit', '').trim() ?? ''; | ||
let date = commitInfo.find((line) => line.startsWith('Date:')) ?? ''; | ||
// First non-empty line after the Date: line is the commit message | ||
let message = commitInfo.slice(commitInfo.indexOf(date) + 1).find((line) => line.trim().length > 0)?.trim() ?? ''; | ||
// Remove the Date: prefix from the date | ||
date = date.replace('Date:', '').trim(); | ||
|
||
// Get the current branch of the latest commit | ||
const contains = (await gitBranch(['--contains', commit])).split('\n') | ||
let branch = (contains.find((line) => line.startsWith('develop') || line.startsWith('*')) ?? '').replace('*', '').trim(); | ||
|
||
if (branch === '' || branch.includes('HEAD')) { | ||
branch = 'develop'; | ||
} | ||
|
||
return { | ||
message, | ||
commit, | ||
date: new Date(date).toISOString(), | ||
branch, | ||
}; | ||
} | ||
|
||
const versionLib = async () => { | ||
const currentPwd = process.cwd(); | ||
// if the currentPwd includes 'node_modules', we are running from within the monorepo package itself | ||
// and we have to account for the difference | ||
let workspaceRoot, currentProjectPath; | ||
if (currentPwd.includes('node_modules')) { | ||
const [_workspaceRoot, nodeModulesPath, _currentProjectPath] = currentPwd.split('web') | ||
workspaceRoot = path.join(_workspaceRoot, 'web', nodeModulesPath) | ||
currentProjectPath = _currentProjectPath | ||
} else { | ||
const [_workspaceRoot, _currentProjectPath] = currentPwd.split('web') | ||
workspaceRoot = _workspaceRoot | ||
currentProjectPath = _currentProjectPath | ||
} | ||
const distPath = path.join(workspaceRoot, 'web', 'dist', currentProjectPath) | ||
|
||
try { | ||
await fs.mkdir(distPath, {recursive: true}) | ||
} catch { /* ignore */ | ||
} | ||
|
||
const versionData = await getVersionData(); | ||
const versionJson = JSON.stringify(versionData, null, 2); | ||
const versionFile = path.join(distPath, 'version.json'); | ||
await fs.writeFile(versionFile, versionJson); | ||
} | ||
|
||
versionLib().then(() => { | ||
console.log('Versioning complete'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|