@@ -2,8 +2,8 @@ name: Build and Release
22
33on :
44 push :
5- tags :
6- - ' v* ' # Trigger workflow on version tags (e.g., v1.0.0)
5+ paths :
6+ - ' **/*.c ' # Trigger workflow when any `.c` file changes
77 workflow_dispatch : # Allow manual triggering
88
99jobs :
@@ -21,35 +21,39 @@ jobs:
2121 choco install mingw -y
2222 echo "C:\Program Files\mingw-w64\bin" >> $env:GITHUB_PATH
2323
24- # Compile the C file
25- - name : Compile test.c
24+ # Find and compile all `.c` files in changed directories
25+ - name : Compile all changed files
2626 run : |
27- gcc C/test.c -o test.exe -mwindows
28-
29- # Upload the compiled binary as an artifact
30- - name : Upload artifact
27+ for dir in $(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -oE '^[^/]+/' | sort -u); do
28+ if [ -f "$dir/main.c" ]; then
29+ gcc "$dir/main.c" -o "$dir/main.exe" -mwindows
30+ fi
31+ done
32+
33+ # Upload all compiled binaries as artifacts
34+ - name : Upload artifacts
3135 uses : actions/upload-artifact@v4
3236 with :
33- name : test-exe
34- path : test .exe
37+ name : compiled-binaries
38+ path : ' **/* .exe'
3539
3640 release :
3741 needs : build
3842 runs-on : ubuntu-latest
3943
4044 steps :
41- # Download the compiled binary artifact
42- - name : Download artifact
45+ # Download the compiled binary artifacts
46+ - name : Download artifacts
4347 uses : actions/download-artifact@v4
4448 with :
45- name : test-exe
49+ name : compiled-binaries
4650
47- # Create a GitHub release and upload the binary
51+ # Create a GitHub release and upload all binaries
4852 - name : Create Release
4953 uses : ncipollo/release-action@v1
5054 with :
51- artifacts : test .exe
55+ artifacts : ' **/* .exe'
5256 token : ${{ secrets.GITHUB_TOKEN }}
5357 tag : ${{ github.ref_name }}
5458 name : Release ${{ github.ref_name }}
55- body : " This release contains the compiled binary of test.c ."
59+ body : " This release contains the compiled binaries for the changed files ."
0 commit comments