Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding simple versioning using GHA to ZMK #2464

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
3 changes: 3 additions & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MAJOR=0
MINOR=1
PATCH=0
51 changes: 51 additions & 0 deletions version_update.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOL > 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