From ef6ac37eb57f74fa6565c7261f3c7c46479b8fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Fri, 21 Feb 2025 13:54:19 +0100 Subject: [PATCH 1/2] Version bumper (#133) * chore: auto-versioning * Update bump_version.sh --- .github/CONTRIBUTING.md | 6 +- .github/bump_version.sh | 92 ++++++++++++++++++++++++++ .github/workflows/pr_tag_commit.yml | 26 +++++++- .github/workflows/pr_version_check.yml | 24 ------- 4 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 .github/bump_version.sh delete mode 100644 .github/workflows/pr_version_check.yml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index c967d8b03..b0a1954c2 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -18,11 +18,15 @@ If you feel up for it, feel free to code and pull request any changes you've mad We loosely follow semver to enforce build requirements between networked peers. -Please ensure your PR modifies the VERSION file and bumps: +We separate and bump versions based on these criteria: * PATCH when changes were made to either side that do not affect sync between peers nor the scripting layer itself (could also be cosmetic/meta changes) * MINOR when a change is made in the scripting layer * MAJOR when a change is made to the netcode, shared ecs modules or sync flow between peers (requires both client and the server side to be updated) +Our PR workflow automates version bumping for you based on files that have been modified. This way we ensure each PR properly communicates potential dependency changes. + +Make sure to tag your PR as [PATCH] in case you wish to hotfix an existing code. + ## Code submission policy Please follow the following rules when contributing to the project: diff --git a/.github/bump_version.sh b/.github/bump_version.sh new file mode 100644 index 000000000..7e3a8b1f5 --- /dev/null +++ b/.github/bump_version.sh @@ -0,0 +1,92 @@ +#!/bin/bash +set -e + +# Get the PR title from the first argument. +PR_TITLE="$1" +if [[ -z "$PR_TITLE" ]]; then + echo "Error: PR title must be passed as the first argument." + exit 1 +fi + +echo "PR Title: $PR_TITLE" + +# Get the list of changed files between the merge commit and its first parent. +mapfile -t changed_files < <(git diff --name-only HEAD^ HEAD) +echo "Changed files: ${changed_files[@]}" + +# Default bump type is patch. +BUMP_TYPE="patch" + +# Define arrays for directories that trigger a major or minor bump. +major_paths=( + "code/framework/src/networking/messages" + "code/framework/src/networking/rpc" +) +minor_paths=( + "code/framework/src/scripting/builtins" + "code/framework/src/integrations/server/scripting/builtins" +) + +pr_title_lower=$(echo "$PR_TITLE" | tr '[:upper:]' '[:lower:]') + +# Check if PR title enforces a PATCH bump. +if [[ "$pr_title_lower" == *"[patch]"* ]]; then + echo "PR title contains [patch]. Enforcing PATCH bump." + BUMP_TYPE="patch" +else + # Check for major bump directories. + for file in "${changed_files[@]}"; do + for major in "${major_paths[@]}"; do + if [[ "$file" == "$major"* ]]; then + BUMP_TYPE="major" + break 2 + fi + done + done + + # If no major changes were found, check for minor bump directories. + if [[ "$BUMP_TYPE" != "major" ]]; then + for file in "${changed_files[@]}"; do + for minor in "${minor_paths[@]}"; do + if [[ "$file" == "$minor"* ]]; then + BUMP_TYPE="minor" + break 2 + fi + done + done + fi +fi + +echo "Determined bump type: $BUMP_TYPE" + +# Ensure VERSION file exists. +if [ ! -f VERSION ]; then + echo "VERSION file not found. Creating VERSION with default value 0.0.0." + echo "0.0.0" > VERSION +fi + +# Read the current version from the VERSION file. +CURRENT_VERSION=$(cat VERSION) +echo "Current version: $CURRENT_VERSION" + +IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT_VERSION" + +# Calculate the new version based on the bump type. +case "$BUMP_TYPE" in + major) + NEW_MAJOR=$((MAJOR + 1)) + NEW_VERSION="$NEW_MAJOR.0.0" + ;; + minor) + NEW_MINOR=$((MINOR + 1)) + NEW_VERSION="$MAJOR.$NEW_MINOR.0" + ;; + patch) + NEW_PATCH=$((PATCH + 1)) + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" + ;; +esac + +# Update the VERSION file with the new version. +echo "$NEW_VERSION" > VERSION +echo "Updated version set to: $NEW_VERSION" diff --git a/.github/workflows/pr_tag_commit.yml b/.github/workflows/pr_tag_commit.yml index 8cde16213..649ff9d13 100644 --- a/.github/workflows/pr_tag_commit.yml +++ b/.github/workflows/pr_tag_commit.yml @@ -5,10 +5,32 @@ on: types: [closed] branches: [develop] -jobs: - evaluate-release: +jobs: + bump-semver: if: github.event.pull_request.merged == true runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Ensure full history for diff comparisons + + - name: Run bump semver script + run: | + chmod +x ./.github/bump_version.sh + ./.github/bump_version.sh "${{ github.event.pull_request.title }}" + + - name: Commit version bump + run: | + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add VERSION + git diff-index --quiet HEAD || git commit -m "Bump version to $(cat VERSION) [skip ci]" + git push origin HEAD:develop --follow-tags + evaluate-release: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + needs: bump-semver steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/pr_version_check.yml b/.github/workflows/pr_version_check.yml deleted file mode 100644 index 8b22de09c..000000000 --- a/.github/workflows/pr_version_check.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Check VERSION File Presence - -on: - pull_request: - branches: [ 'develop' ] - -jobs: - check-version-file: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Required to access commit history - - - name: Verify VERSION file change - run: | - # Get list of changed files between base and HEAD - CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}) - - # Check if VERSION is in changed files - if ! echo "$CHANGED_FILES" | grep -q '^VERSION$'; then - echo "::error::VERSION file must be updated in this pull request" - exit 1 - fi From ef072ec75f7fbf2f2a1360a41e0373e54c6f987f Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Fri, 21 Feb 2025 12:54:50 +0000 Subject: [PATCH 2/2] Bump version to 1.8.1 [skip ci] --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 27f9cd322..a8fdfda1c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.8.0 +1.8.1