set first version to 1.0.1 #18
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: Create Tag and Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Git | |
run: | | |
git config --global user.name "${{ secrets.GIT_USER_NAME }}" | |
git config --global user.email "${{ secrets.GIT_USER_EMAIL }}" | |
- name: Get current version | |
id: get_version | |
run: | | |
set -e # Fail on first error | |
# Extract the latest tag, or default to v1.0.1 if no tags exist | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.1") | |
echo "Latest tag: $latest_tag" | |
echo "latest_tag=$latest_tag" >> $GITHUB_ENV | |
# Split the tag into parts | |
IFS='.' read -r -a parts <<< "${latest_tag//v/}" | |
major=${parts[0]} | |
minor=${parts[1]} | |
patch=${parts[2]} | |
# Increment the patch version | |
new_patch=$((patch + 1)) | |
new_tag="v$major.$minor.$new_patch" | |
echo "New tag: $new_tag" | |
echo "new_tag=$new_tag" >> $GITHUB_ENV | |
- name: Check if tag exists | |
id: tag_check | |
run: | | |
set -e # Fail on first error | |
if git rev-parse "refs/tags/${{ env.new_tag }}" >/dev/null 2>&1; then | |
echo "Tag already exists." | |
# Increment the minor version instead | |
new_minor=$((minor + 1)) | |
new_patch=0 | |
new_tag="v$major.$new_minor.$new_patch" | |
echo "New incremented tag: $new_tag" | |
echo "new_tag=$new_tag" >> $GITHUB_ENV | |
else | |
echo "Tag does not exist." | |
echo "new_tag=${{ env.new_tag }}" >> $GITHUB_ENV | |
fi | |
- name: Create new tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -e # Fail on first error | |
git tag "${{ env.new_tag }}" | |
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} "${{ env.new_tag }}" | |
- name: Create GitHub release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.new_tag }} | |
release_name: ${{ env.new_tag }} | |
body: "Automated release for tag ${{ env.new_tag }}" | |
draft: false | |
prerelease: false |