Skip to content

Commit 0d5a58b

Browse files
authored
Update gradle-build.yml
1 parent daeedde commit 0d5a58b

1 file changed

Lines changed: 60 additions & 15 deletions

File tree

.github/workflows/gradle-build.yml

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
packages: write
2424

2525
steps:
26-
- uses: actions/checkout@v4
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
2728
with:
2829
fetch-depth: 0
2930

@@ -32,44 +33,88 @@ jobs:
3233
with:
3334
java-version: '21'
3435
distribution: 'temurin'
35-
cache: gradle
3636

3737
- name: Validate Gradle wrapper
3838
uses: gradle/wrapper-validation-action@v2
3939

40+
# Alternative caching strategy when GitHub cache fails
41+
- name: Cache Gradle dependencies
42+
uses: actions/cache@v4
43+
with:
44+
path: |
45+
~/.gradle/caches
46+
~/.gradle/wrapper
47+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
48+
restore-keys: |
49+
${{ runner.os }}-gradle-
50+
4051
- name: Setup Gradle
4152
uses: gradle/actions/setup-gradle@v3
53+
with:
54+
cache-disabled: false
55+
cache-read-only: ${{ github.event_name == 'pull_request' }}
56+
gradle-home-cache-cleanup: true
4257

4358
- name: Make Gradle wrapper executable
4459
run: chmod +x ./gradlew
4560

46-
- name: Build with Gradle
47-
run: ./gradlew build --no-daemon
48-
49-
- name: Run tests
50-
run: ./gradlew test --no-daemon
61+
# Combine build and test in one step to reduce overhead
62+
- name: Build and test with Gradle
63+
run: ./gradlew build --no-daemon --parallel --build-cache --configuration-cache
64+
env:
65+
GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx2g -XX:MaxMetaspaceSize=512m" -Dorg.gradle.daemon=false
5166

52-
- name: Extract version
67+
- name: Extract version information
5368
id: extract_version
5469
run: |
55-
VERSION=$(grep 'version =' build.gradle | head -n 1 | awk -F "'" '{print $2}')
56-
echo "VERSION=$VERSION" >> $GITHUB_ENV
70+
# More robust version extraction that handles different formats
71+
if [ -f "build.gradle" ]; then
72+
VERSION=$(grep -E "version\s*=\s*['\"]" build.gradle | head -n 1 | sed -E "s/.*version\s*=\s*['\"]([^'\"]*)['\"].*/\1/")
73+
elif [ -f "build.gradle.kts" ]; then
74+
VERSION=$(grep -E "version\s*=\s*['\"]" build.gradle.kts | head -n 1 | sed -E "s/.*version\s*=\s*['\"]([^'\"]*)['\"].*/\1/")
75+
else
76+
VERSION="unknown"
77+
fi
78+
79+
if [ -z "$VERSION" ] || [ "$VERSION" = "unknown" ]; then
80+
VERSION="dev-$(date +%Y%m%d)"
81+
fi
82+
5783
COMMIT_SHA_SHORT=$(git rev-parse --short HEAD)
84+
85+
echo "VERSION=$VERSION" >> $GITHUB_ENV
5886
echo "COMMIT_SHA_SHORT=$COMMIT_SHA_SHORT" >> $GITHUB_ENV
87+
echo "version=$VERSION" >> $GITHUB_OUTPUT
88+
echo "commit_sha_short=$COMMIT_SHA_SHORT" >> $GITHUB_OUTPUT
89+
5990
echo "Version: $VERSION (Commit: $COMMIT_SHA_SHORT)"
6091
6192
- name: Upload JAR artifact
6293
uses: actions/upload-artifact@v4
6394
with:
64-
name: SmartSpawner-${{ env.VERSION }}
65-
path: core/build/libs/SmartSpawner-${{ env.VERSION }}.jar
95+
name: SmartSpawner-${{ env.VERSION }}-${{ env.COMMIT_SHA_SHORT }}
96+
path: |
97+
core/build/libs/SmartSpawner-*.jar
98+
build/libs/SmartSpawner-*.jar
6699
retention-days: 90
67-
if-no-files-found: error
100+
if-no-files-found: warn
68101

69102
- name: Upload test reports on failure
70103
if: failure()
71104
uses: actions/upload-artifact@v4
72105
with:
73106
name: test-reports-${{ env.COMMIT_SHA_SHORT }}
74-
path: build/reports/tests/
75-
retention-days: 7
107+
path: |
108+
**/build/reports/tests/
109+
**/build/test-results/
110+
retention-days: 7
111+
if-no-files-found: ignore
112+
113+
# Optional: Add summary for better visibility
114+
- name: Build Summary
115+
if: always()
116+
run: |
117+
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
118+
echo "- **Version**: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
119+
echo "- **Commit**: ${{ env.COMMIT_SHA_SHORT }}" >> $GITHUB_STEP_SUMMARY
120+
echo "- **Status**: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)