Skip to content

Commit

Permalink
Merge pull request #3 from serucee/master
Browse files Browse the repository at this point in the history
* Add option to pass tag from another action (Fixes #2 ).
* Add option to pass release title.
  • Loading branch information
Roang-zero1 authored Dec 6, 2019
2 parents 39e9fd7 + 82c38e9 commit 69d4a52
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Intellij settings
.idea
35 changes: 18 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"spellright.language": [
"en_GB"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext",
"git-commit",
"shellscript",
"github-actions"
],
"spellright.parserByClass": {
"github-actions": {
"parser": "code"
}
}
}
"spellright.language": [
"en_GB"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext",
"git-commit",
"shellscript",
"github-actions"
],
"spellright.parserByClass": {
"github-actions": {
"parser": "code"
}
},
"editor.formatOnSave": true
}
62 changes: 52 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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`.
Expand All @@ -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.
44 changes: 26 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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"
15 changes: 13 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

# Backwards compability mapping
# Backwards compatibility mapping
if [ -z $VERSION_REGEX ]; then :; else
INPUT_VERSION_REGEX=$VERSION_REGEX
fi
Expand All @@ -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')
Expand All @@ -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
Expand Down

0 comments on commit 69d4a52

Please sign in to comment.