From 0ea3436f7b93a2866bddedd9e29cd08fb6d58620 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 13 Aug 2024 13:12:18 +0200 Subject: [PATCH] build: try to cache source tarballs --- .docker/build-linux.sh | 20 +++++++++++-------- .github/workflows/build.yml | 39 ++++++++++++++++++++++++++++++++----- CMakeLists.txt | 3 --- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.docker/build-linux.sh b/.docker/build-linux.sh index 84ab0a22d..fa5e7bb08 100755 --- a/.docker/build-linux.sh +++ b/.docker/build-linux.sh @@ -44,12 +44,17 @@ cd "$HOME" rm -rf dwarfs dwarfs-* if [[ "$BUILD_FROM_TARBALL" == "1" ]]; then - # delete all but the latest tarball - ls -1 -r --sort=time /workspace/dwarfs-*.tar.zst | tail -n +2 | while read -r tarball; do - echo "deleting old tarball: $tarball" - rm -f "$tarball" - done - tar xf /workspace/dwarfs-*.tar.zst + TARBALL="dwarfs-source-${GITHUB_RUN_NUMBER}.tar.zst" + TARBALL_PATH="" + if [ -f "/tmp-runner/artifacts/$TARBALL" ]; then + TARBALL_PATH="/tmp-runner/artifacts" + elif [ -f "/workspace/$TARBALL" ]; then + TARBALL_PATH="/workspace" + else + echo "source tarball not found: $TARBALL" + exit 1 + fi + tar xf "$TARBALL_PATH/$TARBALL" ln -s dwarfs-* dwarfs else git config --global --add safe.directory /workspace @@ -311,8 +316,7 @@ else $BUILD_TOOL copy_source_artifacts rm -rf /tmp-runner/artifacts mkdir -p /tmp-runner/artifacts - cp source-artifacts.env /tmp-runner - cp dwarfs-*.tar.zst /tmp-runner/artifacts + cp dwarfs-*.tar.zst /tmp-runner/artifacts/dwarfs-source-${GITHUB_RUN_NUMBER}.tar.zst fi if [[ "-$BUILD_TYPE-" != *-[at]san-* ]] && \ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9641fcc40..744ede248 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,7 @@ permissions: jobs: windows: + if: false runs-on: - self-hosted - Windows @@ -136,17 +137,20 @@ jobs: --env GITHUB_RUN_ATTEMPT \ dwarfs-linux-build-arch - - name: Prepare Artifact Upload - run: cat ${{ runner.temp }}/source-artifacts.env >> $GITHUB_ENV - - name: Upload Source Package uses: actions/upload-artifact@v4 with: name: dwarfs-source - path: ${{ runner.temp }}/artifacts/${{ env.source_tarball }} + path: ${{ runner.temp }}/artifacts/dwarfs-source-${{ github.run_number }}.tar.zst if-no-files-found: error compression-level: 0 + - name: Cache Source Tarball + uses: actions/cache/save@v4 + with: + path: ${{ runner.temp }}/artifacts/dwarfs-source-${{ github.run_number }}.tar.zst + key: dwarfs-source-run-${{ github.run_number }} + linux-src: needs: package-source @@ -213,11 +217,32 @@ jobs: fetch-depth: '0' ref: ${{ github.ref }} - - name: Download Source Tarball + - name: Fetch Source Tarball From Cache + id: source-tarball + uses: actions/cache/restore@v4 + with: + path: ${{ runner.temp }}/artifacts/dwarfs-source-${{ github.run_number }}.tar.zst + key: dwarfs-source-run-${{ github.run_number }} + + - name: Download Source Tarball Artifact + if: steps.source-tarball.outputs.cache-hit != 'true' uses: actions/download-artifact@v4 with: name: dwarfs-source + - name: Move Tarball To Artifacts Location + if: steps.source-tarball.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ runner.temp }}/artifacts + mv ${GITHUB_WORKSPACE}/dwarfs-source-${{ github.run_number }}.tar.zst ${{ runner.temp }}/artifacts/ + + - name: Re-cache Source Tarball + if: steps.source-tarball.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ runner.temp }}/artifacts/dwarfs-source-${{ github.run_number }}.tar.zst + key: dwarfs-source-run-${{ github.run_number }} + - name: Build Docker Image run: | docker build \ @@ -246,7 +271,11 @@ jobs: --env GITHUB_RUN_ATTEMPT \ dwarfs-linux-build-${{ matrix.dist }} + - name: Remove Source Tarballs + run: rm -vf ${GITHUB_WORKSPACE}/dwarfs-*.tar.zst + linux-git: + if: false strategy: matrix: arch: diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bf0e79f2..0c8c79216 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -855,9 +855,6 @@ if(DEFINED ENV{GITHUB_REF_TYPE}) set(PACKAGE_EXT ".tar.zst") endif() - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/source-artifacts.env" - "source_tarball=${CMAKE_PROJECT_NAME}-${PRJ_VERSION_FULL}${PACKAGE_EXT}\n") - add_custom_target(copy_source_artifacts COMMAND ${CMAKE_COMMAND} -E make_directory ${ARTIFACTS_FULL_PATH} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}-${PRJ_VERSION_FULL}${PACKAGE_EXT} ${ARTIFACTS_FULL_PATH}