Create file .github/workflows/create-release-from-a-tag.yml
with the content:
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'release*' # Push events to matching release*, i.e. release-1.0, release-20.15.10, release-2020-10-28-10-26-15
name: Create Release
jobs:
build:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: "Get latest tag"
id: latest_tag
run: echo "::set-output name=name::$(git tag --sort=-creatordate | head -1)"
- name: "Get second latest tag"
id: second_latest_tag
run: echo "::set-output name=name::$(git tag --sort=-creatordate | head -2 | tail -1)"
- name: "Get changelog"
id: changelog
run: echo "::set-output name=changelog::$(echo $(git log --pretty=format:'- %s\n' ${{ steps.second_latest_tag.outputs.name }}..${{ steps.latest_tag.outputs.name }}))"
- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: |
${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
This action will be triggered when you push a tag with prefix release
to your github repository. And it will do:
- get the latest tag (that you've just pushed)
- get the previous latest tag
- get the change log betwen those tags
- create the release from the latest tag with the body is the change logs
Stay in your code's folder, fetch and rebase newest code of master, then run command to create a tag from latest commit of master:
datetime=$(date +'%Y-%m-%d-%H-%M-%S')
release_name="release-${datetime}"
git tag -a ${release_name} -m ${release_name}
git push origin ${release_name}
Note:
- Currently release's name has format
release-%Y-%m-%d-%H-%M-%S
. Example:release-2020-10-28-10-26-15
. But you can change to what you want by edit:datetime=$(date +'%Y-%m-%d-%H-%M-%S') release_name="release-${datetime}"
Then github action will auto run and create the release from this tag with the change log (list of commit from previous tag -> latest tag). You just need to go to edit the release, add the break line between the commit (if needed)
The break line between the commit in the change logs doesn't work 😂