Skip to content

Create CI cache

Create CI cache #48

on:
workflow_dispatch:
inputs:
pr_url:
required: true
type: string
description: 'The url of the pull_request json object that contains the information about the PR on which the slash command was triggered.'
comment_id:
required: false
type: string
description: 'The id of the comment that contains the slash command that triggered this workflow.'
name: Create CI cache
jobs:
config:
name: Determine PR info
runs-on: ubuntu-latest
outputs:
pull_request_number: ${{ steps.pr_info.outputs.pull_request_number }}
steps:
- name: Download PR info
id: pr_info
run: |
pr_info=`wget -O - ${{ inputs.pr_url }}`
pr_nr=`echo $pr_info | jq -r '.number'`
head_label=`echo $pr_info | jq -r '.head.label'`
head_sha=`echo $pr_info | jq -r '.head.sha'`
base_ref=`echo $pr_info | jq -r '.base.ref'`
echo "target_branch=$base_ref" >> $GITHUB_OUTPUT
echo "source_label=$head_label" >> $GITHUB_OUTPUT
echo "source_sha=$head_sha" >> $GITHUB_OUTPUT
echo "pull_request_number=$pr_nr" >> $GITHUB_OUTPUT
- name: Add reaction
if: inputs.comment_id
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ inputs.comment_id }}
body: |
Running workflow from ${{ github.ref_type }} `${{ github.ref_name }}`. The created cache will be owned by that branch.
Checking out source code from head `${{ steps.pr_info.outputs.source_label }}` (sha: ${{ steps.pr_info.outputs.source_sha }}).
edit-mode: append
repoinfo:
name: Configure build
needs: config
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
llvm_commit: ${{ steps.repo_info.outputs.llvm_commit }}
pybind11_commit: ${{ steps.repo_info.outputs.pybind11_commit }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: "${{ format('refs/pull/{0}/merge', needs.config.outputs.pull_request_number) }}"
- id: repo_info
run: |
echo "llvm_commit=$(git rev-parse @:./tpls/llvm)" >> $GITHUB_OUTPUT
echo "pybind11_commit=$(git rev-parse @:./tpls/pybind11)" >> $GITHUB_OUTPUT
devdeps_caches:
name: Cache dev dependencies
needs: [config, repoinfo]
strategy:
matrix:
platform: [amd64, arm64]
toolchain: [llvm, clang16, gcc12]
fail-fast: false
uses: ./.github/workflows/dev_environment.yml
with:
platforms: linux/${{ matrix.platform }}
dockerfile: build/devdeps.Dockerfile
toolchain: ${{ matrix.toolchain }}
build_args: |
llvm_commit=${{ needs.repoinfo.outputs.llvm_commit }}
pybind11_commit=${{ needs.repoinfo.outputs.pybind11_commit }}
create_local_cache: true
registry_cache_from: ${{ needs.config.outputs.target_branch }}
pull_request_number: ${{ needs.config.outputs.pull_request_number }}
# needed only for the cloudposse GitHub action
matrix_key: ${{ matrix.platform }}-${{ matrix.toolchain }}
wheeldeps_caches:
name: Cache wheel dependencies
needs: [config, repoinfo]
strategy:
matrix:
platform: [amd64, arm64]
fail-fast: false
uses: ./.github/workflows/dev_environment.yml
with:
platforms: linux/${{ matrix.platform }}
dockerfile: build/devdeps.manylinux.Dockerfile
toolchain: gcc11
build_args: |
manylinux_image=manylinux_2_28
arch=${{ (matrix.platform == 'arm64' && 'aarch64') || (matrix.platform == 'amd64' && 'x86_64') || 'any' }}
distro=rhel8
llvm_commit=${{ needs.repoinfo.outputs.llvm_commit }}
pybind11_commit=${{ needs.repoinfo.outputs.pybind11_commit }}
create_local_cache: true
registry_cache_from: ${{ needs.config.outputs.target_branch }}
pull_request_number: ${{ needs.config.outputs.pull_request_number }}
# needed only for the cloudposse GitHub action
matrix_key: ${{ matrix.platform }}-python
finalize:
name: Indicate completion
runs-on: ubuntu-latest
needs: [devdeps_caches, wheeldeps_caches]
# We need to clean up even if the workflow is cancelled or fails.
if: always()
steps:
- name: Add reaction to comment
if: inputs.comment_id && success()
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ inputs.comment_id }}
reactions-edit-mode: append
reactions: hooray
- uses: cloudposse/[email protected]
id: read_json
with:
matrix-step-name: dev_environment
- run: |
set -e
key_matrix='${{ steps.read_json.outputs.result }}'
keys=`echo $key_matrix | jq '.cache_key | to_entries | .[].value' --raw-output`
gh extension install actions/gh-actions-cache
for key in $keys; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}