From e540f15e16a985425a201894f5260c0eb57d7079 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Sun, 28 Jul 2024 02:49:50 +0200 Subject: [PATCH] ci: utilize cache for SDK --- .github/workflows/build.yaml | 27 ++++++++++++++++++++++++++- contrib/cache-key-sdk.sh | 13 +++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 contrib/cache-key-sdk.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 7186a3e..2897ff9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -47,24 +47,49 @@ jobs: - name: Install dependencies run: | $GITHUB_WORKSPACE/contrib/install-deps.sh + - name: Determine Cache-Key + id: cache-key-sdk + run: > + echo "cache-key=$(bash $GITHUB_WORKSPACE/contrib/cache-key.sh + $GITHUB_WORKSPACE ${{ needs.build-meta.outputs.sdk-url }})" >> "$GITHUB_OUTPUT" + - name: Restore Cache + id: restore-cache-sdk + uses: actions/cache/restore@v4 + with: + path: /tmp/openwrt-sdk + key: ${{ steps.cache-key-sdk.outputs.cache-key }} - name: Download SDK + if: steps.restore-cache-sdk.outputs.cache-hit != 'true' run: | curl -o /tmp/openwrt-sdk.tar.xz ${{ needs.build-meta.outputs.sdk-url }} - name: Extract SDK + if : steps.restore-cache-sdk.outputs.cache-hit != 'true' run: | tar -xf /tmp/openwrt-sdk.tar.xz -C /tmp ls /tmp mv /tmp/${{ needs.build-meta.outputs.sdk-name }} /tmp/openwrt-sdk - name: Create feeds.conf + if: steps.restore-cache-sdk.outputs.cache-hit != 'true' run: | cp /tmp/openwrt-sdk/feeds.conf.default /tmp/openwrt-sdk/feeds.conf echo "src-link oobfw $GITHUB_WORKSPACE/openwrt" >> /tmp/openwrt-sdk/feeds.conf echo "src-link oobpkgs $GITHUB_WORKSPACE/packages" >> /tmp/openwrt-sdk/feeds.conf - - name: Init SDK + - name: Install SDK feeds + if: steps.restore-cache-sdk.outputs.cache-hit != 'true' run: | cd /tmp/openwrt-sdk ./scripts/feeds update -a ./scripts/feeds install -a + - name: Save cache + id: save-cache-sdk + if: steps.restore-cache-sdk.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: /tmp/openwrt-sdk + key: ${{ steps.cache-key-sdk.outputs.cache-key }} + - name: Create SDK configuration + run: | + cd /tmp/openwrt-sdk echo "# CONFIG_SIGNED_PACKAGES is not set" > /tmp/openwrt-sdk/.config echo CONFIG_FFDA_OOB_FIRMWARE_VERSION=\"${{ needs.build-meta.outputs.firmware-version }}\" >> /tmp/openwrt-sdk/.config make defconfig diff --git a/contrib/cache-key-sdk.sh b/contrib/cache-key-sdk.sh new file mode 100755 index 0000000..a5fd998 --- /dev/null +++ b/contrib/cache-key-sdk.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +WORKSPACE_DIR="$1" +SDK_URL="$2" + +if [ -z "$WORKSPACE_DIR" ] || [ -z "$SDK_URL" ]; then + echo "Usage: $0 " + exit 1 +fi + +PACKAGES_SUBMODULE_REV="$(git -C "$WORKSPACE_DIR/packages" rev-parse HEAD)" +SDK_URL_HASH="$(echo "$SDK_URL" | sha256sum | cut -d ' ' -f 1)" +CACHE_KEY="sdk-$PACKAGES_SUBMODULE_REV-$SDK_URL_HASH" \ No newline at end of file