Skip to content

ci: add github workflows #1

ci: add github workflows

ci: add github workflows #1

name: Automatic create tag and release.
on:
push:
branches: [master]
jobs:
auto_tag:
permissions:
contents: write
name: Automatic create new tag from tools/get_project_version.sh
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# NOTE:
# Step `check_tag` need history.
fetch-depth: 0
- name: Run get-project-version.sh
id: get_project_version
run: |
# NOTE:
# The pitchfork layout holds extra scripts in tools directory.
# > https://blog.black-desk.cn/pages/pintchfork-layout.html
# But the "Standard Go Project Layout"
# holds extra scripts in scripts directory.
# > https://github.com/golang-standards/project-layout#scripts
get_project_version=tools/get-project-version.sh
if [ ! -f "$get_project_version" ]; then
get_project_version=scripts/get-project-version.sh
fi
if [ ! -f "$get_project_version" ]; then
echo "get-project-version script not found" >&2
exit -1
fi
version="$("${get_project_version}")"
echo version="$version" >> $GITHUB_OUTPUT
- name: Check if tag already exists
id: check_tag
run: |
if git rev-parse "${{ steps.get_project_version.outputs.version }}" &>/dev/null; then
echo existed=true >> $GITHUB_OUTPUT
else
echo existed=false >> $GITHUB_OUTPUT
fi
- name: Run anothrNick/github-tag-action
id: create_tag
if: steps.check_tag.outputs.existed == 'false'
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}}
CUSTOM_TAG: ${{ steps.get_project_version.outputs.version }}
outputs:
new_tag: ${{ steps.create_tag.outputs.new_tag }}
auto_release:
permissions:
contents: write
name: Automatic release for new tag
runs-on: ubuntu-latest
needs:
- auto_tag
steps:
- name: Checkout repository
if: needs.auto_tag.outputs.new_tag
uses: actions/checkout@v4
with:
# NOTE:
# Some automatic release action
# might need history for generate change log.
fetch-depth: 0
- name: Run tools/generate-release-assets.sh
id: generate_release_assets
if: needs.auto_tag.outputs.new_tag
run: |
# NOTE:
# The pitchfork layout holds extra scripts in tools directory.
# > https://blog.black-desk.cn/pages/pintchfork-layout.html
# But the "Standard Go Project Layout"
# holds extra scripts in scripts directory.
# > https://github.com/golang-standards/project-layout#scripts
generate_release_assets=tools/generate-release-assets.sh
if [ ! -f "$generate_release_assets" ]; then
generate_release_assets=scripts/generate-release-assets.sh
fi
if [ ! -f "$generate_release_assets" ]; then
echo "generate-release-assets script not found" >&2
exit -1
fi
ASSETS="$("${generate_release_assets}")"
echo assets="$ASSETS" >> $GITHUB_OUTPUT
- name: Run marvinpinto/action-automatic-releases
uses: marvinpinto/action-automatic-releases@latest
if: needs.auto_tag.outputs.new_tag
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: ${{ needs.auto_tag.outputs.new_tag }}
prerelease: false
files: ${{ steps.generate_release_assets.outputs.assets }}