-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ccache in CIs. Set up GitHub Cache for storing the ccache data.
- Loading branch information
1 parent
923c655
commit 2e491a8
Showing
12 changed files
with
374 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: CleanUpCachePostPR | ||
|
||
on: | ||
workflow_run: | ||
workflows: [PostPR] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
CleanUpCcacheCachePostPR: | ||
name: Clean Up Ccahe Cache Post PR | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: write | ||
contents: read | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Clean up ccahe | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
REPO=${{ github.repository }} | ||
gh run download ${{ github.event.workflow_run.id }} -n pr_number | ||
pr_number=`cat pr_number.txt` | ||
BRANCH=refs/pull/${pr_number}/merge | ||
# Setting this to not fail the workflow while deleting cache keys. | ||
set +e | ||
keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1) | ||
# $keys might contain spaces. Thus we set IFS to \n. | ||
IFS=$'\n' | ||
for k in $keys | ||
do | ||
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm | ||
done | ||
unset IFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: CleanUpCache | ||
|
||
on: | ||
workflow_run: | ||
workflows: [👑 CI] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
CleanUpCcacheCache: | ||
name: Clean Up Ccahe Cache for ${{ github.event.workflow_run.name }} | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: write | ||
contents: read | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Clean up ccahe | ||
run: | | ||
gh extension install actions/gh-actions-cache | ||
REPO=${{ github.repository }} | ||
# push or pull_request or schedule or ... | ||
EVENT=${{ github.event.workflow_run.event }} | ||
# Triggering workflow run name (e.g., LinuxClang) | ||
WORKFLOW_NAME="${{ github.event.workflow_run.name }}" | ||
if [[ $EVENT == "pull_request" ]]; then | ||
gh run download ${{ github.event.workflow_run.id }} -n pr_number | ||
pr_number=`cat pr_number.txt` | ||
BRANCH=refs/pull/${pr_number}/merge | ||
else | ||
BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }} | ||
fi | ||
# Setting this to not fail the workflow while deleting cache keys. | ||
set +e | ||
# In our cache keys, substring after `-git-` is git hash, substring | ||
# before that is a unique id for jobs (e.g., `ccache-LinuxClang-configure-2d`). | ||
# The goal is to keep the last used key of each job and delete all others. | ||
# something like ccache-LinuxClang- | ||
keyprefix="ccache-${WORKFLOW_NAME}-" | ||
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq) | ||
# cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d". | ||
# It might also contain spaces. Thus we set IFS to \n. | ||
IFS=$'\n' | ||
for j in $cached_jobs | ||
do | ||
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2) | ||
for k in $old_keys | ||
do | ||
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm | ||
done | ||
done | ||
unset IFS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ $# -eq 2 ]]; then | ||
CVER=$1 | ||
else | ||
CVER=4.8 | ||
fi | ||
|
||
wget https://github.com/ccache/ccache/releases/download/v${CVER}/ccache-${CVER}-linux-x86_64.tar.xz | ||
tar xvf ccache-${CVER}-linux-x86_64.tar.xz | ||
sudo mv -f ccache-${CVER}-linux-x86_64/ccache /usr/local/bin/ | ||
sudo rm -rf ccache-${CVER}-linux-x86_64 | ||
sudo rm -f ccache-${CVER}-linux-x86_64.tar.xz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: PostPR | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
|
||
jobs: | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Save PR number | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
run: | | ||
echo $PR_NUMBER > pr_number.txt | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: pr_number | ||
path: pr_number.txt | ||
retention-days: 1 |
Oops, something went wrong.