From 7691554cd1dd95772679ee48dead2b4ded0acf75 Mon Sep 17 00:00:00 2001 From: Nicolas Munnich Date: Sat, 7 Sep 2024 10:54:50 +0200 Subject: [PATCH] feat: Adding simple versioning using GHA to ZMK --- .github/workflows/versioning.yml | 51 ++++++++++++++++++++++++++++++++ VERSION | 3 ++ version_update.sh | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 .github/workflows/versioning.yml create mode 100644 VERSION create mode 100755 version_update.sh diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml new file mode 100644 index 00000000000..a4e21142966 --- /dev/null +++ b/.github/workflows/versioning.yml @@ -0,0 +1,51 @@ +name: Versioning and Release + +on: + push: + branches: + - main + +jobs: + versioning: + runs-on: ubuntu-latest + if: github.event.repository.fork == false + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Authenticate with GitHub + run: | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git + + - name: Run version update script + id: run_version_update + run: ./version_update.sh + + - name: Read version from file + if: ${{ env.RUN_TAG_RELEASE == 'true' }} + id: read_version + run: | + source VERSION + echo "VERSION=${MAJOR}.${MINOR}.${PATCH}" >> $GITHUB_ENV + + - name: Create new tag + if: ${{ env.RUN_TAG_RELEASE == 'true' }} + run: | + git tag -a "v${{ env.VERSION }}" -m "${{ env.VERSION }}: ${{ github.event.head_commit.message }}" + git push origin "v${{ env.VERSION }}" + + - name: Create a Release + if: ${{ env.RUN_TAG_RELEASE == 'true' }} + uses: elgohr/Github-Release-Action@v5 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + title: "${{ env.VERSION }}: ${{ github.event.head_commit.message }}" + tag: "v${{ env.VERSION }}" diff --git a/VERSION b/VERSION new file mode 100644 index 00000000000..51e92940867 --- /dev/null +++ b/VERSION @@ -0,0 +1,3 @@ +MAJOR=0 +MINOR=1 +PATCH=0 \ No newline at end of file diff --git a/version_update.sh b/version_update.sh new file mode 100755 index 00000000000..d2778d0f6e4 --- /dev/null +++ b/version_update.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Source the VERSION file +source VERSION + +# Check the latest commit message +COMMIT_MSG=$(git log -1 --pretty=%B) + +# Initialize variables for version update +UPDATE_REQUIRED=false + +# Determine if a version bump is needed +if [[ "$COMMIT_MSG" =~ SKIP\ VERSIONING ]]; then + echo "RUN_TAG_RELEASE=false" >> $GITHUB_ENV + exit 0 +fi + +if [[ "$COMMIT_MSG" =~ ^!|!:|BREAKING\ CHANGE ]]; then + ((MAJOR+=1)) + MINOR=0 + PATCH=0 + UPDATE_REQUIRED=true +elif [[ "$COMMIT_MSG" == feat* ]]; then + ((MINOR+=1)) + PATCH=0 + UPDATE_REQUIRED=true +elif [[ "$COMMIT_MSG" == fix* ]]; then + ((PATCH+=1)) + UPDATE_REQUIRED=true +fi + +if [ "$UPDATE_REQUIRED" = true ]; then + # Update VERSION file + cat < VERSION +MAJOR=$MAJOR +MINOR=$MINOR +PATCH=$PATCH +EOL + + # commit and push changes + git add VERSION + git commit -m "Update version to $MAJOR.$MINOR.$PATCH" + git push origin main + + echo "Version updated to $MAJOR.$MINOR.$PATCH" + echo "RUN_TAG_RELEASE=true" >> $GITHUB_ENV + exit 0 +fi + +echo "RUN_TAG_RELEASE=false" >> $GITHUB_ENV +