buil.yml with cleanup

This commit is contained in:
2025-07-29 11:40:22 +02:00
parent a7d8c4fb33
commit f8d2a5c483

View File

@@ -57,19 +57,31 @@ jobs:
id: build id: build
working-directory: ${{ needs.detect-project.outputs.project-dir }} working-directory: ${{ needs.detect-project.outputs.project-dir }}
run: | run: |
set -e
cargo build --release --target x86_64-unknown-linux-gnu cargo build --release --target x86_64-unknown-linux-gnu
binary_name=$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
- name: Strip debug symbols - name: Strip debug symbols
if: success()
working-directory: ${{ needs.detect-project.outputs.project-dir }} working-directory: ${{ needs.detect-project.outputs.project-dir }}
run: strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2) run: |
set -e
strip target/x86_64-unknown-linux-gnu/release/$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
- name: Upload Linux artifact - name: Upload Linux artifact
if: success()
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ${{ needs.detect-project.outputs.project-dir }}-linux name: ${{ needs.detect-project.outputs.project-dir }}-linux
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ steps.build.outputs.binary_name }} path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-unknown-linux-gnu/release/${{ steps.build.outputs.binary_name }}
- name: Cleanup on failure
if: failure()
run: |
echo "Cleaning up Docker images..."
docker system prune -a -f || echo "Docker cleanup failed"
windows-cross: windows-cross:
name: Windows Cross-Compile name: Windows Cross-Compile
needs: detect-project needs: detect-project
@@ -87,19 +99,43 @@ jobs:
override: true override: true
- name: Install mingw cross-compiler - name: Install mingw cross-compiler
run: sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64 run: |
set -e
sudo apt-get update && sudo apt-get install -y gcc-mingw-w64-x86-64
- name: Build Windows binary - name: Build Windows binary
working-directory: ${{ needs.detect-project.outputs.project-dir }} working-directory: ${{ needs.detect-project.outputs.project-dir }}
id: build id: build
run: | run: |
set -e
cargo build --release --target x86_64-pc-windows-gnu cargo build --release --target x86_64-pc-windows-gnu
binary_name=$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2) binary_name=$(grep -m1 '^name =' Cargo.toml | cut -d'"' -f2)
x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/$binary_name.exe x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/$binary_name.exe
echo "binary_name=$binary_name" >> $GITHUB_OUTPUT echo "binary_name=$binary_name" >> $GITHUB_OUTPUT
- name: Upload Windows artifact - name: Upload Windows artifact
if: success()
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: ${{ needs.detect-project.outputs.project-dir }}-windows name: ${{ needs.detect-project.outputs.project-dir }}-windows
path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ steps.build.outputs.binary_name }}.exe path: ${{ needs.detect-project.outputs.project-dir }}/target/x86_64-pc-windows-gnu/release/${{ steps.build.outputs.binary_name }}.exe
- name: Cleanup on failure
if: failure()
run: |
echo "Cleaning up Docker images..."
docker system prune -a -f || echo "Docker cleanup failed"
cleanup:
name: Cleanup
if: always()
needs: [native-build, windows-cross]
runs-on: ubuntu-latest
steps:
- name: Cleanup Docker images
if: contains(needs.*.result, 'failure')
run: |
echo "One or more jobs failed. Performing cleanup..."
docker system prune -a -f || echo "Docker cleanup failed"
env:
DOCKER_CLI_HINTS: false