From 6c0ec331a3ea8df2c3e77d0c0b78f39c9a354c0f Mon Sep 17 00:00:00 2001 From: Leo Botinelly Date: Sun, 15 Mar 2020 23:22:54 -0400 Subject: [PATCH] Add VERSION_STATIC for external version resolution External version resolution (#17) --- README.md | 2 ++ action.yml | 3 +++ index.js | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 340f7cd..c908a07 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ jobs: PROJECT_FILE_PATH: Core/Core.csproj # Relative to repository root # VERSION_FILE_PATH: Directory.Build.props # Filepath with version info, relative to repository root. Defaults to project file # VERSION_REGEX: (.*)<\/Version> # Regex pattern to extract version info in a capturing group + # VERSION_STATIC: Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning # TAG_COMMIT: true # Flag to enable / disalge git tagging # TAG_FORMAT: v* # Format of the git tag, [*] gets replaced with version # NUGET_KEY: ${{secrets.NUGET_API_KEY}} # nuget.org API key @@ -48,6 +49,7 @@ Input | Default Value | Description PROJECT_FILE_PATH | | File path of the project to be packaged, relative to repository root VERSION_FILE_PATH | `[PROJECT_FILE_PATH]` | File path containing version info, relative to repository root VERSION_REGEX | `(.*)<\/Version>` | Regex pattern to extract version info in a capturing group +VERSION_STATIC| | Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning TAG_COMMIT | `true` | Flag to enable / disable git tagging TAG_FORMAT | `v*` | `[*]` is a placeholder for the actual project version NUGET_KEY | | API key to authorize the package upload to nuget.org diff --git a/action.yml b/action.yml index 4c0504f..91dfe42 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: description: Regex (with version in a capturing group) to extract the version from `VERSION_FILE_PATH` required: false default: (.*)<\/Version> + VERSION_STATIC: + description: Bypasses version resolution; useful for external providers like Nerdbank.GitVersioning + required: false TAG_COMMIT: description: Whether to create a tag when there's a version change required: false diff --git a/index.js b/index.js index 5ddd723..92d6fc9 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ class Action { this.PROJECT_FILE_PATH = process.env.INPUT_PROJECT_FILE_PATH this.VERSION_FILE_PATH = process.env.INPUT_VERSION_FILE_PATH || process.env.VERSION_FILE_PATH this.VERSION_REGEX = new RegExp(process.env.INPUT_VERSION_REGEX || process.env.VERSION_REGEX) + this.VERSION_STATIC = process.env.INPUT_VERSION_STATIC || process.env.VERSION_STATIC this.TAG_COMMIT = JSON.parse(process.env.INPUT_TAG_COMMIT || process.env.TAG_COMMIT) this.TAG_FORMAT = process.env.INPUT_TAG_FORMAT || process.env.TAG_FORMAT this.NUGET_KEY = process.env.INPUT_NUGET_KEY || process.env.NUGET_KEY @@ -85,17 +86,22 @@ class Action { run() { if (!this.PROJECT_FILE_PATH) this._fail("😭 project file not given") - this.PROJECT_FILE_PATH = this._resolveIfExists(this.PROJECT_FILE_PATH, "😭 project file not found") - this.VERSION_FILE_PATH = !this.VERSION_FILE_PATH ? this.PROJECT_FILE_PATH : this._resolveIfExists(this.VERSION_FILE_PATH, "😭 version file not found") + + let CURRENT_VERSION = "" + + if (!this.VERSION_STATIC) { + this.VERSION_FILE_PATH = !this.VERSION_FILE_PATH ? this.PROJECT_FILE_PATH : this._resolveIfExists(this.VERSION_FILE_PATH, "😭 version file not found") - const FILE_CONTENT = fs.readFileSync(this.VERSION_FILE_PATH, { encoding: "utf-8" }), - VERSION_INFO = this.VERSION_REGEX.exec(FILE_CONTENT) + const FILE_CONTENT = fs.readFileSync(this.VERSION_FILE_PATH, { encoding: "utf-8" }), + VERSION_INFO = this.VERSION_REGEX.exec(FILE_CONTENT) - if (!VERSION_INFO) - this._fail("😢 unable to extract version info") + if (!VERSION_INFO) + this._fail("😢 unable to extract version info!") - const CURRENT_VERSION = VERSION_INFO[1] + CURRENT_VERSION = VERSION_INFO[1] + } else + CURRENT_VERSION = this.VERSION_STATIC if (!this.PACKAGE_NAME) this.PACKAGE_NAME = path.basename(this.PROJECT_FILE_PATH).split(".").slice(0, -1).join(".")