Skip to content

Commit 8513165

Browse files
authored
GHA: Refactor repetitive action inputs into in-repo composite actions (#6199)
2 parents 180deff + 735e926 commit 8513165

File tree

9 files changed

+131
-278
lines changed

9 files changed

+131
-278
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Cache and Install APT Dependencies
3+
description:
4+
Light wrapper around the actions/cache action and our script
5+
to maintain the input vars in only one place for all workflows.
6+
7+
runs:
8+
using: "composite"
9+
steps:
10+
- name: Cache APT Dependencies
11+
id: cache-apt-deps
12+
uses: actions/cache@v4
13+
with:
14+
path: |
15+
~/apt_cache
16+
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
17+
restore-keys: |
18+
${{ runner.os }}-v8-apt-
19+
20+
- name: Install APT Depedencies
21+
shell: bash
22+
env:
23+
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
24+
run: |
25+
# install dev dependencies for Python YAML and LDAP packages
26+
# https://github.com/StackStorm/st2-auth-ldap
27+
./scripts/github/install-apt-packages-use-cache.sh
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Initialize Pants and its GHA caches
3+
description:
4+
Light wrapper around the pantsbuild/actions/init-pants action
5+
to maintain the input vars in only one place for all workflows.
6+
7+
inputs:
8+
gha-cache-key:
9+
description: Qualify all cache keys with this string. Useful for invalidating everything.
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: Initialize Pants and its GHA caches
16+
uses: pantsbuild/actions/init-pants@v8
17+
# This action adds an env var to make pants use both pants.ci.toml & pants.toml.
18+
# This action also creates 3 GHA caches (1 is optional).
19+
# - `pants-setup` has the bootsrapped pants install
20+
# - `pants-named-caches` has pip/wheel and PEX caches
21+
# - `pants-lmdb-store` has the fine-grained process cache.
22+
# If we ever use a remote cache, then we can drop this.
23+
# Otherwise, we may need an additional workflow or job to delete old caches
24+
# if they are not expiring fast enough, and we hit the GHA 10GB per repo max.
25+
with:
26+
base-branch: master
27+
# To ignore a bad cache, bump the cache* integer.
28+
gha-cache-key: ${{ inputs.gha-cache-key }}
29+
# This hash should include all of our lockfiles so that the pip/pex caches
30+
# get invalidated on any transitive dependency update.
31+
named-caches-hash: ${{ hashFiles('lockfiles/*.lock') }}
32+
# enable the optional lmdb_store cache since we're not using remote caching.
33+
cache-lmdb-store: 'true'
34+
# install whatever version of python we need for our in-repo pants-plugins
35+
setup-python-for-plugins: 'true'
36+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
name: Install Python and Cache Deps
3+
description:
4+
Light wrapper around the actions/setup-python and actions/cache actions
5+
to maintain the input vars in only one place for all workflows.
6+
7+
input:
8+
python-version:
9+
description: Which version of python to install.
10+
required: true
11+
12+
runs:
13+
using: "composite"
14+
steps:
15+
- name: 'Set up Python (${{ inputs.python-version }})'
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '${{ inputs.python-version }}'
19+
20+
- name: Cache Python Dependencies
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
~/.cache/pip
25+
virtualenv
26+
~/virtualenv
27+
# TODO: maybe make the virtualenv a partial cache to exclude st2*?
28+
# !virtualenv/lib/python*/site-packages/st2*
29+
# !virtualenv/bin/st2*
30+
key: ${{ runner.os }}-v5-python-${{ inputs.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
31+
# Don't use alternative key as if requirements.txt has altered we
32+
# don't want to retrieve previous cache
33+
#restore-keys: |
34+
# ${{ runner.os }}-v5-python-${{ inputs.python }}-

.github/workflows/ci.yaml

Lines changed: 17 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -81,41 +81,12 @@ jobs:
8181
- name: Custom Environment Setup
8282
run: |
8383
./scripts/github/setup-environment.sh
84-
- name: 'Set up Python (${{ matrix.python-version }})'
85-
uses: actions/setup-python@v5
84+
- name: 'Set up Python (${{ matrix.python-version }}) and Cache Deps'
85+
uses: ./.github/actions/setup-python
8686
with:
8787
python-version: '${{ matrix.python-version }}'
88-
- name: Cache Python Dependencies
89-
uses: actions/cache@v4
90-
with:
91-
path: |
92-
~/.cache/pip
93-
virtualenv
94-
~/virtualenv
95-
# TODO: maybe make the virtualenv a partial cache to exclude st2*?
96-
# !virtualenv/lib/python*/site-packages/st2*
97-
# !virtualenv/bin/st2*
98-
key: ${{ runner.os }}-v5-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
99-
# Don't use alternative key as if requirements.txt has altered we
100-
# don't want to retrieve previous cache
101-
#restore-keys: |
102-
# ${{ runner.os }}-v5-python-${{ matrix.python }}-
103-
- name: Cache APT Dependencies
104-
id: cache-apt-deps
105-
uses: actions/cache@v4
106-
with:
107-
path: |
108-
~/apt_cache
109-
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
110-
restore-keys: |
111-
${{ runner.os }}-v8-apt-
112-
- name: Install APT Depedencies
113-
env:
114-
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
115-
run: |
116-
# install dev dependencies for Python YAML and LDAP packages
117-
# https://github.com/StackStorm/st2-auth-ldap
118-
./scripts/github/install-apt-packages-use-cache.sh
88+
- name: Cache and Install APT Dependencies
89+
uses: ./.github/actions/apt-packages
11990
- name: Install virtualenv
12091
run: |
12192
./scripts/github/install-virtualenv.sh
@@ -180,40 +151,12 @@ jobs:
180151
- name: Custom Environment Setup
181152
run: |
182153
./scripts/github/setup-environment.sh
183-
- name: 'Set up Python (${{ matrix.python-version }})'
184-
uses: actions/setup-python@v5
154+
- name: 'Set up Python (${{ matrix.python-version }}) and Cache Deps'
155+
uses: ./.github/actions/setup-python
185156
with:
186157
python-version: '${{ matrix.python-version }}'
187-
- name: Cache Python Dependencies
188-
uses: actions/cache@v4
189-
with:
190-
path: |
191-
~/.cache/pip
192-
virtualenv
193-
~/virtualenv
194-
# TODO: maybe make the virtualenv a partial cache to exclude st2*?
195-
# !virtualenv/lib/python*/site-packages/st2*
196-
# !virtualenv/bin/st2*
197-
key: ${{ runner.os }}-v5-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
198-
restore-keys: |
199-
${{ runner.os }}-python-${{ matrix.python }}-
200-
- name: Cache APT Dependencies
201-
id: cache-apt-deps
202-
uses: actions/cache@v4
203-
with:
204-
path: |
205-
~/apt_cache
206-
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
207-
restore-keys: |
208-
${{ runner.os }}-v8-apt-
209-
- name: Install APT Depedencies
210-
env:
211-
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
212-
run: |
213-
cat /etc/environment
214-
# install dev dependencies for Python YAML and LDAP packages
215-
# https://github.com/StackStorm/st2-auth-ldap
216-
./scripts/github/install-apt-packages-use-cache.sh
158+
- name: Cache and Install APT Dependencies
159+
uses: ./.github/actions/apt-packages
217160
- name: Install virtualenv
218161
run: |
219162
./scripts/github/install-virtualenv.sh
@@ -384,41 +327,12 @@ jobs:
384327
- name: Custom Environment Setup
385328
run: |
386329
./scripts/github/setup-environment.sh
387-
- name: 'Set up Python (${{ matrix.python-version }})'
388-
uses: actions/setup-python@v5
330+
- name: 'Set up Python (${{ matrix.python-version }}) and Cache Deps'
331+
uses: ./.github/actions/setup-python
389332
with:
390333
python-version: '${{ matrix.python-version }}'
391-
- name: Cache Python Dependencies
392-
uses: actions/cache@v4
393-
with:
394-
path: |
395-
~/.cache/pip
396-
virtualenv
397-
~/virtualenv
398-
# TODO: maybe make the virtualenv a partial cache to exclude st2*?
399-
# !virtualenv/lib/python*/site-packages/st2*
400-
# !virtualenv/bin/st2*
401-
key: ${{ runner.os }}-v5-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
402-
# Don't use alternative key as if requirements.txt has altered we
403-
# don't want to retrieve previous cache
404-
#restore-keys: |
405-
# ${{ runner.os }}-v5-python-${{ matrix.python }}-
406-
- name: Cache APT Dependencies
407-
id: cache-apt-deps
408-
uses: actions/cache@v4
409-
with:
410-
path: |
411-
~/apt_cache
412-
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
413-
restore-keys: |
414-
${{ runner.os }}-v8-apt-
415-
- name: Install APT Depedencies
416-
env:
417-
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
418-
run: |
419-
# install dev dependencies for Python YAML and LDAP packages
420-
# https://github.com/StackStorm/st2-auth-ldap
421-
./scripts/github/install-apt-packages-use-cache.sh
334+
- name: Cache and Install APT Dependencies
335+
uses: ./.github/actions/apt-packages
422336
- name: Install virtualenv
423337
run: |
424338
./scripts/github/install-virtualenv.sh
@@ -604,41 +518,12 @@ jobs:
604518
- name: Custom Environment Setup
605519
run: |
606520
./scripts/github/setup-environment.sh
607-
- name: 'Set up Python (${{ matrix.python-version }})'
608-
uses: actions/setup-python@v5
521+
- name: 'Set up Python (${{ matrix.python-version }}) and Cache Deps'
522+
uses: ./.github/actions/setup-python
609523
with:
610524
python-version: '${{ matrix.python-version }}'
611-
- name: Cache Python Dependencies
612-
uses: actions/cache@v4
613-
with:
614-
path: |
615-
~/.cache/pip
616-
virtualenv
617-
~/virtualenv
618-
# TODO: maybe make the virtualenv a partial cache to exclude st2*?
619-
# !virtualenv/lib/python*/site-packages/st2*
620-
# !virtualenv/bin/st2*
621-
key: ${{ runner.os }}-v5-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
622-
# Don't use alternative key as if requirements.txt has altered we
623-
# don't want to retrieve previous cache
624-
#restore-keys: |
625-
# ${{ runner.os }}-v5-python-${{ matrix.python }}-
626-
- name: Cache APT Dependencies
627-
id: cache-apt-deps
628-
uses: actions/cache@v4
629-
with:
630-
path: |
631-
~/apt_cache
632-
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
633-
restore-keys: |
634-
${{ runner.os }}-v8-apt-
635-
- name: Install APT Depedencies
636-
env:
637-
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
638-
run: |
639-
# install dev dependencies for Python YAML and LDAP packages
640-
# https://github.com/StackStorm/st2-auth-ldap
641-
./scripts/github/install-apt-packages-use-cache.sh
525+
- name: Cache and Install APT Dependencies
526+
uses: ./.github/actions/apt-packages
642527
- name: Install virtualenv
643528
run: |
644529
./scripts/github/install-virtualenv.sh
@@ -709,6 +594,7 @@ jobs:
709594
if: always()
710595
needs:
711596
- lint-checks
597+
- self-check
712598
- unit-tests
713599
- integration-tests
714600
runs-on: ubuntu-20.04

.github/workflows/lint.yaml

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,14 @@ jobs:
3838
# a test uses a submodule, and pants needs access to it to calculate deps.
3939
submodules: 'true'
4040

41-
#- name: Cache APT Dependencies
42-
# id: cache-apt-deps
43-
# uses: actions/cache@v4
44-
# with:
45-
# path: |
46-
# ~/apt_cache
47-
# key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
48-
# restore-keys: |
49-
# ${{ runner.os }}-v8-apt-
50-
- name: Install APT Depedencies
51-
env:
52-
CACHE_HIT: 'false' # cache doesn't work
53-
#CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
54-
run: |
55-
# install dev dependencies for Python YAML and LDAP packages
56-
# https://github.com/StackStorm/st2-auth-ldap
57-
./scripts/github/install-apt-packages-use-cache.sh
41+
- name: Cache and Install APT Dependencies
42+
uses: ./.github/actions/apt-packages
5843

5944
- name: Initialize Pants and its GHA caches
60-
uses: pantsbuild/actions/init-pants@v8
61-
# This action adds an env var to make pants use both pants.ci.toml & pants.toml.
62-
# This action also creates 3 GHA caches (1 is optional).
63-
# - `pants-setup` has the bootsrapped pants install
64-
# - `pants-named-caches` has pip/wheel and PEX caches
65-
# - `pants-lmdb-store` has the fine-grained process cache.
66-
# If we ever use a remote cache, then we can drop this.
67-
# Otherwise, we may need an additional workflow or job to delete old caches
68-
# if they are not expiring fast enough, and we hit the GHA 10GB per repo max.
45+
uses: ./.github/actions/init-pants
6946
with:
70-
base-branch: master
7147
# To ignore a bad cache, bump the cache* integer.
7248
gha-cache-key: cache0
73-
# This hash should include all of our lockfiles so that the pip/pex caches
74-
# get invalidated on any transitive dependency update.
75-
named-caches-hash: ${{ hashFiles('requirements.txt') }}
76-
# enable the optional lmdb_store cache since we're not using remote caching.
77-
cache-lmdb-store: 'true'
78-
# install whatever version of python we need for our in-repo pants-plugins
79-
setup-python-for-plugins: 'true'
8049

8150
- name: Lint
8251
run: |

.github/workflows/microbenchmarks.yaml

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,36 +75,12 @@ jobs:
7575
steps:
7676
- name: Checkout repository
7777
uses: actions/checkout@v4
78-
- name: 'Set up Python (${{ matrix.python-version }})'
79-
uses: actions/setup-python@v5
78+
- name: 'Set up Python (${{ matrix.python-version }}) and Cache Deps'
79+
uses: ./.github/actions/setup-python
8080
with:
8181
python-version: '${{ matrix.python-version }}'
82-
- name: Cache Python Dependencies
83-
uses: actions/cache@v4
84-
with:
85-
path: |
86-
~/.cache/pip
87-
virtualenv
88-
~/virtualenv
89-
key: ${{ runner.os }}-v5-python-${{ matrix.python-version }}-${{ hashFiles('requirements.txt', 'test-requirements.txt', 'lockfiles/*.lock') }}
90-
# Don't use alternative key as if requirements.txt has altered we
91-
# don't want to retrieve previous cache
92-
#restore-keys: |
93-
# ${{ runner.os }}-v5-python-${{ matrix.python }}-
94-
- name: Cache APT Dependencies
95-
id: cache-apt-deps
96-
uses: actions/cache@v4
97-
with:
98-
path: |
99-
~/apt_cache
100-
key: ${{ runner.os }}-v8-apt-${{ hashFiles('scripts/github/apt-packages.txt') }}
101-
restore-keys: |
102-
${{ runner.os }}-v8-apt-
103-
- name: Install APT Dependencies
104-
env:
105-
CACHE_HIT: ${{steps.cache-apt-deps.outputs.cache-hit}}
106-
run: |
107-
./scripts/github/install-apt-packages-use-cache.sh
82+
- name: Cache and Install APT Dependencies
83+
uses: ./.github/actions/apt-packages
10884
- name: Install virtualenv
10985
run: |
11086
./scripts/github/install-virtualenv.sh
@@ -122,7 +98,7 @@ jobs:
12298
- name: Upload Histograms
12399
uses: actions/upload-artifact@v4
124100
with:
125-
name: benchmark_histograms
101+
name: benchmark_histograms-py${{ matrix.python-version }}
126102
path: benchmark_histograms/
127103
retention-days: 30
128104

0 commit comments

Comments
 (0)