Skip to content

Commit

Permalink
ci: do nightly releases
Browse files Browse the repository at this point in the history
  • Loading branch information
zpl-zak committed Feb 24, 2025
1 parent f70e4ac commit e89be39
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 131 deletions.
98 changes: 46 additions & 52 deletions .github/bump_version.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/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
# Find the last [skip ci] commit hash
LAST_SKIP_CI=$(git log --grep="\[skip ci\]" -n 1 --pretty=format:"%H")

echo "PR Title: $PR_TITLE"
if [[ -z "$LAST_SKIP_CI" ]]; then
echo "No previous [skip ci] commit found. Using HEAD^ as reference."
REFERENCE_COMMIT="HEAD^"
else
echo "Found last [skip ci] commit: $LAST_SKIP_CI"
REFERENCE_COMMIT="$LAST_SKIP_CI"
fi

# Get the list of changed files between the merge commit and its first parent.
mapfile -t changed_files < <(git diff --name-only HEAD^ HEAD)
# Get the list of changed files between the last [skip ci] commit and HEAD
mapfile -t changed_files < <(git diff --name-only "$REFERENCE_COMMIT" HEAD)
echo "Changed files: ${changed_files[@]}"

# Default bump type is patch.
# Default bump type is patch
BUMP_TYPE="patch"

# Define arrays for directories that trigger a major or minor bump.
# Define arrays for directories that trigger a major or minor bump
major_paths=(
"code/framework/src/networking/messages"
"code/framework/src/networking/rpc"
Expand All @@ -27,66 +29,58 @@ minor_paths=(
"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
# 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
if [[ "$file" == "$major"* ]]; then
BUMP_TYPE="major"
break 2
fi
done
done
done

# If no major changes were found, check for minor bump directories.
if [[ "$BUMP_TYPE" != "major" ]]; then
# 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
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.
# 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
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.
# 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.
# 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"
;;
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.
# Update the VERSION file with the new version
echo "$NEW_VERSION" > VERSION
echo "Updated version set to: $NEW_VERSION"
158 changes: 79 additions & 79 deletions .github/workflows/pr_tag_commit.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
name: Version Release

on:
pull_request:
types: [closed]
branches: [develop]

name: Version Release

on:
schedule:
- cron: '0 4 * * *' # Runs at 04:00 UTC every day
workflow_dispatch: # Allows manual triggering

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
bump-semver:
runs-on: ubuntu-latest
needs: bump-semver
steps:
- name: Checkout code
uses: actions/checkout@v4
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0 # Get full history for tag comparison

- name: Read raw version
id: version
run: |
VERSION=$(cat VERSION)
echo "raw_version=${VERSION}" >> $GITHUB_OUTPUT
- name: Get previous tag
id: previous-tag
run: |
git fetch --tags
# Default to v0.0.0 if no tags exist
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "prev_tag=${PREV_TAG}" >> $GITHUB_OUTPUT
echo "prev_version=${PREV_TAG#v}" >> $GITHUB_OUTPUT
- name: Compare versions
id: version-check
run: |
NEW_VERSION=${{ steps.version.outputs.raw_version }}
PREV_VERSION=${{ steps.previous-tag.outputs.prev_version }}
IFS='.' read -ra NEW <<< "$NEW_VERSION"
IFS='.' read -ra PREV <<< "$PREV_VERSION"
# Major/minor check (ignore patch)
if [[ ${NEW[0]} -gt ${PREV[0]} || (${NEW[0]} -eq ${PREV[0]} && ${NEW[1]} -gt ${PREV[1]}) ]];
then
echo "RELEASE_NEEDED=true" >> $GITHUB_ENV
echo "new_tag=v${NEW_VERSION}" >> $GITHUB_ENV
fi
- name: Create semver tag and release
if: env.RELEASE_NEEDED == 'true'
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_tag }}
release_name: ${{ env.new_tag }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ref: develop
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
- 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:
runs-on: ubuntu-latest
needs: bump-semver
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0 # Get full history for tag comparison

- name: Read raw version
id: version
run: |
VERSION=$(cat VERSION)
echo "raw_version=${VERSION}" >> $GITHUB_OUTPUT
- name: Get previous tag
id: previous-tag
run: |
git fetch --tags
# Default to v0.0.0 if no tags exist
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "prev_tag=${PREV_TAG}" >> $GITHUB_OUTPUT
echo "prev_version=${PREV_TAG#v}" >> $GITHUB_OUTPUT
- name: Compare versions
id: version-check
run: |
NEW_VERSION=${{ steps.version.outputs.raw_version }}
PREV_VERSION=${{ steps.previous-tag.outputs.prev_version }}
IFS='.' read -ra NEW <<< "$NEW_VERSION"
IFS='.' read -ra PREV <<< "$PREV_VERSION"
# Major/minor check (ignore patch)
if [[ ${NEW[0]} -gt ${PREV[0]} || (${NEW[0]} -eq ${PREV[0]} && ${NEW[1]} -gt ${PREV[1]}) ]];
then
echo "RELEASE_NEEDED=true" >> $GITHUB_ENV
echo "new_tag=v${NEW_VERSION}" >> $GITHUB_ENV
fi
- name: Create semver tag and release
if: env.RELEASE_NEEDED == 'true'
uses: actions/create-release@v1
with:
tag_name: ${{ env.new_tag }}
release_name: ${{ env.new_tag }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit e89be39

Please sign in to comment.