ci: add auto release workflow (#2) #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: [main] | |
jobs: | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
if: "startsWith(github.event.head_commit.message, 'feat: release v')" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install Lua | |
uses: leafo/gh-actions-lua@v8 | |
- name: Install Luarocks | |
uses: leafo/gh-actions-luarocks@v4 | |
- name: Extract release name | |
id: release_env | |
shell: bash | |
env: | |
MESSAGE: ${{ github.event.head_commit.message }} | |
run: | | |
title="${MESSAGE}" | |
re="^feat: release v*(\S+)" | |
if [[ $title =~ $re ]]; then | |
v=v${BASH_REMATCH[1]} | |
echo "##[set-output name=version;]${v}" | |
echo "##[set-output name=version_withou_v;]${BASH_REMATCH[1]}" | |
else | |
echo "commit format is not correct" | |
exit 1 | |
fi | |
- name: Check dot version | |
shell: bash | |
run: | | |
if [ "${{ steps.release_env.outputs.version_withou_v }}" != "$(cat .version)" ]; then | |
echo "VERSION '${{ steps.release_env.outputs.version_withou_v }}' does not match the dot version file '$(cat .version)'" | |
exit 1 | |
fi | |
- name: Create Release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.release_env.outputs.version_withou_v }} | |
release_name: ${{ steps.release_env.outputs.version }} | |
draft: false | |
prerelease: false | |
- name: Upload to luarocks | |
env: | |
VERSION: ${{ steps.release_env.outputs.version_withou_v }} | |
APIKEY: ${{ secrets.LUAROCKS_TOKEN }} | |
run: make upload |