diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..31977e8 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,36 @@ +name: Auto Tag + +on: + push: + branches: + - main + +jobs: + tag: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Get last commit message + id: commit_message + run: echo "COMMIT_MESSAGE=$(git log -1 --pretty=%B)" >> $GITHUB_ENV + + - name: Extract version from branch name + id: extract_version + run: | + BRANCH_NAME=$(echo ${{ github.head_ref }} | sed 's/refs\/heads\///') + if [[ $BRANCH_NAME =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "VERSION=$BRANCH_NAME" >> $GITHUB_ENV + else + echo "VERSION=" >> $GITHUB_ENV + fi + + - name: Create and push tag + if: env.VERSION != '' + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + git tag ${{ env.VERSION }} + git push origin ${{ env.VERSION }}