Initial commit

This commit is contained in:
mtkennerly 2020-07-10 20:43:29 -04:00
commit 67c82a2422
10 changed files with 210 additions and 0 deletions

10
.editorconfig Normal file
View file

@ -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

1
.gitattributes vendored Normal file
View file

@ -0,0 +1 @@
* text=auto

38
.github/workflows/main.yaml vendored Normal file
View file

@ -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

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
node_modules/
tmp*/
.vscode/
*.tgz
*.log

21
LICENSE Normal file
View file

@ -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.

40
README.md Normal file
View file

@ -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
```

32
action.yaml Normal file
View file

@ -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

37
index.js Normal file
View file

@ -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);
}

13
package-lock.json generated Normal file
View file

@ -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=="
}
}
}

13
package.json Normal file
View file

@ -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": {}
}