Create CI cache #39
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
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: Configure build | |
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 | |
devdeps_caches: | |
name: Cache dev dependencies | |
needs: config | |
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 }} | |
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 | |
uses: ./.github/workflows/dev_environment.yml | |
with: | |
dockerfile: build/devdeps.manylinux.Dockerfile | |
toolchain: gcc12 # set by the dockerfile and not configurable | |
build_args: | | |
manylinux_image=quay.io/pypa/manylinux_2_28_x86_64:latest | |
create_local_cache: true | |
registry_cache_from: ${{ needs.config.outputs.target_branch }} | |
pull_request_number: ${{ needs.config.outputs.pull_request_number }} | |
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` | |
keys+=" ${{ needs.wheeldeps_caches.outputs.cache_key }}" | |
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 }} |