commit 67c82a2422da503a8f8db5c14db54720b95e8091 Author: mtkennerly Date: Fri Jul 10 20:43:29 2020 -0400 Initial commit diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..7f17c6d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{json,md,yaml,yml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml new file mode 100644 index 0000000..f585d87 --- /dev/null +++ b/.github/workflows/main.yaml @@ -0,0 +1,38 @@ +on: + - push + - pull_request + +name: Main + +jobs: + example: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v2 + with: + python-version: '3.7' + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: mtkennerly/dunamai-action@v1 + with: + env-var: MY_VERSION + args: --style semver + - run: echo $MY_VERSION + + complete: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v2 + with: + python-version: '3.7' + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: mtkennerly/dunamai-action@v1 + with: + install: '1.2.0' + env-var: MY_VERSION + command: dunamai from git + args: --style semver + - run: echo $MY_VERSION diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..563e944 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +tmp*/ +.vscode/ +*.tgz +*.log diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d0f1580 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Matthew T. Kennerly (mtkennerly) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e75a78e --- /dev/null +++ b/README.md @@ -0,0 +1,40 @@ +# GitHub Action for Dunamai +This repository provides a GitHub Action that uses +[Dunamai](https://github.com/mtkennerly/dunamai) +to determine a dynamic version from your VCS tags. + +## Inputs +* `install` (optional, default: `"latest"`): + Version of Dunamai to install (e.g., "1.3.0"). + Use the default if you don't need a specific version, + or use "none" if your workflow installs Dunamai by other means. +* `env-var` (optional, default: `""`): + Name of environment variable in which to set the dynamic version. + If this is empty, no environment variable will be set. +* `command` (optional, default: `"dunamai from any"`) + Command to run Dunamai. +* `args` (optional, default: `""`): + Additional arguments to pass to the command. + +## Outputs +* `version`: The dynamic version. + +## Example +```yaml +jobs: + example: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v2 + with: + python-version: '3.7' + - uses: actions/checkout@v2 + with: + # This is necessary so that we have the tags. + fetch-depth: 0 + - uses: mtkennerly/dunamai-action@v1 + with: + env-var: MY_VERSION + args: --style semver + - run: echo $MY_VERSION +``` diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..ca6c045 --- /dev/null +++ b/action.yaml @@ -0,0 +1,32 @@ +name: Dunamai +description: | + Use Dunamai to determine a dynamic version from your VCS tags. + This requires access to Python in the workflow. +inputs: + install: + description: | + Version of Dunamai to install (e.g., "1.3.0"). + Use the default if you don't need a specific version, + or use "none" if your workflow installs Dunamai by other means. + required: false + default: latest + env-var: + description: | + Name of environment variable in which to set the dynamic version. + If this is empty, no environment variable will be set. + required: false + default: '' + command: + description: Command to run Dunamai. + required: false + default: 'dunamai from any' + args: + description: Additional arguments to pass to the command. + required: false + default: '' +outputs: + version: + description: The dynamic version. +runs: + using: node12 + main: index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..0d5c51f --- /dev/null +++ b/index.js @@ -0,0 +1,37 @@ +const core = require("@actions/core"); +const { execSync } = require("child_process"); + +function runCommand(command) { + console.log(`Running command: ${command}`); + return execSync(command); +} + +function main() { + const install = core.getInput("install"); + const envVar = core.getInput("env-var"); + const command = core.getInput("command"); + const args = core.getInput("args"); + + if (dunamaiVersion === "none") { + // No install. + } else if (dunamaiVersion === "latest") { + runCommand("pip install dunamai"); + } else { + runCommand(`pip install dunamai==${dunamaiVersion}`); + } + + const version = runCommand(`${command} ${args}`).toString(); + core.setOutput("version", version); + console.log(`Dynamic version: ${version}`); + + if (envVar !== "") { + console.log(`Setting environment variable: ${envVar}`); + core.exportVariable(envVar, version); + } +} + +try { + main(); +} catch (error) { + core.setFailed(error.message); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..01f65eb --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "dunamai-action", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@actions/core": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz", + "integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ad88e12 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "dunamai-action", + "version": "1.0.0", + "description": "", + "main": "index.js", + "keywords": [], + "author": "", + "license": "MIT", + "dependencies": { + "@actions/core": "^1.2.4" + }, + "devDependencies": {} +}