Skip to content

Commit

Permalink
Allow to pass tag name (#3)
Browse files Browse the repository at this point in the history
* Add latestTagName input

* Use latestTagName input for tag creation

* Add documentation of `tag-name` input

* Update action.yml

* Update action.ts

* Update README.md

* Update action.yml

Co-authored-by: Federico Grandi <fgrandi30@gmail.com>
  • Loading branch information
DocX and EndBug committed Apr 14, 2020
1 parent d0a1248 commit 723fbf9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ That's why I made this action: if you're the kind of guy that doesn't like to up

These are the parameters you can use with the action:

- `description`: [optional] Tag description. Providing a value will result in the creation of an **annotated tag**; if no value is enterd, the action will create a **lightweight tag**.
- `tag-name`: [optional] Tag name. Specify the name of tag that will be created or updated (default is `latest`).
- `description`: [optional] Tag description. Providing a value will result in the creation of an **annotated tag**; if no value is entered, the action will create a **lightweight tag**.

## Usage

Expand All @@ -36,6 +37,7 @@ jobs:
uses: EndBug/latest-tag@latest
with:
description: Description for the tag
tag-name: latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this line unchanged
```
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ inputs:
description:
description: "Tag description"
required: false
tag-name:
description: "Tag name"
required: false
13 changes: 7 additions & 6 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ function isRelease() {
&& context.payload.release?.tag_name != null
}

function annotatedTag(message: string) {
function annotatedTag(message: string, tagName: string) {
info('Creating annotated tag...')
return exec(`git tag -a -f -m "${message}" latest`)
return exec(`git tag -a -f -m "${message}" ${tagName}`)
}

function lightweightTag() {
function lightweightTag(tagName: string) {
info('Creating lightweight tag...')
return exec(`git tag -f latest`)
return exec(`git tag -f ${tagName}`)
}

async function run() {
Expand All @@ -40,9 +40,10 @@ async function run() {
await exec(`git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"`)

const message = getInput('description')
const tagName = getInput('tag-name') || "latest"

if (message) await annotatedTag(message)
else await lightweightTag()
if (message) await annotatedTag(message, tagName)
else await lightweightTag(tagName)

info('Pushing updated tag to repo...')
return await exec('git push --force --tags')
Expand Down

0 comments on commit 723fbf9

Please sign in to comment.