Skip to content
This repository was archived by the owner on Oct 26, 2022. It is now read-only.

Commit 6c0ec33

Browse files
author
Leo Botinelly
authored
Add VERSION_STATIC for external version resolution
External version resolution (#17)
1 parent 5fdc86f commit 6c0ec33

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
PROJECT_FILE_PATH: Core/Core.csproj # Relative to repository root
3232
# VERSION_FILE_PATH: Directory.Build.props # Filepath with version info, relative to repository root. Defaults to project file
3333
# VERSION_REGEX: <Version>(.*)<\/Version> # Regex pattern to extract version info in a capturing group
34+
# VERSION_STATIC: Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning
3435
# TAG_COMMIT: true # Flag to enable / disalge git tagging
3536
# TAG_FORMAT: v* # Format of the git tag, [*] gets replaced with version
3637
# NUGET_KEY: ${{secrets.NUGET_API_KEY}} # nuget.org API key
@@ -48,6 +49,7 @@ Input | Default Value | Description
4849
PROJECT_FILE_PATH | | File path of the project to be packaged, relative to repository root
4950
VERSION_FILE_PATH | `[PROJECT_FILE_PATH]` | File path containing version info, relative to repository root
5051
VERSION_REGEX | `<Version>(.*)<\/Version>` | Regex pattern to extract version info in a capturing group
52+
VERSION_STATIC| | Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning
5153
TAG_COMMIT | `true` | Flag to enable / disable git tagging
5254
TAG_FORMAT | `v*` | `[*]` is a placeholder for the actual project version
5355
NUGET_KEY | | API key to authorize the package upload to nuget.org

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
description: Regex (with version in a capturing group) to extract the version from `VERSION_FILE_PATH`
1414
required: false
1515
default: <Version>(.*)<\/Version>
16+
VERSION_STATIC:
17+
description: Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning
18+
required: false
1619
TAG_COMMIT:
1720
description: Whether to create a tag when there's a version change
1821
required: false

index.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Action {
88
this.PROJECT_FILE_PATH = process.env.INPUT_PROJECT_FILE_PATH
99
this.VERSION_FILE_PATH = process.env.INPUT_VERSION_FILE_PATH || process.env.VERSION_FILE_PATH
1010
this.VERSION_REGEX = new RegExp(process.env.INPUT_VERSION_REGEX || process.env.VERSION_REGEX)
11+
this.VERSION_STATIC = process.env.INPUT_VERSION_STATIC || process.env.VERSION_STATIC
1112
this.TAG_COMMIT = JSON.parse(process.env.INPUT_TAG_COMMIT || process.env.TAG_COMMIT)
1213
this.TAG_FORMAT = process.env.INPUT_TAG_FORMAT || process.env.TAG_FORMAT
1314
this.NUGET_KEY = process.env.INPUT_NUGET_KEY || process.env.NUGET_KEY
@@ -85,17 +86,22 @@ class Action {
8586
run() {
8687
if (!this.PROJECT_FILE_PATH)
8788
this._fail("😭 project file not given")
88-
8989
this.PROJECT_FILE_PATH = this._resolveIfExists(this.PROJECT_FILE_PATH, "😭 project file not found")
90-
this.VERSION_FILE_PATH = !this.VERSION_FILE_PATH ? this.PROJECT_FILE_PATH : this._resolveIfExists(this.VERSION_FILE_PATH, "😭 version file not found")
90+
91+
let CURRENT_VERSION = ""
92+
93+
if (!this.VERSION_STATIC) {
94+
this.VERSION_FILE_PATH = !this.VERSION_FILE_PATH ? this.PROJECT_FILE_PATH : this._resolveIfExists(this.VERSION_FILE_PATH, "😭 version file not found")
9195

92-
const FILE_CONTENT = fs.readFileSync(this.VERSION_FILE_PATH, { encoding: "utf-8" }),
93-
VERSION_INFO = this.VERSION_REGEX.exec(FILE_CONTENT)
96+
const FILE_CONTENT = fs.readFileSync(this.VERSION_FILE_PATH, { encoding: "utf-8" }),
97+
VERSION_INFO = this.VERSION_REGEX.exec(FILE_CONTENT)
9498

95-
if (!VERSION_INFO)
96-
this._fail("😢 unable to extract version info")
99+
if (!VERSION_INFO)
100+
this._fail("😢 unable to extract version info!")
97101

98-
const CURRENT_VERSION = VERSION_INFO[1]
102+
CURRENT_VERSION = VERSION_INFO[1]
103+
} else
104+
CURRENT_VERSION = this.VERSION_STATIC
99105

100106
if (!this.PACKAGE_NAME)
101107
this.PACKAGE_NAME = path.basename(this.PROJECT_FILE_PATH).split(".").slice(0, -1).join(".")

0 commit comments

Comments
 (0)