Skip to content

Commit

Permalink
Merge pull request #10 from buildrun-tech/feature/updates-readme
Browse files Browse the repository at this point in the history
cd: fix the step of generate release version
  • Loading branch information
brunograna authored Feb 18, 2024
2 parents 57f3685 + 6d67b6e commit ce86ad0
Showing 1 changed file with 77 additions and 47 deletions.
124 changes: 77 additions & 47 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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 }}

0 comments on commit ce86ad0

Please sign in to comment.