Update tag pushing method in workflow #3
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: Build and Test | |
| on: | |
| push: | |
| branches: [ "master" ] | |
| pull_request: | |
| branches: [ "master" ] | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [ubuntu-latest] | |
| build_type: [Release] | |
| c_compiler: [gcc, clang, cl] | |
| include: | |
| - os: ubuntu-latest | |
| c_compiler: gcc | |
| cpp_compiler: g++ | |
| - os: ubuntu-latest | |
| c_compiler: clang | |
| cpp_compiler: clang++ | |
| exclude: | |
| - os: ubuntu-latest | |
| c_compiler: cl | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Dependencies (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| build-essential \ | |
| cmake \ | |
| ninja-build \ | |
| pkg-config \ | |
| gcc g++ \ | |
| clang \ | |
| libgtk-4-dev \ | |
| libwebkitgtk-6.0-dev \ | |
| libjson-glib-dev | |
| - name: Set reusable strings | |
| id: strings | |
| shell: bash | |
| run: | | |
| echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" | |
| - name: Configure CMake | |
| run: > | |
| cmake -B ${{ steps.strings.outputs.build-output-dir }} | |
| -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} | |
| -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
| -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} | |
| -S ${{ github.workspace }} | |
| - name: Build | |
| run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} | |
| - name: Run unit tests (hb_tests) | |
| working-directory: ${{ steps.strings.outputs.build-output-dir }} | |
| run: ctest -C ${{ matrix.build_type }} -R hb_tests --output-on-failure | |
| tag: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Required for tags | |
| - name: Get latest tag | |
| id: latest | |
| run: | | |
| git fetch --tags | |
| tag=$(git tag --sort=-v:refname | head -n 1) | |
| if [ -z "$tag" ]; then tag="v0.0.0"; fi | |
| echo "latest=$tag" >> $GITHUB_OUTPUT | |
| - name: Calculate next tag | |
| id: next | |
| run: | | |
| tag="${{ steps.latest.outputs.latest }}" | |
| echo "Current tag: $tag" | |
| IFS='.' read -r major minor patch <<< "${tag#v}" | |
| patch=$((patch + 1)) | |
| new_tag="v$major.$minor.$patch" | |
| echo "new_tag=$new_tag" >> $GITHUB_OUTPUT | |
| - name: Create and push tag | |
| env: | |
| TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag ${{ steps.next.outputs.new_tag }} | |
| git push https://$TOKEN@github.com/${{ github.repository }} ${{ steps.next.outputs.new_tag }} |