From 6d67b6e3600370c7fbc858eb18959216f6ca5420 Mon Sep 17 00:00:00 2001 From: brunograna Date: Sun, 18 Feb 2024 18:40:53 -0300 Subject: [PATCH] cd: fix the step of generate release version --- .github/workflows/cd.yml | 124 ++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 47 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 5641f3e..be4c968 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -5,49 +5,8 @@ on: branches: [ "main" ] jobs: - determine-next-version-number: - runs-on: ubuntu-latest - outputs: - new_version: ${{ steps.get-latest-release.outputs.new_version }} - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all history and tags - - - name: Determine next version - id: version - run: | - last_tag=$(git describe --abbrev=0 --always) - commit_range="${last_tag}..HEAD" - major=0 - minor=0 - patch=0 - while IFS= read -r line; do - case "$line" in - *'feat:'*) - minor=$((minor + 1)) - ;; - *'fix:'*) - patch=$((patch + 1)) - ;; - *'BREAKING CHANGE:'*) - major=$((major + 1)) - ;; - esac - done < <(git log --pretty=format:"%s" "$commit_range") - if [ $major -gt 0 ]; then - new_version="$((major + 1)).0.0" - elif [ $minor -gt 0 ]; then - new_version="$major.$((minor + 1)).0" - else - new_version="$major.$minor.$((patch + 1))" - fi - echo "NEW VERSION SHOULD BE => $new_version" - echo "::set-output name=new_version::$new_version" re-build: - needs: determine-next-version-number runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -62,7 +21,6 @@ jobs: run: mvn -B package --file app/pom.xml re-test: - needs: determine-next-version-number runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -82,6 +40,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history and tags - uses: graalvm/setup-graalvm@v1 with: @@ -102,15 +62,85 @@ jobs: ls mvn -Pnative native:compile --file app/pom.xml - - name: Create GitHub Release + - name: Determine next version + id: version + run: | + last_tag=$(git describe --abbrev=0 --always) + commit_range="${last_tag}..HEAD" + major=0 + minor=0 + patch=0 + while IFS= read -r line; do + case "$line" in + *'feat:'*) + minor=$((minor + 1)) + ;; + *'fix:'*) + patch=$((patch + 1)) + ;; + *'BREAKING CHANGE:'*) + major=$((major + 1)) + ;; + esac + done < <(git log --pretty=format:"%s" "$commit_range") + if [ $major -gt 0 ]; then + new_version="$((major + 1)).0.0" + elif [ $minor -gt 0 ]; then + new_version="$major.$((minor + 1)).0" + else + new_version="$major.$minor.$((patch + 1))" + fi + echo "NEW VERSION SHOULD BE => $new_version" + echo "::set-output name=new_version::$new_version" + + - name: Create new tag + run: git tag -a ${{ steps.version.outputs.new_version }} -m "Version ${{ steps.version.outputs.new_version }}" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Generate release notes + id: release_notes + run: | + while IFS= read -r line; do + commit_hash=$(echo "$line" | awk '{print $1}') + commit_msg=$(echo "$line" | awk '{$1=""; print $0}') + case "$commit_msg" in + *'feat:'*) + echo "* **Feature:** ${commit_msg#*:}" + ;; + *'fix:'*) + echo "* **Fix:** ${commit_msg#*:}" + ;; + *'BREAKING CHANGE:'*) + echo "* **Breaking Change:** ${commit_msg#*:}" + ;; + *) + echo "* ${commit_msg}" + ;; + esac + done < commits.txt > release_notes.txt + continue-on-error: false + + - name: Debug release notes + id: debug_release_notes + run: | + cat release_notes.txt + continue-on-error: false + + - name: Push new tag + run: git push origin ${{ steps.version.outputs.new_version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create Release id: create_release uses: softprops/action-gh-release@v1 with: files: | ${{ github.workspace }} - tag_name: ${{ needs.determine-next-version-number.outputs.new_version }} - release_name: Release ${{ needs.determine-next-version-number.outputs.new_version }} + tag_name: ${{ steps.version.outputs.new_version }} + release_name: Release ${{ steps.version.outputs.new_version }} body: | - $(echo "Release notes for version ${{ needs.determine-next-version-number.outputs.new_version }}:") - $(git log --pretty=format:"- %s" $(git describe --tags --abbrev=0)..HEAD) + $(echo "Release notes for version ${{ steps.version.outputs.new_version }}:") + $(cat release_notes.txt) token: ${{ secrets.GITHUB_TOKEN }}