Skip to content

Commit

Permalink
feat: add tag prefix option (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Oct 21, 2023
1 parent eadca4f commit b26070d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
10 changes: 10 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit b26070d

Please sign in to comment.