diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..07d0be4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Intellij settings +.idea diff --git a/.vscode/settings.json b/.vscode/settings.json index 272be54..4db65cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,18 +1,19 @@ { - "spellright.language": [ - "en_GB" - ], - "spellright.documentTypes": [ - "markdown", - "latex", - "plaintext", - "git-commit", - "shellscript", - "github-actions" - ], - "spellright.parserByClass": { - "github-actions": { - "parser": "code" - } - } -} \ No newline at end of file + "spellright.language": [ + "en_GB" + ], + "spellright.documentTypes": [ + "markdown", + "latex", + "plaintext", + "git-commit", + "shellscript", + "github-actions" + ], + "spellright.parserByClass": { + "github-actions": { + "parser": "code" + } + }, + "editor.formatOnSave": true +} diff --git a/README.md b/README.md index 8c680bb..3fdd6fb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # GitHub Action for Creating a Release on Tag push -Create a new GitHub release whenever a tag is pushed. +Creates a new GitHub release whenever a tag is pushed. ## Example Usage @@ -13,12 +13,12 @@ jobs: release: runs-on: ubuntu-latest steps: - - name: Create GitHub release - uses: Roang-zero1/github-create-release-action@master - with: - version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create GitHub release + uses: Roang-zero1/github-create-release-action@master + with: + version_regex: ^v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+ + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` ### Limiting versions and creating pre-releases @@ -27,8 +27,8 @@ If only certain tags should create releases or some releases should be created a These regular expression are evaluated with GNU grep, so these regular expressions need to be compatible with it. Regular expressions containing `\` need them to be escaped with `\\`. -* `version_regex` Regular expression to verify that the version is in a correct format. Defaults to `.*` (accept everything). -* `prerelease_regex` Any version matching this regular expression will be marked as pre-release. Disabled by default. +- `version_regex` Regular expression to verify that the version is in a correct format. Defaults to `.*` (accept everything). +- `prerelease_regex` Any version matching this regular expression will be marked as pre-release. Disabled by default. ```yaml - name: Create GitHub release @@ -40,6 +40,40 @@ Regular expressions containing `\` need them to be escaped with `\\`. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` +### Passing a tag to not rely on manual tag pushes + +If you want to create a tag automatically and create the release in the same workflow you can set CREATED_TAG to achieve this. +This allows you to create a fully automated release in one workflow file (workaround because one workflow/action can not trigger another workflow/action). +The example below uses `K-Phoen/semver-release-action` to create the tag whenever a pull request is closed, merged, and the head_ref starts with RC. +After the tag is created it is passed to the create-release-action via the CREATED_TAG env variable using the output of the semver-release-action. + +```yaml +on: + pull_request: + types: closed + +jobs: + build: + runs-on: ubuntu-latest + if: github.event.pull_request.merged && startsWith(github.head_ref, 'RC') + steps: + - uses: actions/checkout@master + - name: Tag and prepare release + id: tag_and_prepare_release + uses: K-Phoen/semver-release-action@master + with: + release_branch: master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload release notes + if: steps.tag_and_prepare_release.outputs.tag + uses: Roang-zero1/github-create-release-action@master + with: + created_tag: ${{ steps.tag_and_prepare_release.outputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + ### Changelog parsing This action makes it possible to extract the release description from a Markdown changelog. @@ -79,6 +113,14 @@ Create the releases as draft (`true|false [default: false]`). Existing will not Controls whether an existing release should be updated with data from the latest push (`true|false [default: false]`). +### `created_tag` + +Allows to pass an already created tag. + +### `release_title` + +Allows to pass a release title. + ### `changelog_file` File that contains the Markdown formatted changelog. Defaults to `CHANGELOG.md`. @@ -89,4 +131,4 @@ Heading level at which the tag headings exist. Defaults to `h2`, this parses hea ## Secrets -* `GITHUB_TOKEN` Provided by GitHub action, does not need to be set. +- `GITHUB_TOKEN` Provided by GitHub action, does not need to be set. diff --git a/action.yml b/action.yml index d9f1e4a..8dc298f 100644 --- a/action.yml +++ b/action.yml @@ -1,37 +1,45 @@ # action.yml -name: 'GitHub Create Tag Release' -description: 'Create a GitHub release from a pushed Tag.' +name: "GitHub Create Tag Release" +description: "Create a GitHub release from a pushed Tag." branding: - icon: 'zap' - color: 'white' + icon: "zap" + color: "white" inputs: # Version and release control inputs version_regex: - description: 'Regular expression to verify that the version is in a correct format. Defaults to .* (accept everything).' - default: '^.*$' + description: "Regular expression to verify that the version is in a correct format. Defaults to .* (accept everything)." + default: "^.*$" required: false prerelease_regex: - description: 'Any version matching this regular expression will be marked as pre-release. Disabled by default.' - default: '' + description: "Any version matching this regular expression will be marked as pre-release. Disabled by default." + default: "" required: false create_draft: - description: 'Create the releases as draft (true|false [default: false]). Existing will not be updated from released to draft.' - default: 'false' + description: "Create the releases as draft (true|false [default: false]). Existing will not be updated from released to draft." + default: "false" required: false update_existing: - description: 'Controls whether an existing release should be updated with data from the latest push (true|false [default: false]).' - default: 'false' + description: "Controls whether an existing release should be updated with data from the latest push (true|false [default: false])." + default: "false" + required: false + created_tag: + description: "Allows to pass an already created tag, forces update_existing to true." + default: "" + required: false + release_title: + description: "Allows to pass a title for the release." + default: "" required: false # Inputs related to the Changelog parsing changelog_file: - description: 'Path of file that contains the Markdown formatted changelog.' - default: 'CHANGELOG.md' + description: "Path of file that contains the Markdown formatted changelog." + default: "CHANGELOG.md" required: false changelog_heading: - description: 'Heading level at which the tag headings exist.' - default: 'h2' + description: "Heading level at which the tag headings exist." + default: "h2" required: false runs: - using: 'docker' - image: 'Dockerfile' + using: "docker" + image: "Dockerfile" diff --git a/entrypoint.sh b/entrypoint.sh index dc60341..ce9b317 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh -# Backwards compability mapping +# Backwards compatibility mapping if [ -z $VERSION_REGEX ]; then :; else INPUT_VERSION_REGEX=$VERSION_REGEX fi @@ -22,6 +22,14 @@ fi set -euo pipefail +set_tag() { + if [ -n "${INPUT_CREATED_TAG}" ]; then + TAG=${INPUT_CREATED_TAG} + else + TAG="$(echo ${GITHUB_REF} | grep tags | grep -o "[^/]*$" || true)" + fi +} + create_release_data() { RELEASE_DATA="{}" RELEASE_DATA=$(echo ${RELEASE_DATA} | jq --arg tag $TAG '.tag_name = $tag') @@ -44,9 +52,12 @@ create_release_data() { fi fi RELEASE_DATA=$(echo ${RELEASE_DATA} | jq --argjson value $PRERELEASE_VALUE '.prerelease = $value') + if [ -n "${INPUT_RELEASE_TITLE}" ]; then + RELEASE_DATA=$(echo ${RELEASE_DATA} | jq --arg name "${INPUT_RELEASE_TITLE}" '.name = $name') + fi } -TAG="$(echo ${GITHUB_REF} | grep tags | grep -o "[^/]*$" || true)" +set_tag if [ -z $TAG ]; then echo "This is not a tagged push." 1>&2