From 4f4ccf76498f8786ec414d03cfa39aa6d511fd7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Tue, 11 Apr 2023 16:13:54 +0200 Subject: [PATCH] Github workflow build cache (#4150) Cache intermediary build artefacts to speed up build time. --- .github/actions/restore-git-mtimes/action.yml | 14 +++++ .github/workflows/unit_tests.yml | 63 +++++++++++++++++++ ci/build-ci.sh | 6 +- 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 .github/actions/restore-git-mtimes/action.yml diff --git a/.github/actions/restore-git-mtimes/action.yml b/.github/actions/restore-git-mtimes/action.yml new file mode 100644 index 000000000..714c72021 --- /dev/null +++ b/.github/actions/restore-git-mtimes/action.yml @@ -0,0 +1,14 @@ +name: "restore-git-mtimes" +description: "Restore file modification timestamps from git commit timestamps" +runs: + using: "composite" + steps: + - uses: actions/checkout@v3 + with: + repository: "MestreLion/git-tools" + ref: a42a069bc755f0fa81316965335cb33dbf22a968 # pin latest commit + path: "git-tools" + - run: $GITHUB_WORKSPACE/git-tools/git-restore-mtime + shell: bash + - run: git submodule foreach --recursive '$GITHUB_WORKSPACE/git-tools/git-restore-mtime' + shell: bash diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index a238afda2..a2c9f2f62 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -26,6 +26,18 @@ jobs: uses: actions/checkout@v3 with: submodules: "recursive" + fetch-depth: 0 # full history needed for restoring file timestamps + + - name: Restore Timestamps + uses: ./.github/actions/restore-git-mtimes + continue-on-error: true + + - name: Restore Build Cache + uses: actions/cache/restore@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-build-cache - name: Fetch Deps run: TEST=1 ci/actions/osx/install_deps.sh @@ -33,6 +45,15 @@ jobs: - name: Build Tests run: ci/build-ci.sh "/tmp/qt/lib/cmake/Qt5"; + - name: Save Build Cache + # only save build cache from develop to avoid polluting it by other branches / PRs + if: github.ref == 'refs/heads/develop' && success() + uses: actions/cache/save@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-build-cache + - name: Run Tests run: cd build && sudo TEST_USE_ROCKSDB=$TEST_USE_ROCKSDB ../ci/test.sh . env: @@ -60,6 +81,18 @@ jobs: uses: actions/checkout@v3 with: submodules: "recursive" + fetch-depth: 0 # full history needed for restoring file timestamps + + - name: Restore Timestamps + uses: ./.github/actions/restore-git-mtimes + continue-on-error: true + + - name: Restore Build Cache + uses: actions/cache/restore@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-${{ env.COMPILER }}-build-cache - name: Fetch Deps run: ci/actions/linux/install_deps.sh @@ -67,6 +100,15 @@ jobs: - name: Build Tests run: docker run -e TEST_USE_ROCKSDB -e RELEASE -v ${PWD}:/workspace nanocurrency/nano-env:${{ matrix.COMPILER }} /bin/bash -c "cd /workspace && ./ci/build-ci.sh /usr/lib/x86_64-linux-gnu/cmake/Qt5" + - name: Save Build Cache + # only save build cache from develop to avoid polluting it by other branches / PRs + if: github.ref == 'refs/heads/develop' && success() + uses: actions/cache/save@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-${{ env.COMPILER }}-build-cache + - name: Run Tests run: docker run -e RELEASE -e TEST_USE_ROCKSDB -e DEADLINE_SCALE_FACTOR -v ${PWD}:/workspace nanocurrency/nano-env:${{ matrix.COMPILER }} /bin/bash -c "cd /workspace/build && ../ci/test.sh ." env: @@ -92,6 +134,18 @@ jobs: uses: actions/checkout@v3 with: submodules: "recursive" + fetch-depth: 0 # full history needed for restoring file timestamps + + - name: Restore Timestamps + uses: ./.github/actions/restore-git-mtimes + continue-on-error: true + + - name: Restore Build Cache + uses: actions/cache/restore@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-build-cache - name: Windows Defender run: ci/actions/windows/disable_windows_defender.ps1 @@ -102,6 +156,15 @@ jobs: - name: Build Tests run: ci/actions/windows/build.ps1 + - name: Save Build Cache + # only save build cache from develop to avoid polluting it by other branches / PRs + if: github.ref == 'refs/heads/develop' && success() + uses: actions/cache/save@v3 + continue-on-error: true + with: + path: build + key: ${{ runner.os }}-build-cache + - name: Run Tests [TEST_USE_ROCKSDB=${{ env.TEST_USE_ROCKSDB }}] run: ci/actions/windows/run.ps1 env: diff --git a/ci/build-ci.sh b/ci/build-ci.sh index 16ff8deb3..2e11af84e 100755 --- a/ci/build-ci.sh +++ b/ci/build-ci.sh @@ -3,15 +3,12 @@ qt_dir=${1} build_target=${2:-all} -set -o errexit -set -o nounset -set -o xtrace OS=$(uname) source "$(dirname "$BASH_SOURCE")/impl/code-inspector.sh" code_inspect "${ROOTPATH:-.}" -mkdir build +mkdir -p build pushd build if [[ "${RELEASE:-false}" == "true" ]]; then @@ -49,7 +46,6 @@ cmake \ -DPORTABLE=1 \ -DNANO_WARN_TO_ERR=ON \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Debug} \ --DCMAKE_VERBOSE_MAKEFILE=ON \ -DQt5_DIR=${qt_dir} \ -DCI_TEST="1" \ ${BACKTRACE:-} \