Skip to content

Commit

Permalink
feat: Enhance Release Number Calculation to Ensure Auto-Increment #1 (#2
Browse files Browse the repository at this point in the history
)

* adding versioning process to the CI

* removing the unrequired character

* adding ignores for version tags

* Adding tag versioned CI

* Separated CI for patch releases and major/minor releases

* adding edge case for github tag-ignores in major/minor version releases

* dummy commit for the tag change

* Dummy change

* changing ignore filter

* Removing double v from versioning

* changing main tag related push

* removing main branch condition

* dummy change for testing CI

* Removed commented out code from ci

---------

Co-authored-by: marshal-dteach <marshal-dteach@github.com>
Co-authored-by: SCC/楊志璿 <zxc25077667@gmail.com>
  • Loading branch information
3 people committed Jun 7, 2024
1 parent 3e6ed83 commit efb9aea
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: C/C++ CI
name: C/C++ patch CI

on:
push:
branches: [ main ]
tags-ignore:
- 'v*' # Ignore all tag version pushes
pull_request:
branches: [ main ]
release:
Expand Down Expand Up @@ -53,13 +55,23 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Get commit count
id: get_commit_count
- name: Get latest release
id: get_latest_release
run: |
git fetch --tags origin
COMMIT_COUNT=$(expr 1 '+' $(git tag --list | grep '^v[0-9]\+' | wc -l))
echo "commit_count=$COMMIT_COUNT" >> $GITHUB_OUTPUT
echo "commit_count=$COMMIT_COUNT"
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "latest_release=${latest_release}" >> $GITHUB_ENV
- name: Determine next version
id: next_version
run: |
if [ "${{ env.latest_release }}" = "null" ]; then
echo "new_version=v0.1.0" >> $GITHUB_ENV
else
IFS='.' read -r major minor patch <<< "${{ env.latest_release }}"
patch=$((patch + 1))
new_version="$major.$minor.$patch"
echo "new_version=$new_version" >> $GITHUB_ENV
fi
- name: Create release directory
run: |
Expand All @@ -83,9 +95,9 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
tag_name: "v${{ steps.get_commit_count.outputs.commit_count }}"
name: "Release v${{ steps.get_commit_count.outputs.commit_count }}"
body: "Release for commit number ${{ steps.get_commit_count.outputs.commit_count }}"
tag_name: "${{ env.new_version }}"
name: "Release ${{ env.new_version }}"
body: "Release for commit number ${{ env.new_version }}"
files: |
release.zip
release.tar.gz
82 changes: 82 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: C/C++ Major/Minor Release CI

on:
push:
tags:
- 'v*.*.*' # Trigger the workflow on version tags like v1.0.0
release:
types: [created]


jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache CMake and build files
uses: actions/cache@v4
with:
path: |
~/.cache
build
key: ${{ runner.os }}-cmake-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-cmake-
- name: Install C++ build tools and dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++ make build-essential --no-install-recommends
- name: Configure CMake
run: |
mkdir -p build
cmake -S . -B build
- name: Build the project
run: |
cmake --build build
- name: Run unit tests
run: |
ctest --test-dir build --output-on-failure
release:
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create release directory
run: |
mkdir release
shopt -s extglob
cp -r !(release) release/
- name: Create release zip file
run: |
cd release
zip -r ../release.zip .
- name: Create release tarball file
run: |
cd release
tar -czvf ../release.tar.gz .
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
with:
tag_name: "${{ github.ref_name }}"
name: "Release ${{ github.ref_name }}"
body: "Release for commit number ${{ github.ref_name }}"
files: |
release.zip
release.tar.gz

0 comments on commit efb9aea

Please sign in to comment.