[llvm] Workflows: Add composite actions for managing sccache caches for a PR (PR #101578)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 16:08:29 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

<details>
<summary>Changes</summary>

These actions allow you to create and reusue an sccache cache that is unique to a PR.  This way each time you update a PR you will be able to resuse the sccache cache from the previous PR build.  This will help increase the cache hit rate vs trying to use a global cache that is share amongst several PRs.

---
Full diff: https://github.com/llvm/llvm-project/pull/101578.diff


2 Files Affected:

- (added) .github/workflows/pr-sccache-restore/action.yml (+26) 
- (added) .github/workflows/pr-sccache-save/action.yml (+27) 


``````````diff
diff --git a/.github/workflows/pr-sccache-restore/action.yml b/.github/workflows/pr-sccache-restore/action.yml
new file mode 100644
index 0000000000000..8aa87025ba54b
--- /dev/null
+++ b/.github/workflows/pr-sccache-restore/action.yml
@@ -0,0 +1,26 @@
+name: PR sccache restore
+
+inputs:
+  artifact-name-suffix:
+    desciption: The suffix to append to the artifict name (sccache-pr#)
+    required: true
+
+runs:
+  using: "composite"
+  steps:
+    - uses: ./.github/workflows/unprivileged-download-artifact
+      id: download-artifact
+      with:
+        artifact-name: sccache-pr${{ github.event.pull_request.number }}-${{ inputs.artifact-name-suffix }}
+
+    - shell: bash
+      if: steps.download-artifact.outputs.filename != ''
+      run: |
+        # Is this the best way to clear the cache?
+        rm -Rf .sccache/
+        unzip ${{ steps.download-artifact.outputs.filename }}
+        rm ${{ steps.download-artifact.outputs.filename }}
+        tar --zstd -xf sccache.tar.zst
+        rm sccache.tar.zst
+        ls -altr
+
diff --git a/.github/workflows/pr-sccache-save/action.yml b/.github/workflows/pr-sccache-save/action.yml
new file mode 100644
index 0000000000000..badf623d32d5e
--- /dev/null
+++ b/.github/workflows/pr-sccache-save/action.yml
@@ -0,0 +1,27 @@
+name: PR sccache save
+inputs:
+  artifact-name-suffix:
+    desciption: The suffix to append to the artifict name (sccache-pr#)
+    required: true
+
+runs:
+  using: "composite"
+  steps:
+    - name: Package sccache Directory
+      shell: bash
+      run: |
+        # Dereference symlinks so that this works on Windows.
+        tar -h -c .sccache | zstd -T0 -c > sccache.tar.zst
+
+    - uses: actions/upload-artifact at 26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
+      with:
+        name: 'sccache-pr${{ github.event.number }}-${{ inputs.artifact-name-suffix }}'
+        path: sccache.tar.zst
+        retention-days: 7
+        overwrite: true
+
+    - shell: bash
+      run: |
+        rm sccache.tar.zst
+        sccache --show-stats
+

``````````

</details>


https://github.com/llvm/llvm-project/pull/101578


More information about the llvm-commits mailing list