Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Nov 1, 2020
0 parents commit f54689c
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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: ./
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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: [email protected]`)
- Exact version (`uses: [email protected]`)

## Inputs

None.

## License

[MIT](LICENSE)
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Additional Tags
description: Create major and minor git tags from the last tag
runs:
using: node12
main: index.js
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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', '[email protected]'])
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)
}

0 comments on commit f54689c

Please sign in to comment.