Skip to content

Commit 9ba947f

Browse files
authored
feat: Add tagName and tagMessage options (#78)
* feat: Add tagName and tagMessage options * feat: Add print_info for tag options * feat: Add tagOverwrite option * docs: Add new section about Git tag options Close #76
1 parent ebe79a7 commit 9ba947f

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Do you want to skip the docker build step? OK, the script mode is available.
7373
- [⭐️ Force orphan](#%EF%B8%8F-force-orphan)
7474
- [⭐️ Set Git username and email](#%EF%B8%8F-set-git-username-and-email)
7575
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
76+
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
7677
- [⭐️ Script mode](#%EF%B8%8F-script-mode)
7778
- [Tips and FAQ](#tips-and-faq)
7879
- [⭐️ Use the latest and specific release](#%EF%B8%8F-use-the-latest-and-specific-release)
@@ -347,6 +348,63 @@ When we create a commit with a message `docs: Update some post`, a deployment co
347348
commitMessage: ${{ github.event.head_commit.message }}
348349
```
349350

351+
### ⭐️ Create Git tag
352+
353+
Here is an example workflow.
354+
355+
```yaml
356+
name: github pages
357+
358+
on:
359+
push:
360+
branches:
361+
- master
362+
tags:
363+
- 'v*.*.*'
364+
365+
jobs:
366+
build-deploy:
367+
runs-on: ubuntu-18.04
368+
steps:
369+
- uses: actions/checkout@v2
370+
371+
- name: Some build
372+
373+
- name: Prepare tag
374+
id: prepare_tag
375+
if: startsWith(github.ref, 'refs/tags/')
376+
run: |
377+
TAG_NAME="${GITHUB_REF##refs/tags/}"
378+
echo "::set-output name=tag_name::${TAG_NAME}"
379+
echo "::set-output name=deploy_tag_name::deploy-${TAG_NAME}"
380+
381+
- name: Deploy
382+
uses: peaceiris/actions-gh-pages@v2
383+
env:
384+
ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
385+
PUBLISH_BRANCH: gh-pages
386+
PUBLISH_DIR: ./public
387+
with:
388+
tagName: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
389+
tagMessage: 'Deployment ${{ steps.prepare_tag.outputs.tag_name }}'
390+
```
391+
392+
Commands on a local machine.
393+
394+
```console
395+
$ # On the master branch
396+
$ git tag -a "v1.2.3" -m "Release v1.2.3"
397+
$ git push origin "v1.2.3"
398+
399+
$ # After deployment
400+
$ git fetch origin
401+
$ git tag
402+
deploy-v1.2.3 # Tag on the gh-pages branch
403+
v1.2.3 # Tag on the master branch
404+
```
405+
406+
We can set `tagOverwrite` option to `true` for overwriting a tag.
407+
350408
### ⭐️ Script mode
351409

352410
From `v2.5.0`, we can run this action as a shell script.

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,13 @@ inputs:
2929
commitMessage:
3030
description: 'Set custom commit message'
3131
required: false
32+
tagName:
33+
description: 'Set tag name'
34+
required: false
35+
tagMessage:
36+
description: 'Set tag message'
37+
required: false
38+
tagOverwrite:
39+
description: 'Enable overwriting tag'
40+
required: false
41+
default: false

entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,22 @@ else
142142
git push origin "${remote_branch}"
143143
fi
144144

145+
if [[ -n "${INPUT_TAGNAME}" ]]; then
146+
print_info "Tag name: ${INPUT_TAGNAME}"
147+
print_info "Tag message: ${INPUT_TAGMESSAGE}"
148+
print_info "Tag overwrite: ${INPUT_TAGOVERWRITE}"
149+
if [[ -n "${INPUT_TAGMESSAGE}" ]]; then
150+
GIT_TAG_MESSAGE="${INPUT_TAGMESSAGE}"
151+
else
152+
GIT_TAG_MESSAGE="Deployment ${INPUT_TAGNAME}"
153+
fi
154+
if [[ "${INPUT_TAGOVERWRITE}" == "true" ]]; then
155+
GIT_TAG_OPTION="--force"
156+
else
157+
GIT_TAG_OPTION=""
158+
fi
159+
git tag "${GIT_TAG_OPTION}" -a "${INPUT_TAGNAME}" -m "${GIT_TAG_MESSAGE}"
160+
git push "${GIT_TAG_OPTION}" origin "${INPUT_TAGNAME}"
161+
fi
162+
145163
print_info "${GITHUB_SHA} was successfully deployed"

0 commit comments

Comments
 (0)