Skip to content

Workflows: Add composite actions for managing sccache caches for a PR #101578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tstellar
Copy link
Collaborator

@tstellar tstellar commented Aug 1, 2024

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2024

@llvm/pr-subscribers-github-workflow

Author: Tom Stellard (tstellar)

Changes

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 --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@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
+

@tru
Copy link
Collaborator

tru commented Aug 2, 2024

Will the cache always be empty the first time we build a PR? Shouldn't we want a cache from whatever basenline as a fallback so that we can get some cache hits when we build the PR the first time?

@tstellar
Copy link
Collaborator Author

tstellar commented Aug 2, 2024

Will the cache always be empty the first time we build a PR? Shouldn't we want a cache from whatever basenline as a fallback so that we can get some cache hits when we build the PR the first time?

In the first run, this action will do nothing, so whatever cache you had in place when you ran the ccache-action step will still be there.

Here is an example usage:

- name: Restore sccache from previous PR run

In this example we have the ccache-action configured to use a cache shared by other PRs (and potentially pushes to main if we wanted to set it up that way).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants