Skip to content

Commit 223b229

Browse files
committed
Update get-envs script to replace grep
1 parent 32eb0f7 commit 223b229

File tree

3 files changed

+73
-58
lines changed

3 files changed

+73
-58
lines changed

.github/scripts/get-envs.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python
2+
# Copyright 2010 New Relic, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import fileinput
17+
import os
18+
from textwrap import dedent
19+
20+
GROUP_NUMBER = int(os.environ["GROUP_NUMBER"]) - 1
21+
TOTAL_GROUPS = int(os.environ["TOTAL_GROUPS"])
22+
GITHUB_JOB = os.environ["GITHUB_JOB"]
23+
24+
25+
def main(stdin):
26+
environments = [env.rstrip() for env in stdin]
27+
filtered_envs = [env for env in environments if env.startswith(GITHUB_JOB + "-")]
28+
grouped_envs = environments[GROUP_NUMBER::TOTAL_GROUPS]
29+
joined_envs = ",".join(grouped_envs)
30+
31+
# If not environments are found, raise an error with helpful information.
32+
if joined_envs:
33+
print(joined_envs)
34+
else:
35+
error_msg = dedent(f"""
36+
No matching environments found.
37+
GITHUB_JOB = {GITHUB_JOB}
38+
GROUP_NUMBER = {GROUP_NUMBER + 1}
39+
TOTAL_GROUPS = {TOTAL_GROUPS}
40+
41+
environments = {environments}
42+
filtered_envs = {filtered_envs}
43+
grouped_envs = {grouped_envs}
44+
joined_envs = {joined_envs}
45+
""")
46+
raise RuntimeError(error_msg(environments))
47+
48+
49+
if __name__ == "__main__":
50+
with fileinput.input() as stdin:
51+
main(stdin)

.github/workflows/get-envs.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ jobs:
166166
- name: Get Environments
167167
id: get-envs
168168
run: |
169-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
169+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
170170
env:
171171
GROUP_NUMBER: ${{ matrix.group-number }}
172172

@@ -217,7 +217,7 @@ jobs:
217217
- name: Get Environments
218218
id: get-envs
219219
run: |
220-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
220+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
221221
env:
222222
GROUP_NUMBER: ${{ matrix.group-number }}
223223

@@ -282,7 +282,7 @@ jobs:
282282
- name: Get Environments
283283
id: get-envs
284284
run: |
285-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
285+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
286286
env:
287287
GROUP_NUMBER: ${{ matrix.group-number }}
288288

@@ -348,7 +348,7 @@ jobs:
348348
- name: Get Environments
349349
id: get-envs
350350
run: |
351-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
351+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
352352
env:
353353
GROUP_NUMBER: ${{ matrix.group-number }}
354354

@@ -414,7 +414,7 @@ jobs:
414414
- name: Get Environments
415415
id: get-envs
416416
run: |
417-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
417+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
418418
env:
419419
GROUP_NUMBER: ${{ matrix.group-number }}
420420

@@ -483,7 +483,7 @@ jobs:
483483
- name: Get Environments
484484
id: get-envs
485485
run: |
486-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
486+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
487487
env:
488488
GROUP_NUMBER: ${{ matrix.group-number }}
489489

@@ -552,7 +552,7 @@ jobs:
552552
- name: Get Environments
553553
id: get-envs
554554
run: |
555-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
555+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
556556
env:
557557
GROUP_NUMBER: ${{ matrix.group-number }}
558558

@@ -657,7 +657,7 @@ jobs:
657657
- name: Get Environments
658658
id: get-envs
659659
run: |
660-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
660+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
661661
env:
662662
GROUP_NUMBER: ${{ matrix.group-number }}
663663

@@ -721,7 +721,7 @@ jobs:
721721
- name: Get Environments
722722
id: get-envs
723723
run: |
724-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
724+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
725725
env:
726726
GROUP_NUMBER: ${{ matrix.group-number }}
727727

@@ -787,7 +787,7 @@ jobs:
787787
- name: Get Environments
788788
id: get-envs
789789
run: |
790-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
790+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
791791
env:
792792
GROUP_NUMBER: ${{ matrix.group-number }}
793793

@@ -854,7 +854,7 @@ jobs:
854854
- name: Get Environments
855855
id: get-envs
856856
run: |
857-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
857+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
858858
env:
859859
GROUP_NUMBER: ${{ matrix.group-number }}
860860

@@ -918,7 +918,7 @@ jobs:
918918
- name: Get Environments
919919
id: get-envs
920920
run: |
921-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
921+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
922922
env:
923923
GROUP_NUMBER: ${{ matrix.group-number }}
924924

@@ -983,7 +983,7 @@ jobs:
983983
- name: Get Environments
984984
id: get-envs
985985
run: |
986-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
986+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
987987
env:
988988
GROUP_NUMBER: ${{ matrix.group-number }}
989989

@@ -1059,7 +1059,7 @@ jobs:
10591059
- name: Get Environments
10601060
id: get-envs
10611061
run: |
1062-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1062+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
10631063
env:
10641064
GROUP_NUMBER: ${{ matrix.group-number }}
10651065

@@ -1123,7 +1123,7 @@ jobs:
11231123
- name: Get Environments
11241124
id: get-envs
11251125
run: |
1126-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1126+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
11271127
env:
11281128
GROUP_NUMBER: ${{ matrix.group-number }}
11291129

@@ -1187,7 +1187,7 @@ jobs:
11871187
- name: Get Environments
11881188
id: get-envs
11891189
run: |
1190-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1190+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
11911191
env:
11921192
GROUP_NUMBER: ${{ matrix.group-number }}
11931193

@@ -1256,7 +1256,7 @@ jobs:
12561256
- name: Get Environments
12571257
id: get-envs
12581258
run: |
1259-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1259+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
12601260
env:
12611261
GROUP_NUMBER: ${{ matrix.group-number }}
12621262

@@ -1322,7 +1322,7 @@ jobs:
13221322
- name: Get Environments
13231323
id: get-envs
13241324
run: |
1325-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1325+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
13261326
env:
13271327
GROUP_NUMBER: ${{ matrix.group-number }}
13281328

@@ -1389,7 +1389,7 @@ jobs:
13891389
- name: Get Environments
13901390
id: get-envs
13911391
run: |
1392-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1392+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
13931393
env:
13941394
GROUP_NUMBER: ${{ matrix.group-number }}
13951395

@@ -1460,7 +1460,7 @@ jobs:
14601460
- name: Get Environments
14611461
id: get-envs
14621462
run: |
1463-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1463+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
14641464
env:
14651465
GROUP_NUMBER: ${{ matrix.group-number }}
14661466

@@ -1524,7 +1524,7 @@ jobs:
15241524
- name: Get Environments
15251525
id: get-envs
15261526
run: |
1527-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1527+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
15281528
env:
15291529
GROUP_NUMBER: ${{ matrix.group-number }}
15301530

@@ -1590,7 +1590,7 @@ jobs:
15901590
- name: Get Environments
15911591
id: get-envs
15921592
run: |
1593-
echo "envs=$(tox -l | grep '^${{ github.job }}\-' | ./.github/workflows/get-envs.py)" >> "$GITHUB_OUTPUT"
1593+
echo "envs=$(tox -l | python ./.github/scripts/get-envs.py)" >> "$GITHUB_OUTPUT"
15941594
env:
15951595
GROUP_NUMBER: ${{ matrix.group-number }}
15961596

0 commit comments

Comments
 (0)