Skip to content

Commit

Permalink
Add token input option
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Sep 8, 2022
1 parent ef2a802 commit 1b162d4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Add `token` input option to use the specified token instead of `GITHUB_TOKEN` environment variable.

- Update `parse-changelog` to 0.5.1. This includes a bug fix and performance improvements.

## [1.5.0] - 2022-02-17
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ Currently, changelog format and supported tag names have the following rule:

### Inputs

| Name | Required | Description | Type | Default |
|-----------|:--------:|-----------------------------------------------------------------------------|---------|---------|
| changelog | false | Path to changelog (variables `$tag`, `$version`, `$prefix`, and any string) | String | |
| title | false | Format of title (variables `$tag`, `$version`, `$prefix`, and any string) | String | `$tag` |
| draft | false | Create a draft release (`true` or `false`) | Boolean | `false` |
| branch | false | Reject releases from commits not contained in branches that match the specified pattern (regular expression) | String | |
| prefix | false | An optional pattern that matches a prefix for the release tag, before the version number (see [action.yml](action.yml) for more) | String | |
| Name | Required | Description | Type | Default |
|-----------|:---------:|-----------------------------------------------------------------------------|---------|---------|
| token | false [^1]| GitHub token for creating GitHub Releases (see [action.yml](action.yml) for more) | String | |
| changelog | false | Path to changelog (variables `$tag`, `$version`, `$prefix`, and any string) | String | |
| title | false | Format of title (variables `$tag`, `$version`, `$prefix`, and any string) | String | `$tag` |
| draft | false | Create a draft release (`true` or `false`) | Boolean | `false` |
| branch | false | Reject releases from commits not contained in branches that match the specified pattern (regular expression) | String | |
| prefix | false | An optional pattern that matches a prefix for the release tag, before the version number (see [action.yml](action.yml) for more) | String | |

[^1]: Required one of `token` input option or `GITHUB_TOKEN` environment variable.

### Outputs

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ inputs:
variable.
required: false
default: ''
token:
description: >
GitHub token for creating GitHub Releases.
If not set this option, the GITHUB_TOKEN environment variable will be used.
required: false

outputs:
computed-prefix:
Expand Down
11 changes: 6 additions & 5 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ changelog="${INPUT_CHANGELOG:-}"
draft="${INPUT_DRAFT:-}"
branch="${INPUT_BRANCH:-}"
prefix="${INPUT_PREFIX:-}"
token="${INPUT_TOKEN:-"${GITHUB_TOKEN:-}"}"

if [[ -z "${GITHUB_TOKEN:-}" ]]; then
bail "GITHUB_TOKEN not set"
if [[ -z "${token:-}" ]]; then
bail "neither GITHUB_TOKEN environment variable nor 'token' input option is set."
fi

if [[ "${GITHUB_REF:?}" != "refs/tags/"* ]]; then
Expand Down Expand Up @@ -103,13 +104,13 @@ if [[ -n "${changelog}" ]]; then
fi

# https://cli.github.com/manual/gh_release_view
if gh release view "${tag}" &>/dev/null; then
if GITHUB_TOKEN="${token}" gh release view "${tag}" &>/dev/null; then
# https://cli.github.com/manual/gh_release_delete
gh release delete "${tag}" -y
GITHUB_TOKEN="${token}" gh release delete "${tag}" -y
fi

# https://cli.github.com/manual/gh_release_create
gh release create "${release_options[@]}" --title "${title}" --notes "${notes:-}"
GITHUB_TOKEN="${token}" gh release create "${release_options[@]}" --title "${title}" --notes "${notes:-}"

# set (computed) prefix and version outputs for future step use
computed_prefix=${tag%"${version}"}
Expand Down

0 comments on commit 1b162d4

Please sign in to comment.