@@ -41,37 +41,35 @@ jobs:
4141 run : |
4242 if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
4343 if [ -n "${{ github.event.inputs.project }}" ]; then
44- # Use the manually specified project
4544 PROJECTS="[\"${{ github.event.inputs.project }}\"]"
4645 else
4746 # Auto-detect changed files (same logic as push events)
4847 CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
4948 CHANGED_DIRS=$(echo "$CHANGED_FILES" | grep -o "^[^/]*" | sort -u | grep -v "^$")
50- PROJECTS_WITH_DOCKERFILE =$(find . -maxdepth 2 -name "Dockerfile.sandbox" -not -path "*/\.*" | xargs dirname | xargs basename -a )
49+ ALL_PROJECT_DIRS =$(find . -maxdepth 1 -type d -not -path "*/\.*" -not -path "." | sed 's|^\./||' | grep -v "^_" )
5150 PROJECTS="["
5251 COMMA=""
5352 for DIR in $CHANGED_DIRS; do
54- if echo "$PROJECTS_WITH_DOCKERFILE " | grep -q "^$DIR$"; then
53+ if echo "$ALL_PROJECT_DIRS " | grep -q "^$DIR$"; then
5554 PROJECTS="${PROJECTS}${COMMA}\"${DIR}\""
5655 COMMA=","
5756 fi
5857 done
5958 PROJECTS="${PROJECTS}]"
6059 fi
6160 else
62- # Original push event logic
63- CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
64- CHANGED_DIRS=$(echo "$CHANGED_FILES" | grep -o "^[^/]*" | sort -u | grep -v "^$")
65- PROJECTS_WITH_DOCKERFILE=$(find . -maxdepth 2 -name "Dockerfile.sandbox" -not -path "*/\.*" | xargs dirname | xargs basename -a)
66- PROJECTS="["
67- COMMA=""
68- for DIR in $CHANGED_DIRS; do
69- if echo "$PROJECTS_WITH_DOCKERFILE" | grep -q "^$DIR$"; then
70- PROJECTS="${PROJECTS}${COMMA}\"${DIR}\""
71- COMMA=","
72- fi
73- done
74- PROJECTS="${PROJECTS}]"
61+ CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
62+ CHANGED_DIRS=$(echo "$CHANGED_FILES" | grep -o "^[^/]*" | sort -u | grep -v "^$")
63+ ALL_PROJECT_DIRS=$(find . -maxdepth 1 -type d -not -path "*/\.*" -not -path "." | sed 's|^\./||' | grep -v "^_")
64+ PROJECTS="["
65+ COMMA=""
66+ for DIR in $CHANGED_DIRS; do
67+ if echo "$ALL_PROJECT_DIRS" | grep -q "^$DIR$"; then
68+ PROJECTS="${PROJECTS}${COMMA}\"${DIR}\""
69+ COMMA=","
70+ fi
71+ done
72+ PROJECTS="${PROJECTS}]"
7573 fi
7674 echo "matrix=$PROJECTS" >> $GITHUB_OUTPUT
7775 echo "Projects to build: $PROJECTS"
8583 steps :
8684 - name : Checkout code
8785 uses : actions/checkout@v3
86+ with :
87+ fetch-depth : 0
88+ token : ${{ secrets.GITHUB_TOKEN }}
8889
8990 - name : Check for Dockerfile.sandbox
9091 id : check-dockerfile
@@ -93,28 +94,46 @@ jobs:
9394 echo "dockerfile_exists=true" >> $GITHUB_OUTPUT
9495 else
9596 echo "dockerfile_exists=false" >> $GITHUB_OUTPUT
96- echo "No Dockerfile.sandbox found in ${{ matrix.project }}, skipping ."
97+ echo "No Dockerfile.sandbox found in ${{ matrix.project }}, will generate one ."
9798 fi
9899
100+ - name : Set up Python
101+ if : steps.check-dockerfile.outputs.dockerfile_exists == 'false'
102+ uses : actions/setup-python@v4
103+ with :
104+ python-version : " 3.10"
105+
106+ - name : Generate Dockerfile.sandbox if needed
107+ if : steps.check-dockerfile.outputs.dockerfile_exists == 'false'
108+ run : |
109+ python generate_sandbox_dockerfile.py "${{ matrix.project }}"
110+ echo "Generated Dockerfile.sandbox for ${{ matrix.project }}"
111+
99112 - name : Set up Docker Buildx
100- if : steps.check-dockerfile.outputs.dockerfile_exists == 'true'
101113 uses : docker/setup-buildx-action@v2
102114
103115 - name : Login to DockerHub
104- if : steps.check-dockerfile.outputs.dockerfile_exists == 'true'
105116 uses : docker/login-action@v2
106117 with :
107118 username : ${{ secrets.DOCKERHUB_USERNAME }}
108- password : ${{ secrets.DOCKERHUB_PASSWORD}}
119+ password : ${{ secrets.DOCKERHUB_PASSWORD }}
109120
110121 - name : Build and push
111- if : steps.check-dockerfile.outputs.dockerfile_exists == 'true'
112122 uses : docker/build-push-action@v4
113123 with :
114124 context : .
115125 file : ${{ matrix.project }}/Dockerfile.sandbox
116126 push : true
117127 tags : |
118- zenmldocker/project -${{ matrix.project }}:latest
128+ safoinext/zenml-sandbox -${{ matrix.project }}:latest
119129 cache-from : type=gha
120130 cache-to : type=gha,mode=max
131+
132+ - name : Commit Dockerfile if newly generated
133+ if : steps.check-dockerfile.outputs.dockerfile_exists == 'false'
134+ run : |
135+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
136+ git config --local user.name "github-actions[bot]"
137+ git add "${{ matrix.project }}/Dockerfile.sandbox"
138+ git commit -m "Auto-generate Dockerfile.sandbox for ${{ matrix.project }}"
139+ git push || echo "Failed to push changes, but Docker image was still built and pushed."
0 commit comments