ci: refactor Spark workflow for DRY and robustness

1. Add explicit permissions (least privilege):
   - contents: read
   - checks: write (for test reports)
   - pull-requests: write (for PR comments)

2. Extract duplicate build steps into shared 'build-deps' job:
   - Eliminates duplication between spark-tests and spark-example
   - Build artifacts are uploaded and reused by dependent jobs
   - Reduces CI time and ensures consistency

3. Fix spark-example service startup verification:
   - Match robust approach from spark-tests job
   - Add explicit timeout and failure handling
   - Verify all services (master, volume, filer)
   - Include diagnostic logging on failure
   - Prevents silent failures and obscure errors

These changes improve maintainability, security, and reliability
of the Spark integration test workflow.
This commit is contained in:
chrislu
2025-11-22 13:06:14 -08:00
parent b35463c8b4
commit 786f5de7bb
2 changed files with 127 additions and 82 deletions
+61 -39
View File
@@ -19,11 +19,16 @@ on:
- '.github/workflows/spark-integration-tests.yml'
workflow_dispatch:
permissions:
contents: read
checks: write
pull-requests: write
jobs:
spark-tests:
name: Spark Integration Tests
build-deps:
name: Build SeaweedFS Dependencies
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 15
steps:
- name: Checkout code
@@ -70,6 +75,37 @@ jobs:
mvn clean install -DskipTests -Dgpg.skip=true
echo "✓ HDFS3 client built"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: seaweedfs-build
path: |
docker/weed
~/.m2/repository/com/seaweedfs
retention-days: 1
spark-tests:
name: Spark Integration Tests
runs-on: ubuntu-latest
needs: build-deps
timeout-minutes: 30
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: seaweedfs-build
path: .
- name: Start SeaweedFS services
working-directory: test/java/spark
run: |
@@ -157,7 +193,7 @@ jobs:
spark-example:
name: Run Spark Example Application
runs-on: ubuntu-latest
needs: spark-tests
needs: [build-deps, spark-tests]
timeout-minutes: 20
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
@@ -170,38 +206,12 @@ jobs:
with:
java-version: '11'
distribution: 'temurin'
cache: maven
- name: Set up Go
uses: actions/setup-go@v5
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
go-version: '1.24'
- name: Build SeaweedFS binary
run: |
echo "Building SeaweedFS binary..."
cd weed
go build -o ../docker/weed
cd ../docker
ls -la weed filer.toml entrypoint.sh
echo "✓ SeaweedFS binary built and ready for Docker build"
- name: Build SeaweedFS Java dependencies
run: |
echo "Building Java client..."
cd other/java/client
mvn clean install -DskipTests -Dgpg.skip=true
cd ../../..
echo "Building HDFS2 client..."
cd other/java/hdfs2
mvn clean install -DskipTests -Dgpg.skip=true
cd ../../..
echo "Building HDFS3 client..."
cd other/java/hdfs3
mvn clean install -DskipTests -Dgpg.skip=true
echo "✓ All Java dependencies built"
name: seaweedfs-build
path: .
- name: Cache Apache Spark
id: cache-spark
@@ -226,17 +236,29 @@ jobs:
- name: Start SeaweedFS services
working-directory: test/java/spark
run: |
docker compose up -d
sleep 10
echo "Starting SeaweedFS with Docker Compose..."
docker compose up -d seaweedfs-master seaweedfs-volume seaweedfs-filer
# Wait for filer to be ready
for i in {1..20}; do
echo "Waiting for SeaweedFS filer to be ready..."
for i in {1..30}; do
if curl -f http://localhost:8888/ > /dev/null 2>&1; then
echo "✓ SeaweedFS is ready"
echo "✓ SeaweedFS filer is ready!"
break
fi
if [ $i -eq 30 ]; then
echo "✗ SeaweedFS failed to start after 60 seconds"
docker compose logs
exit 1
fi
echo "Waiting... ($i/30)"
sleep 2
done
# Verify all services
echo "Verifying SeaweedFS services..."
curl -f http://localhost:9333/cluster/status || exit 1
curl -f http://localhost:8888/ || exit 1
echo "✓ All SeaweedFS services are healthy"
- name: Build project
working-directory: test/java/spark