From f54689cf358d5368ed738306a414a3b020957296 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 1 Nov 2020 22:58:02 +0100 Subject: [PATCH] Initial --- .github/workflows/release.yml | 10 +++++++++ LICENSE | 19 +++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++ action.yml | 5 +++++ index.js | 28 +++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100644 index.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8734d39 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,10 @@ +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ./ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d13cc4b --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +The MIT License (MIT) + +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..10e8cfc --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ +# additional-tags-action + +**A [GitHub Action](https://github.com/features/actions) to create major and minor git tags from the last tag.** + +![GitHub tag](https://img.shields.io/github/v/tag/vweevers/additional-tags-action?sort=semver) +[![License](https://img.shields.io/github/license/vweevers/additional-tags-action)](LICENSE) + +## Usage + +```yaml +on: + push: + tags: + - v[0-9]+.[0-9]+.[0-9]+ +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: vweevers/additional-tags-action@v1 +``` + +If your tag is `v2.4.8` (for example) then this action will create 2 additional tags (`v2` and `v2.4`) and push them to GitHub, replacing existing tags. If the tag is a prerelease (not x.x.x) or not prefixed with `v` then nothing happens. + +## Why + +Useful to release actions. Consumers of your action can now pin to either a: + +- Major version (`uses: my-action@v2`) +- Minor version (`uses: my-action@v2.4`) +- Exact version (`uses: my-action@v2.4.8`) + +## Inputs + +None. + +## License + +[MIT](LICENSE) diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..66f46c9 --- /dev/null +++ b/action.yml @@ -0,0 +1,5 @@ +name: Additional Tags +description: Create major and minor git tags from the last tag +runs: + using: node12 + main: index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..e5f88b0 --- /dev/null +++ b/index.js @@ -0,0 +1,28 @@ +'use strict' + +const { execFileSync } = require('child_process') + +try { + const maxBuffer = 1024 * 1024 * 16 + const tags = execFileSync('git', ['tag'], { maxBuffer, encoding: 'utf8' }) + const tag = tags.split(/\r?\n/).filter(Boolean).pop() + + if (!tag) { + // Nothing to do + } else if (!/^v\d+\.\d+\.\d+$/.test(tag)) { + console.log('Skipping tag %s', tag) + } else { + const [major, minor] = tag.slice(1).split('.') + const majorTag = 'v' + major + const minorTag = 'v' + major + '.' + minor + + execFileSync('git', ['config', 'user.name', 'github-actions']) + execFileSync('git', ['config', 'user.email', 'github-actions@github.com']) + execFileSync('git', ['tag', '-fa', majorTag, '-m', majorTag]) + execFileSync('git', ['tag', '-fa', minorTag, '-m', minorTag]) + execFileSync('git', ['push', '--tags', '-f']) + } +} catch (err) { + console.log('::error::%s', err.message || String(err)) + process.exit(1) +}