surrealist / dev-dynamo

0 stars 11 forks source link

Update GH Action for auto version bumping #32

Closed surrealist closed 1 year ago

surrealist commented 1 year ago

To do

Yaml

Here is the updated script from GPT, improved after talking back and forth a few times.

name: Run .NET Tool

on:
  push:
    branches:
      - develop

jobs:
  check:
    runs-on: ubuntu-latest
    outputs:
      last_commit_message: ${{ steps.check.outputs.last_commit_message }}

    steps:
    - name: Get last commit message
      id: check
      run: |
        echo "::set-output name=last_commit_message::$(git log -1 --pretty=%B)"

  build:
    needs: check
    if: ${{ !startsWith(needs.check.outputs.last_commit_message, 'Bump version to ') }}
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v3
      with:
        token: ${{ secrets.GH_PAT }}

    - name: Setup .NET
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '2.1'

    - name: Install .NET tool command
      run: dotnet tool install -g dotnet-ver

    - name: Bump version
      id: bump
      run: |
        echo "NEW_VERSION=$(dotnet ver)" >> $GITHUB_ENV

    - name: Commit and push if changes
      run: |
        git config --global user.email "action@github.com"
        git config --global user.name "GitHub Action"
        git diff --quiet || (git commit -am "Bump version to $NEW_VERSION" && git push)
surrealist commented 1 year ago

The above script is just for the initial. See the most updated version in the folder.