-
Notifications
You must be signed in to change notification settings - Fork 191
147 lines (131 loc) · 5.13 KB
/
create_cache_command.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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 }}