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

Commit

Permalink
Add VERSION_STATIC for external version resolution
Browse files Browse the repository at this point in the history
External version resolution (#17)
  • Loading branch information
Leo Botinelly authored Mar 16, 2020
1 parent 5fdc86f commit 6c0ec33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>(.*)<\/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
Expand All @@ -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>(.*)<\/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
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
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
Expand Down
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(".")
Expand Down

0 comments on commit 6c0ec33

Please sign in to comment.