diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index df741db..9147521 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,12 +5,13 @@ on: jobs: release: + if: github.repository == 'lumynou5/github-release-action' runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - + - name: Release - uses: lumynou5/github-release-action@main + uses: lumynou5/github-release-action@v1 with: token: ${{github.token}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 941188f..b2fde02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,19 @@ # Changelog All notable changes to this project will be documented in this file. +## [1.2.0] - 2024-01-16 +### Added +- Minor tag. +### Changed +- Major tag of major version 0. +### Fixed +- Templates using multiple parameters work as expected now. + ## [1.1.1] - 2023-05-05 ### Fixed - Accidently used tuple for tag name. -## [1.1.0] - 2023-05-05 +## [1.1.0] - 2023-05-05 [YANKED] ### Added - Outputs the names of the Git tags of the release and the major version; i.e., the filled templates are outputed. - Input `major-tag-template` can be empty for no major tag now. @@ -18,6 +26,7 @@ All notable changes to this project will be documented in this file. ### Added - First release. +[1.2.2]: https://github.com/lumynou5/github-release-action/releases/tag/v1.2.0 [1.1.1]: https://github.com/lumynou5/github-release-action/releases/tag/v1.1.1 [1.1.0]: https://github.com/lumynou5/github-release-action/releases/tag/v1.1.0 [1.0.1]: https://github.com/lumynou5/github-release-action/releases/tag/v1.0.1 diff --git a/README.md b/README.md index cc227f4..ee6d3ca 100644 --- a/README.md +++ b/README.md @@ -15,20 +15,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - + - name: Release - # Use the latest version. - uses: lumynou5/github-release-action@main + uses: lumynou5/github-release-action@v1 with: token: ${{github.token}} ``` In this example workflow, it'll create a release whenever push to `main` branch. -The version will be set according to the changelog following [Keep a Changelog](https://keepachangelog.com/) -and [Semantic Versioning](https://semver.org/). +The version and the release note will be captured from the changelog following +[Keep a Changelog](https://keepachangelog.com/) and [Semantic Versioning](https://semver.org/). +And a Git tag will be created for the major revision, see [Inputs](#Inputs) for more information. -Specifically, a release is created and the tag of the corresponding major version is moved onto that version. -If there isn't a tag of the major version, it'll be created. +This is useful to automatically publish releases on pushing to the stable branch when using Git flow, etc. ## Inputs - `token` (required) @@ -38,13 +37,19 @@ If there isn't a tag of the major version, it'll be created. - `tag-template` The template of the Git tag. Default: `v{version}`. - `major-tag-template` - The template of the Git tag of the major version. Default: `v{major}`. Empty for no major tag. + The template of the Git tag of the major version. Doesn't perform if the major version is 0. + Default: `v{major}`. Empty for no major tag. +- `minor-tag-template` + The template of the Git tag of the minor version. Default: `v{maojr}.{minor}`. Empty for no minor tag. - `name-template` The template of the GitHub release. Default: `v{version}`. - `is-draft` If the GitHub release is a draft. Default: `false`. -The following list shows the arguments can be used in the template. +The following list shows the parameters that can be used in templates. +To use parameters, add a parameter name wrapping with braces to your template, +and it will be replaced with data from your changelog; +i.e. `{parameter-name}` will be replaced with the corresponding value. - `version` The version. - `major` @@ -61,12 +66,18 @@ The following list shows the arguments can be used in the template. The release date. ## Outputs -The outputs include all the arguments of templates and the following items in addition. +The outputs include all the parameters of templates and the following items in addition. - `tag` The name of the Git tag. - `major-tag` The name of the Git tag of the major version. +- `minor-tag` + The name of the Git tag of the minor version. - `html-url` The URL to the page of the GitHub release. - `upload-url` The URL to upload assets for the GitHub release. + +## License +The source code is distributed under the MIT license. +See [LICENSE.md](LICENSE.md) for further information. diff --git a/action.yml b/action.yml index 54c7dd1..c47d357 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: description: The template of the Git tag of the major version. required: false default: v{major} + minor-tag-template: + description: The template of the Git tag of the major version. + required: false + default: v{major}.{minor} name-template: description: The template of the GitHub release. required: false @@ -27,7 +31,7 @@ inputs: is-draft: description: If the GitHub release is a draft. required: false - default: false + default: 'false' outputs: version: description: The version. diff --git a/main.py b/main.py index e29fa6d..5343711 100644 --- a/main.py +++ b/main.py @@ -13,7 +13,7 @@ def fillTemplate(template, data): i = 0 while i < len(template): if template[i] == '{': - end = template.find('}') + end = template.find('}', i) if end == -1: result += template[i:] break @@ -55,7 +55,7 @@ def fillTemplate(template, data): env['GITHUB_SHA']) # Move major tag. -if env['INPUT_MAJOR-TAG-TEMPLATE'] != '': +if env['INPUT_MAJOR-TAG-TEMPLATE'] != '' and data['major'] != 0: major_tag = fillTemplate(env['INPUT_MAJOR-TAG-TEMPLATE'], data) major = repo.get_git_ref(f'tags/{major_tag}') if major.ref is not None: @@ -65,9 +65,21 @@ def fillTemplate(template, data): else: major_tag = '' +# Move minor tag. +if env['INPUT_MINOR-TAG-TEMPLATE'] != '': + minor_tag = fillTemplate(env['INPUT_MINOR-TAG-TEMPLATE'], data) + minor = repo.get_git_ref(f'tags/{minor_tag}') + if minor.ref is not None: + minor.edit(env['GITHUB_SHA']) + else: + repo.create_git_ref(f'refs/tags/{minor_tag}', env['GITHUB_SHA']) +else: + minor_tag = '' + # Output. data['tag'] = tag data['major-tag'] = major_tag +data['minor-tag'] = minor_tag data['html-url'] = release.html_url data['upload-url'] = release.upload_url with open(env['GITHUB_OUTPUT'], 'a') as out: