From b26070d7bd6a4aa80f4ca4fedde9150c7153e122 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 21 Oct 2023 18:48:53 -0400 Subject: [PATCH] feat: add tag prefix option (#7) --- .github/workflows/ci.yml | 28 ++++++++++++++++++++++++++++ README.md | 12 +++++++----- action.yml | 10 ++++++++++ action/main.py | 9 +++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3e9e3b..4a38813 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -132,3 +132,31 @@ jobs: echo "changelog_version does not match expected" exit 1 fi + + release: + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Action + id: setup-release + uses: ./ + with: + fail_on_events_api_error: true + github_token: ${{ secrets.GH_BOT_TOKEN }} + + - name: Create Release + id: action + uses: LizardByte/create-release-action@master + with: + allowUpdates: false + artifacts: '' + body: '' + discussionCategory: announcements + generateReleaseNotes: true + name: ${{ steps.setup-release.outputs.release_tag }} + prerelease: ${{ steps.setup-release.outputs.publish_stable_release != 'True' }} + tag: ${{ steps.setup-release.outputs.release_tag }} + token: ${{ secrets.GH_BOT_TOKEN }} diff --git a/README.md b/README.md index ce472f6..cd185ab 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,13 @@ The action does the following: ``` ## Inputs -| Name | Description | Default | Required | -|--------------------------|--------------------------------------------------------------|----------------|----------| -| changelog_path | The path to the changelog file | `CHANGELOG.md` | `false` | -| fail_on_events_api_error | Fail if the action cannot find this commit in the events API | `false` | `false` | -| github_token | The GitHub token to use for API calls | | `true` | +| Name | Description | Default | Required | +|------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|----------| +| changelog_path | The path to the changelog file | `CHANGELOG.md` | `false` | +| fail_on_events_api_error | Fail if the action cannot find this commit in the events API | `false` | `false` | +| github_token | The GitHub token to use for API calls | | `true` | +| include_tag_prefix_in_output | Whether to include the tag prefix in the output. | `true` | `false` | +| tag_prefix | The tag prefix. This will be used when searching for existing releases in GitHub API. This should not be included in the version within the changelog. | `v` | `false` | ## Outputs | Name | Description | diff --git a/action.yml b/action.yml index 02a5015..394db23 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,16 @@ inputs: github_token: description: "GitHub token to use for API requests." required: true + include_tag_prefix_in_output: + description: "Whether to include the tag prefix in the output." + default: 'true' + required: false + tag_prefix: + description: | + The tag prefix. This will be used when searching for existing releases in GitHub API. + This should not be included in the version within the changelog. + default: "v" + required: false outputs: changelog_changes: diff --git a/action/main.py b/action/main.py index 7ed59a1..5414714 100644 --- a/action/main.py +++ b/action/main.py @@ -94,7 +94,8 @@ def check_release(version: str) -> bool: True if the release exists, False otherwise. """ # Get the release from the GitHub API - github_api_url = f'https://api.github.com/repos/{REPOSITORY_NAME}/releases/tags/v{version}' + version_prefix = os.getenv('INPUT_TAG_PREFIX', 'v') + github_api_url = f'https://api.github.com/repos/{REPOSITORY_NAME}/releases/tags/{version_prefix}{version}' response = requests.get(github_api_url, headers=GITHUB_HEADERS) # Check if the release exists @@ -343,9 +344,13 @@ def main() -> dict: release_build = push_event_details["release_build"] release_tag = f"{release_version}" + version_prefix = '' + if os.getenv('INPUT_INCLUDE_TAG_PREFIX_IN_OUTPUT', 'true').lower() == 'true': + version_prefix = os.getenv('INPUT_TAG_PREFIX', 'v') + job_outputs['release_version'] = release_version job_outputs['release_build'] = release_build - job_outputs['release_tag'] = release_tag + job_outputs['release_tag'] = f'{version_prefix}{release_tag}' # Set the outputs for output_name, output_value in job_outputs.items():