44 push :
55 branches : [ "master" ]
66 tags : [ 'v*.*.*' ]
7- paths :
8- - ' backend/**'
9- - ' frontend/**'
10- - ' docker/**'
11- - ' Dockerfile'
12- - ' docker-compose.yml'
13- - ' .github/workflows/**'
147 pull_request :
158 branches : [ "master" ]
16- paths :
17- - ' backend/**'
18- - ' frontend/**'
19- - ' docker/**'
20- - ' Dockerfile'
21- - ' docker-compose.yml'
22- - ' .github/workflows/**'
239
2410env :
2511 IMAGE_NAME : dunajdev/docker-mailserver-gui
@@ -30,39 +16,67 @@ jobs:
3016 permissions :
3117 contents : read
3218 packages : write
19+ pull-requests : read # Needed for tj-actions/changed-files on PRs
3320
3421 steps :
3522 - name : Checkout repository
3623 uses : actions/checkout@v4
24+ with :
25+ # Fetch history to compare files (important for PRs)
26+ fetch-depth : ${{ github.event_name == 'pull_request' && 2 || 0 }}
27+
28+ - name : Check for relevant file changes
29+ id : check_changes
30+ uses : tj-actions/changed-files@v44 # Use a recent version
31+ with :
32+ files : |
33+ backend/**
34+ frontend/**
35+ docker/**
36+ Dockerfile
37+ docker-compose.yml
38+ .github/workflows/**
39+ files_ignore : |
40+ **.md
41+ backend/db.json
42+
43+ # --- Conditional Steps ---
44+ # Run subsequent steps only if relevant files were changed
3745
3846 - name : Set up Node.js
47+ if : steps.check_changes.outputs.any_changed == 'true'
3948 uses : actions/setup-node@v4
4049 with :
4150 node-version : ' 20' # Use a recent LTS version
4251
4352 - name : Install backend dependencies and check formatting
53+ if : steps.check_changes.outputs.any_changed == 'true'
4454 run : |
4555 cd backend
4656 npm ci
4757 npm run format:check
4858
4959 - name : Install frontend dependencies and check formatting
60+ if : steps.check_changes.outputs.any_changed == 'true'
5061 run : |
5162 cd frontend
5263 npm ci
5364 npm run format:check
5465
5566 - name : Set up Docker Buildx
67+ if : steps.check_changes.outputs.any_changed == 'true'
5668 uses : docker/setup-buildx-action@v3
5769
5870 - name : Log in to Docker Hub
59- if : github.event_name != 'pull_request'
71+ # Also check if relevant files changed
72+ if : steps.check_changes.outputs.any_changed == 'true' && github.event_name != 'pull_request'
6073 uses : docker/login-action@v3
6174 with :
6275 username : ${{ secrets.DOCKERHUB_USERNAME }}
6376 password : ${{ secrets.DOCKERHUB_TOKEN }}
6477
6578 - name : Extract metadata for Docker
79+ if : steps.check_changes.outputs.any_changed == 'true'
6680 id : meta
6781 uses : docker/metadata-action@v5
6882 with :
7690 type=raw,value=latest,enable={{is_default_branch}}
7791
7892 - name : Build and push Docker image
93+ if : steps.check_changes.outputs.any_changed == 'true'
7994 uses : docker/build-push-action@v5
8095 with :
8196 context : .
97+ # Push condition remains the same, but the whole step is conditional
8298 push : ${{ github.event_name != 'pull_request' }}
8399 tags : ${{ steps.meta.outputs.tags }}
84100 labels : ${{ steps.meta.outputs.labels }}
0 commit comments