8000 Implement additional flags - `nocache`, `nonormalize`, `overrideconfig` by arturcic · Pull Request #1056 · GitTools/actions · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement additional flags - nocache, nonormalize, overrideconfig #1056

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

Merged
merged 3 commits into from
Mar 3, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .azure/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ jobs:
node ./gitversion/setup/bundle.js
displayName: gitversion/setup
workingDirectory: dist/azure
- pwsh: node ./gitversion/execute/bundle.js
- pwsh: |
# set the inputs for the 'gitversion/execute' action
$env:INPUT_TARGETPATH = './'
$env:INPUT_DISABLECACHE = 'true'
$env:INPUT_DISABLENORMALIZATION = 'true'
$env:INPUT_OVERRIDECONFIG = '
next-version=1.0.0
update-build-number=false'

# run the 'gitversion/execute' action
node ./gitversion/execute/bundle.js
name: version
displayName: gitversion/execute
workingDirectory: dist/azure
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ jobs:
- name: gitversion/execute
id: gitversion # step id used as reference for output values
uses: ./gitversion/execute
with:
targetPath: './'
disableCache: true
disableNormalization: true
overrideConfig: |
next-version=1.0.0
update-build-number=false
- run: |
echo "Major (major) : ${{ env.major }}"
echo "Major (env.GitVersion_Major) : ${{ env.GitVersion_Major }}"
Expand Down
6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/addasset/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/close/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/create/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/discard/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/open/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/publish/bundle.js

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions dist/azure/gitreleasemanager/setup/bundle.js

Large diffs are not rendered by default.

56 changes: 40 additions & 16 deletions dist/azure/gitversion/execute/bundle.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions dist/azure/gitversion/execute/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
"helpMarkDown": "Optionally supply the path to the working directory",
"groupName": "gitversionDetails"
},
{
"name": "disableCache",
"type": "boolean",
"label": "Disable Cache",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to disable GitVersion cache"
},
{
"name": "disableNormalization",
"type": "boolean",
"label": "Disable Normalization",
"defaultValue": "false",
"required": false,
"helpMarkDown": "Whether to disable GitVersion normalization"
},
{
"name": "useConfigFile",
"type": "boolean",
Expand All @@ -65,6 +81,14 @@
"helpMarkDown": "Optional path to config file (defaults to GitVersion.yml)",
"visibleRule": "useConfigFile = true"
},
{
"name": "overrideConfig",
"type": "multiLine",
"label": "Override Configuration",
"defaultValue": "",
"required": false,
"helpMarkDown": "Optional override for the configuration file. This should be newline-separated key-value pairs, e.g.: \n\nupdate-build-number=false\nnext-version=1.0.0"
},
{
"name": "updateAssemblyInfo",
"type": "boolean",
Expand Down
56 changes: 40 additions & 16 deletions dist/azure/gitversion/setup/bundle.js

Large diffs are not rendered by default.

52 changes: 39 additions & 13 deletions dist/github/gitversion/execute/bundle.js

Large diffs are not rendered by default.

52 changes: 39 additions & 13 deletions dist/github/gitversion/setup/bundle.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions gitversion/execute/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ inputs:
description: Optionally supply the path to the working directory
required: false
default: ''
disableCache:
description: Whether to disable GitVersion cache
required: false
default: 'false'
disableNormalization:
description: Whether to disable GitVersion normalization
required: false
default: 'false'
useConfigFile:
description: Whether to use a custom configuration file
required: false
Expand All @@ -20,6 +28,13 @@ inputs:
description: Optional path to config file (defaults to GitVersion.yml)
required: false
default: 'GitVersion.yml'
overrideConfig:
description: |
Optional override for the configuration file. This should be newline-separated key-value pairs, e.g.:
update-build-number=false
next-version=1.0.0
required: false
default: ''
updateAssemblyInfo:
description: Whether to update versions in the AssemblyInfo files
required: false
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"node": ">=20.0.0"
},
"scripts": {
"build": "npm run build:mock && npm run build:azure && npm run build:github",
"build": "npm run build:agent:mock && npm run build:agent:azure && npm run build:agent:github",
"format": "prettier --write src/**/*.ts",
"format-check": "prettier --check src/**/*.ts",
"build:agent:mock": "webpack --config webpack.config.js --env agent=mock",
Expand Down
5 changes: 1 addition & 4 deletions src/agent/azure/build-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ class BuildAgent implements IBuildAgent {
}

public getListInput(input: string, required?: boolean): string[] {
return taskLib
.getInput(input, required)
.split('\n')
.filter(x => x !== '')
return taskLib.getDelimitedInput(input, '\n', required).filter(x => x !== '')
}

public getBooleanInput(input: string, required?: boolean): boolean {
Expand Down
6 changes: 6 additions & 0 deletions src/tools/gitversion/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { ISettingsProvider } from '../common/models'

export enum ExecuteFields {
targetPath = 'targetPath',
disableCache = 'disableCache',
disableNormalization = 'disableNormalization',
useConfigFile = 'useConfigFile',
configFilePath = 'configFilePath',
overrideConfig = 'overrideConfig',
updateAssemblyInfo = 'updateAssemblyInfo',
updateAssemblyInfoFilename = 'updateAssemblyInfoFilename',
additionalArguments = 'additionalArguments',
Expand All @@ -12,8 +15,11 @@ export enum ExecuteFields {

export interface GitVersionSettings {
[ExecuteFields.targetPath]: string
[ExecuteFields.disableCache]: boolean
[ExecuteFields.disableNormalization]: boolean
[ExecuteFields.useConfigFile]: boolean
[ExecuteFields.configFilePath]: string
[ExecuteFields.overrideConfig]: string[]
[ExecuteFields.updateAssemblyInfo]: boolean
[ExecuteFields.updateAssemblyInfoFilename]: string
[ExecuteFields.additionalArguments]: string
Expand Down
7 changes: 7 additions & 0 deletions src/tools/gitversion/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ export class GitVersionSettingsProvider extends SettingsProvider implements IGit
public getGitVersionSettings(): GitVersionSettings {
const targetPath = this.buildAgent.getInput(ExecuteFields.targetPath)

const disableCache = this.buildAgent.getBooleanInput(ExecuteFields.disableCache)
const disableNormalization = this.buildAgent.getBooleanInput(ExecuteFields.disableNormalization)

const useConfigFile = this.buildAgent.getBooleanInput(ExecuteFields.useConfigFile)
const configFilePath = this.buildAgent.getInput(ExecuteFields.configFilePath)
const overrideConfig = this.buildAgent.getListInput(ExecuteFields.overrideConfig)

const updateAssemblyInfo = this.buildAgent.getBooleanInput(ExecuteFields.updateAssemblyInfo)
const updateAssemblyInfoFilename = this.buildAgent.getInput(ExecuteFields.updateAssemblyInfoFilename)
Expand All @@ -25,8 +29,11 @@ export class GitVersionSettingsProvider extends SettingsProvider implements IGit

return {
targetPath,
disableCache,
disableNormalization,
useConfigFile,
configFilePath,
overrideConfig,
updateAssemblyInfo,
updateAssemblyInfoFilename,
additionalArguments,
Expand Down
55 changes: 43 additions & 12 deletions src/tools/gitversion/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { ISetupSettings } from '../common/models'

export interface IGitVersionTool extends IDotnetTool {
install(setupSettings: ISetupSettings): Promise<void>

run(options: GitVersionSettings): Promise<IExecResult>

writeGitVersionToAgent(gitversion: GitVersionOutput): void
}

Expand All @@ -22,16 +24,17 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
}

public run(options: GitVersionSettings): Promise<IExecResult> {
const workDir = this.getRepoDir(options.targetPath)
const workDir = this.getRepoDir(options)

const args = this.getArguments(workDir, options)

return this.execute('dotnet-gitversion', args)
}

private getRepoDir(targetPath: string): string {
private getRepoDir(options: GitVersionSettings): string {
const targetPath = options.targetPath
const srcDir = options.srcDir || '.'
let workDir: string
const srcDir = this.buildAgent.getSourceDir() || '.'
if (!targetPath) {
workDir = srcDir
} else {
Expand All @@ -47,7 +50,25 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
private getArguments(workDir: string, options: GitVersionSettings): string[] {
let args = [workDir, '/output', 'json', '/output', 'buildserver']

const { useConfigFile, configFilePath, updateAssemblyInfo, updateAssemblyInfoFilename, additionalArguments } = options
const {
useConfigFile,
disableCache,
disableNormalization,
configFilePath,
overrideConfig,
updateAssemblyInfo,
updateAssemblyInfoFilename,
additionalArguments
//
} = options

if (disableCache) {
args.push('/nocache')
}

if (disableNormalization) {
args.push('/nonormalize')
}

if (useConfigFile) {
if (this.buildAgent.isValidInputFile('configFilePath', configFilePath)) {
Expand All @@ -56,6 +77,16 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
throw new Error('GitVersion configuration file not found at ' + configFilePath)
}
}

if (overrideConfig) {
overrideConfig.forEach(config => {
config = config.trim()
if (config.match(/([a-zA-Z0-9]+(-[a-zA-Z]+)*=[a-zA-Z0-9\- :.']*)/)) {
args.push('/overrideconfig', config)
}
})
}

if (updateAssemblyInfo) {
args.push('/updateassemblyinfo')

Expand Down Expand Up @@ -93,14 +124,14 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
}

private argStringToArray(argString: string): string[] {
var args: string[] = []
const args: string[] = []

var inQuotes = false
var escaped = false
var lastCharWasSpace = true
var arg = ''
let inQuotes = false
let escaped = false
let lastCharWasSpace = true
let arg = ''

var append = function (c: string) {
const append = function (c: string) {
// we only escape double quotes.
if (escaped && c !== '"') {
arg += '\\'
Expand All @@ -110,8 +141,8 @@ export class GitVersionTool extends DotnetTool implements IGitVersionTool {
escaped = false
}

for (var i = 0; i < argString.length; i++) {
var c = argString.charAt(i)
for (let i = 0; i < argString.length; i++) {
const c = argString.charAt(i)

if (c === ' ' && !inQuotes) {
if (!lastCharWasSpace) {
Expand Down
0