[action] Save pbuilder cache daily and use it in each PR
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Fri, 26 Apr 2024 08:46:33 +0000 (17:46 +0900)
committerjaeyun-jung <39614140+jaeyun-jung@users.noreply.github.com>
Tue, 30 Apr 2024 09:25:47 +0000 (18:25 +0900)
- Let the daily job `update_pbuilder_cache.yml` save cache.
- Let the PR job `pdebuild.yml use proper cache for each arch.

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
.github/workflows/pdebuild.yml
.github/workflows/update_pbuilder_cache.yml [new file with mode: 0644]

index b6ed732..703b74b 100644 (file)
@@ -55,7 +55,23 @@ jobs:
         echo "Rebuild required: ${rebuild}"
         echo "rebuild=${rebuild}" >> "$GITHUB_ENV"
     - uses: actions/setup-python@v1
-    ## @todo Make cache works (daily update cache on main branch / restore the cache on each PR (w/o saving))
+
+    - name: make cache dir for pbuilder
+      ## prevent permission error
+      run: sudo mkdir --mode a=rwx --parents /var/cache/pbuilder
+
+    - name: restore pbuilder cache
+      id: restore-pbuilder-cache
+      if: env.rebuild == '1'
+      uses: actions/cache/restore@v4
+      with:
+        path: |
+          /var/cache/pbuilder/aptcache
+          /var/cache/pbuilder/base.tgz
+        key: pbuilder-cache-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('**/debian/control') }}
+        restore-keys: |
+          pbuilder-cache-${{ matrix.os }}-${{ matrix.arch }}-
+
     - name: prepare pdebuild
       if: env.rebuild == '1'
       run: |
@@ -69,7 +85,9 @@ jobs:
         cat ~/.pbuilderrc
         sudo mkdir -p /root/
         sudo ln -s ~/.pbuilderrc /root/
+
     - name: make pbuilder base.tgz
+      if: ${{ env.rebuild == '1' && steps.restore-pbuilder-cache.outputs.cache-hit != 'true' }}
       run: |
         echo "=== pbuilder create"
         echo "::group::pbuilder create --allow-untrusted"
@@ -82,6 +100,7 @@ jobs:
         echo "::group::pbuilder update"
         sudo pbuilder update
         echo "::endgroup"
+
     - name: run pdebuild
       if: env.rebuild == '1'
       run: |
diff --git a/.github/workflows/update_pbuilder_cache.yml b/.github/workflows/update_pbuilder_cache.yml
new file mode 100644 (file)
index 0000000..ce0502e
--- /dev/null
@@ -0,0 +1,67 @@
+name: Update pbuilder cache once a day
+
+on:
+  schedule:
+    # 04:00 AM (KST) Mon-Fri
+    - cron: "00 19 * * 0-4"
+
+  # Allow manually triggering the workflow
+  workflow_dispatch:
+
+jobs:
+  cache_pbuilder:
+    strategy:
+      matrix:
+        os: [ ubuntu-22.04 ]
+        arch: [ amd64 ]
+        include:
+          - distroname: jammy
+            os: ubuntu-22.04
+
+    runs-on: ${{ matrix.os }}
+    steps:
+      - uses: actions/checkout@v4
+      - uses: actions/setup-python@v1
+      - name: make cache dir for pbuilder
+        ## prevent permission error
+        run: sudo mkdir --mode a=rwx --parents /var/cache/pbuilder
+
+      - name: prepare pdebuild
+        run: |
+          echo "Installing build tools"
+          sudo add-apt-repository ppa:nnstreamer/ppa
+          echo "::group::apt-get update && apt-get install"
+          sudo apt-get update && sudo apt-get install -y pbuilder debootstrap curl ubuntu-dev-tools qemu-user-static debian-archive-keyring ubuntu-keyring debhelper
+          echo "::endgroup::"
+          echo "DISTRIBUTION=${{ matrix.distroname }}" > ~/.pbuilderrc
+          echo "OTHERMIRROR=\"deb [trusted=yes] http://archive.ubuntu.com/ubuntu ${{ matrix.distroname }}-backports universe |deb [trusted=yes] http://ppa.launchpad.net/nnstreamer/ppa/ubuntu ${{ matrix.distroname }} main\"" >> ~/.pbuilderrc
+          cat ~/.pbuilderrc
+          sudo mkdir -p /root/
+          sudo ln -s ~/.pbuilderrc /root/
+
+      - name: make pbuilder base.tgz
+        run: |
+          echo "=== pbuilder create"
+          echo "::group::pbuilder create --allow-untrusted"
+          sudo pbuilder create --allow-untrusted
+          echo "::endgroup::"
+          echo "=== pbuilder update"
+          echo "::group::pbuilder update --distribution ${{ matrix.distroname }}"
+          sudo pbuilder update --distribution ${{ matrix.distroname }}
+          echo "::endgroup"
+          echo "::group::pbuilder update"
+          sudo pbuilder update
+          echo "::endgroup"
+
+      - name: run pdebuild
+        run: |
+          pdebuild --architecture ${{ matrix.arch }} -- --distribution ${{ matrix.distroname }}
+
+      - name: save pbuilder cache
+        uses: actions/cache/save@v4
+        if: always()
+        with:
+          path: |
+            /var/cache/pbuilder/aptcache
+            /var/cache/pbuilder/base.tgz
+          key: pbuilder-cache-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles('**/debian/control') }}