Skip to content

Commit

Permalink
ci: utilize cache for SDK and Imagebuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
blocktrron committed Jul 28, 2024
1 parent 61bb034 commit 8d72a2c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
53 changes: 52 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,23 @@ jobs:
${{ steps.build-metadata.outputs.imagebuilder-name }}
imagebuilder-url:
${{ steps.build-metadata.outputs.imagebuilder-url }}
cache-key:
${{ steps.cache-key.outputs.cache-key }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
submodules: true
- name: Determine Version
id: build-metadata
run: bash $GITHUB_WORKSPACE/contrib/get-version.sh
- name: Determine Cache-Key
id: cache-key
run: >
echo "cache-key=$(bash $GITHUB_WORKSPACE/contrib/cache-key.sh
$GITHUB_WORKSPACE ${{ steps.build-metadata.outputs.sdk-url }})" >> "$GITHUB_OUTPUT"
- name: Create Artifact of build-meta
uses: actions/upload-artifact@v4
with:
Expand All @@ -47,24 +55,48 @@ jobs:
- name: Install dependencies
run: |
$GITHUB_WORKSPACE/contrib/install-deps.sh
- name: Determine Cache-Key
id: cache-key-sdk
run: >
echo "cache-key=sdk-${{ needs.build-meta.outputs.cache-key }}" >> "$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
Expand Down Expand Up @@ -100,16 +132,35 @@ jobs:
- name: Show binary output directory structure
run: |
tree /tmp/packages
- name: Determine Cache-Key
id: cache-key-ib
run: >
echo "cache-key=ib-${{ needs.build-meta.outputs.cache-key }}" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: |
$GITHUB_WORKSPACE/contrib/install-deps.sh
- name: Restore Cache
id: restore-cache-ib
uses: actions/cache/restore@v4
with:
path: /tmp/openwrt-imagebuilder
key: ${{ steps.cache-key-ib.outputs.cache-key }}
- name: Download Imagebuilder
if: steps.restore-cache-ib.outputs.cache-hit != 'true'
run: |
curl -o /tmp/openwrt-imagebuilder.tar.xz ${{ needs.build-meta.outputs.imagebuilder-url }}
- name: Extract Imagebuilder
if: steps.restore-cache-ib.outputs.cache-hit != 'true'
run: |
tar -xf /tmp/openwrt-imagebuilder.tar.xz -C /tmp
mv /tmp/${{ needs.build-meta.outputs.imagebuilder-name }} /tmp/openwrt-imagebuilder
- name: Save cache
if: steps.restore-cache-ib.outputs.cache-hit != 'true'
id: save-cache-ib
uses: actions/cache/save@v4
with:
path: /tmp/openwrt-imagebuilder
key: ${{ steps.cache-key-ib.outputs.cache-key }}
- name: Link repositories
run: |
sed -i '/^option check_signature/d' /tmp/openwrt-imagebuilder/repositories.conf
Expand Down
15 changes: 15 additions & 0 deletions contrib/cache-key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

WORKSPACE_DIR="$1"
SDK_URL="$2"

if [ -z "$WORKSPACE_DIR" ] || [ -z "$SDK_URL" ]; then
echo "Usage: $0 <workspace_dir> <sdk_url>"
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="$PACKAGES_SUBMODULE_REV-$SDK_URL_HASH"

echo "$CACHE_KEY"

0 comments on commit 8d72a2c

Please sign in to comment.