Created
June 3, 2023 19:29
-
-
Save ManoloTonto1/edda8a3aa293df9874f8d9a2ce2a94e6 to your computer and use it in GitHub Desktop.
Automatic semantic release-tagging based on commit title and description.
This file contains hidden or 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: Automatic Tagging Check | |
| on: | |
| pull_request: | |
| branches: ["develop"] | |
| jobs: | |
| create_tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Extract issue number and release type | |
| id: extract | |
| run: | | |
| ISSUE_NUMBER=$(echo "${{ github.event.pull_request.title }}" | grep -oP '#\K[0-9]+') | |
| RELEASE_TYPE=$(echo "${{ github.event.pull_request.title }}" | grep -oP '(?i)(patch|minor|major)') | |
| DESCRIPTION=$(echo "${{ github.event.pull_request.body }}") | |
| echo "::set-output name=issue_number::$ISSUE_NUMBER" | |
| echo "::set-output name=release_type::$RELEASE_TYPE" | |
| echo "::set-output name=description::$DESCRIPTION" | |
| - name: Get latest tag | |
| id: latest_tag | |
| run: | | |
| git fetch --tags --force | |
| LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
| echo "::set-output name=latest_tag::$LATEST_TAG" | |
| - name: Set up Git | |
| run: | | |
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
| git config --global user.name "${{ github.actor }}" | |
| - name: Create tag | |
| run: | | |
| ISSUE_NUMBER="${{ steps.extract.outputs.issue_number }}" | |
| RELEASE_TYPE="${{ steps.extract.outputs.release_type }}" | |
| DESCRIPTION="${{ steps.extract.outputs.description }}" | |
| LATEST_TAG="${{ steps.latest_tag.outputs.latest_tag }}" | |
| IFS='.' read -ra PARTS <<< "$LATEST_TAG" | |
| case $RELEASE_TYPE in | |
| patch) | |
| NEW_TAG="${PARTS[0]}.${PARTS[1]}.$((PARTS[2]+1))" | |
| ;; | |
| minor) | |
| NEW_TAG="${PARTS[0]}.$((PARTS[1]+1)).0" | |
| ;; | |
| major) | |
| NEW_TAG="$((PARTS[0]+1)).0.0" | |
| ;; | |
| *) | |
| echo "Invalid release type: $RELEASE_TYPE" | |
| exit 1 | |
| ;; | |
| esac | |
| echo "actor: ${{ github.actor }}" | |
| echo "email: ${{ github.actor }}@users.noreply.github.com" | |
| echo "Creating tag $LATEST_TAG -> $NEW_TAG will be successful!" | |
| echo "Description: $DESCRIPTION" | |
This file contains hidden or 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: Automatic Tagging | |
| on: | |
| pull_request: | |
| types: | |
| - closed | |
| jobs: | |
| create_tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Extract issue number and release type | |
| id: extract | |
| run: | | |
| ISSUE_NUMBER=$(echo "${{ github.event.pull_request.title }}" | grep -oP '#\K[0-9]+') | |
| RELEASE_TYPE=$(echo "${{ github.event.pull_request.title }}" | grep -oP '(?i)(patch|minor|major)') | |
| DESCRIPTION=$(echo "${{ github.event.pull_request.body }}") | |
| echo "::set-output name=issue_number::$ISSUE_NUMBER" | |
| echo "::set-output name=release_type::$RELEASE_TYPE" | |
| echo "::set-output name=description::$DESCRIPTION" | |
| - name: Get latest tag | |
| id: latest_tag | |
| run: | | |
| git fetch --tags --force | |
| LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
| echo "::set-output name=latest_tag::$LATEST_TAG" | |
| - name: Set up Git | |
| run: | | |
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
| git config --global user.name "${{ github.actor }}" | |
| - name: Create tag | |
| run: | | |
| ISSUE_NUMBER="${{ steps.extract.outputs.issue_number }}" | |
| RELEASE_TYPE="${{ steps.extract.outputs.release_type }}" | |
| DESCRIPTION="${{ steps.extract.outputs.description }}" | |
| LATEST_TAG="${{ steps.latest_tag.outputs.latest_tag }}" | |
| IFS='.' read -ra PARTS <<< "$LATEST_TAG" | |
| case $RELEASE_TYPE in | |
| patch) | |
| NEW_TAG="${PARTS[0]}.${PARTS[1]}.$((PARTS[2]+1))" | |
| ;; | |
| minor) | |
| NEW_TAG="${PARTS[0]}.$((PARTS[1]+1)).0" | |
| ;; | |
| major) | |
| NEW_TAG="$((PARTS[0]+1)).0.0" | |
| ;; | |
| *) | |
| echo "Invalid release type: $RELEASE_TYPE" | |
| exit 1 | |
| ;; | |
| esac | |
| echo "Creating tag $NEW_TAG" | |
| git tag -a $NEW_TAG -m "$DESCRIPTION" | |
| git push origin $NEW_TAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment