Skip to content

Commit

Permalink
build: try to cache source tarballs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhx committed Aug 13, 2024
1 parent 03d6b14 commit bc7ef74
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
21 changes: 13 additions & 8 deletions .docker/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ 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"
rm -f /workspace/dwarfs-*.tar.zst
ln -s dwarfs-* dwarfs
else
git config --global --add safe.directory /workspace
Expand Down Expand Up @@ -311,8 +317,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-* ]] && \
Expand Down
24 changes: 19 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ permissions:

jobs:
windows:
if: false
runs-on:
- self-hosted
- Windows
Expand Down Expand Up @@ -136,17 +137,21 @@ 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:
name: dwarfs-source
path: ${{ runner.temp }}/artifacts/dwarfs-source-${{ github.run_number }}.tar.zst
key: run-${{ github.run_number }}

linux-src:
needs: package-source

Expand Down Expand Up @@ -213,7 +218,15 @@ 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:
name: dwarfs-source
key: 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
Expand Down Expand Up @@ -247,6 +260,7 @@ jobs:
dwarfs-linux-build-${{ matrix.dist }}
linux-git:
if: false
strategy:
matrix:
arch:
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit bc7ef74

Please sign in to comment.