Skip to content

Better Liquid Evaporation, Space Cleaner Grenades actually work now, … #1

Better Liquid Evaporation, Space Cleaner Grenades actually work now, …

Better Liquid Evaporation, Space Cleaner Grenades actually work now, … #1

name: Good File Check and Tag Semantic Version
on:
push:
branches:
- develop
jobs:
tag-commit:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/develop')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Check for modified files
id: check_changes
run: |
git fetch --prune --unshallow || true
# Get the previous commit on the current branch
BASE_COMMIT=$(git rev-parse HEAD^)
echo "Base commit: $BASE_COMMIT"
# Get the current commit
CURRENT_COMMIT=${{ github.sha }}
echo "Current commit: $CURRENT_COMMIT"
# Get the list of modified files and save them as a newline-separated string
MODIFIED_FILES=$(git diff --name-only "$BASE_COMMIT" "$CURRENT_COMMIT")
echo "Modified files:"
echo "$MODIFIED_FILES"
# Define folders/files to watch
WATCHED=("UnityProject/Packages/" "UnityProject/ProjectSettings/" "UnityProject/Assets/Plugins/" "UnityProject/Assets/Scripts/Core/SecureStuff/")
# Initialize the trigger status
TRIGGERED=false
# Check if any of the watched files/folders were modified
while IFS= read -r MOD_FILE; do
for ITEM in "${WATCHED[@]}"; do
if [[ "$MOD_FILE" == "$ITEM"* ]]; then
echo "Found changes in $ITEM"
TRIGGERED=true
break 2
fi
done
done <<< "$MODIFIED_FILES"
# Set the trigger status as an output
echo "TRIGGERED=$TRIGGERED" >> $GITHUB_ENV
env:
GITHUB_ENV: ${{ github.env }}
- name: Increment version and create tag
if: env.TRIGGERED == 'true'
id: version_bump
run: |
# Get the latest tag, sorted by version
LATEST_TAG=$(git tag --list "good-file*" --sort=-v:refname | head -n 1)
if [ -z "$LATEST_TAG" ]; then
MAJOR=0
MINOR=1
PATCH=0
else
VERSION=${LATEST_TAG#"good-file-"}
MAJOR=$(echo "$VERSION" | cut -d. -f1)
MINOR=$(echo "$VERSION" | cut -d. -f2)
PATCH=$(echo "$VERSION" | cut -d. -f3)
MINOR=$((MINOR + 1))
PATCH=0
fi
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
NEW_TAG="good-file-$NEW_VERSION"
echo "New version: $NEW_TAG"
echo "NEW_VERSION=$NEW_TAG" >> $GITHUB_ENV
env:
GITHUB_ENV: ${{ github.env }}
- name: Tag the commit
if: env.TRIGGERED == 'true'
run: |
NEW_VERSION=${{ env.NEW_VERSION }}
# Create and push the new tag
git tag "$NEW_VERSION"
git push origin "$NEW_VERSION"