From 1b162d4454461f93f2c65740848bda888e4e9d77 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 7 Sep 2022 20:03:11 +0900 Subject: [PATCH] Add token input option --- CHANGELOG.md | 2 ++ README.md | 17 ++++++++++------- action.yml | 6 ++++++ main.sh | 11 ++++++----- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc76f6..ba7d447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 8052e49..f1717e2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 88928e2..be71260 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/main.sh b/main.sh index 507a4cb..e1f31a5 100755 --- a/main.sh +++ b/main.sh @@ -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 @@ -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}"}