Skip to content

Commit a30fc4e

Browse files
authored
Merge pull request #130 from github/jm_workflow_types
chore: standardize github action types
2 parents 1f45c76 + 9db8e7f commit a30fc4e

File tree

10 files changed

+119
-39
lines changed

10 files changed

+119
-39
lines changed

.github/workflows/auto-labeler.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
2-
name: Auto Labeler
2+
name: Auto Labeler
33

4-
on:
5-
# pull_request_target event is required for autolabeler to support all PRs including forks
6-
pull_request_target:
7-
types: [opened, reopened, synchronize]
4+
on:
5+
# pull_request_target event is required for autolabeler to support all PRs including forks
6+
pull_request_target:
7+
types: [ opened, reopened, edited, synchronize ]
88

9-
permissions:
10-
contents: read
9+
permissions:
10+
contents: read
1111

12-
jobs:
13-
main:
14-
permissions:
15-
contents: write
16-
pull-requests: write
17-
name: Auto label pull requests
18-
runs-on: ubuntu-latest
19-
steps:
20-
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
21-
env:
22-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
with:
24-
config-name: release-drafter.yml
12+
jobs:
13+
main:
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
name: Auto label pull requests
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
21+
env:
22+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
with:
24+
config-name: release-drafter.yml

.github/workflows/docker-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Docker Image CI
33

44
on:
55
push:
6-
branches: main
6+
branches: [ main ]
77
pull_request:
8-
branches: main
8+
branches: [ main ]
99

1010
permissions:
1111
contents: read

.github/workflows/major-version-updater.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Major Version Updater
33
# Whenever a new release is made, push a major version tag
44
on:
55
release:
6-
types: published
6+
types: [ published ]
77

88
permissions:
99
contents: read

.github/workflows/pr-title.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ name: "Lint PR Title"
44

55
on:
66
pull_request_target:
7-
types:
8-
- opened
9-
- edited
10-
- synchronize
7+
types: [ opened, reopened, edited, synchronize ]
118

129
permissions:
1310
contents: read

.github/workflows/python-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ name: Python package
66

77
on:
88
push:
9-
branches: main
9+
branches: [ main ]
1010
pull_request:
11-
branches: main
11+
branches: [ main ]
1212

1313
permissions:
1414
contents: read

.github/workflows/release.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
on:
55
workflow_dispatch:
66
pull_request_target:
7-
types:
8-
- closed
9-
branches:
10-
- main
7+
types: [ closed ]
8+
branches: [ main ]
119

1210
permissions:
1311
contents: read

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
schedule:
1212
- cron: '29 11 * * 6'
1313
push:
14-
branches: ["main"]
14+
branches: [ main ]
1515

1616
permissions: read-all
1717

.github/workflows/super-linter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Lint Code Base
33

44
on:
55
pull_request:
6-
branches: main
6+
branches: [ main ]
77

88
permissions:
99
contents: read

env.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
from dotenv import load_dotenv
1111

1212

13-
def get_bool_env_var(env_var_name: str) -> bool:
13+
def get_bool_env_var(env_var_name: str, default: bool = False) -> bool:
1414
"""Get a boolean environment variable.
1515
1616
Args:
1717
env_var_name: The name of the environment variable to retrieve.
18+
default: The default value to return if the environment variable is not set.
1819
1920
Returns:
2021
The value of the environment variable as a boolean.
2122
"""
22-
return os.environ.get(env_var_name, "").strip().lower() == "true"
23+
ev = os.environ.get(env_var_name, "")
24+
if ev == "" and default:
25+
return default
26+
return ev.strip().lower() == "true"
2327

2428

2529
def get_int_env_var(env_var_name: str) -> int | None:
@@ -121,8 +125,8 @@ def get_env_vars(
121125
start_date = validate_date_format("START_DATE")
122126
end_date = validate_date_format("END_DATE")
123127

124-
sponsor_info = get_bool_env_var("SPONSOR_INFO")
125-
link_to_profile = get_bool_env_var("LINK_TO_PROFILE")
128+
sponsor_info = get_bool_env_var("SPONSOR_INFO", False)
129+
link_to_profile = get_bool_env_var("LINK_TO_PROFILE", False)
126130

127131
# Separate repositories_str into a list based on the comma separator
128132
repositories_list = []

test_env_get_bool.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
"""Test the get_bool_env_var function"""
2+
3+
import os
4+
import unittest
5+
from unittest.mock import patch
6+
7+
from env import get_bool_env_var
8+
9+
10+
class TestEnv(unittest.TestCase):
11+
"""Test the get_bool_env_var function"""
12+
13+
@patch.dict(
14+
os.environ,
15+
{
16+
"TEST_BOOL": "true",
17+
},
18+
clear=True,
19+
)
20+
def test_get_bool_env_var_that_exists_and_is_true(self):
21+
"""Test that gets a boolean environment variable that exists and is true"""
22+
result = get_bool_env_var("TEST_BOOL", False)
23+
self.assertTrue(result)
24+
25+
@patch.dict(
26+
os.environ,
27+
{
28+
"TEST_BOOL": "false",
29+
},
30+
clear=True,
31+
)
32+
def test_get_bool_env_var_that_exists_and_is_false(self):
33+
"""Test that gets a boolean environment variable that exists and is false"""
34+
result = get_bool_env_var("TEST_BOOL", False)
35+
self.assertFalse(result)
36+
37+
@patch.dict(
38+
os.environ,
39+
{
40+
"TEST_BOOL": "nope",
41+
},
42+
clear=True,
43+
)
44+
def test_get_bool_env_var_that_exists_and_is_false_due_to_invalid_value(self):
45+
"""Test that gets a boolean environment variable that exists and is false
46+
due to an invalid value
47+
"""
48+
result = get_bool_env_var("TEST_BOOL", False)
49+
self.assertFalse(result)
50+
51+
@patch.dict(
52+
os.environ,
53+
{
54+
"TEST_BOOL": "false",
55+
},
56+
clear=True,
57+
)
58+
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_true(self):
59+
"""Test that gets a boolean environment variable that does not exist
60+
and default value returns: true
61+
"""
62+
result = get_bool_env_var("DOES_NOT_EXIST", True)
63+
self.assertTrue(result)
64+
65+
@patch.dict(
66+
os.environ,
67+
{
68+
"TEST_BOOL": "true",
69+
},
70+
clear=True,
71+
)
72+
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_false(self):
73+
"""Test that gets a boolean environment variable that does not exist
74+
and default value returns: false
75+
"""
76+
result = get_bool_env_var("DOES_NOT_EXIST", False)
77+
self.assertFalse(result)
78+
79+
80+
if __name__ == "__main__":
81+
unittest.main()

0 commit comments

Comments
 (0)