Skip to content

Commit

Permalink
Merge pull request #130 from github/jm_workflow_types
Browse files Browse the repository at this point in the history
chore: standardize github action types
  • Loading branch information
zkoppert authored Jun 7, 2024
2 parents 1f45c76 + 9db8e7f commit a30fc4e
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 39 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/auto-labeler.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
---
name: Auto Labeler
name: Auto Labeler

on:
# pull_request_target event is required for autolabeler to support all PRs including forks
pull_request_target:
types: [opened, reopened, synchronize]
on:
# pull_request_target event is required for autolabeler to support all PRs including forks
pull_request_target:
types: [ opened, reopened, edited, synchronize ]

permissions:
contents: read
permissions:
contents: read

jobs:
main:
permissions:
contents: write
pull-requests: write
name: Auto label pull requests
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config-name: release-drafter.yml
jobs:
main:
permissions:
contents: write
pull-requests: write
name: Auto label pull requests
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
config-name: release-drafter.yml
4 changes: 2 additions & 2 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Docker Image CI

on:
push:
branches: main
branches: [ main ]
pull_request:
branches: main
branches: [ main ]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/major-version-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Major Version Updater
# Whenever a new release is made, push a major version tag
on:
release:
types: published
types: [ published ]

permissions:
contents: read
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ name: "Lint PR Title"

on:
pull_request_target:
types:
- opened
- edited
- synchronize
types: [ opened, reopened, edited, synchronize ]

permissions:
contents: read
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Python package

on:
push:
branches: main
branches: [ main ]
pull_request:
branches: main
branches: [ main ]

permissions:
contents: read
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
on:
workflow_dispatch:
pull_request_target:
types:
- closed
branches:
- main
types: [ closed ]
branches: [ main ]

permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
schedule:
- cron: '29 11 * * 6'
push:
branches: ["main"]
branches: [ main ]

permissions: read-all

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Lint Code Base

on:
pull_request:
branches: main
branches: [ main ]

permissions:
contents: read
Expand Down
12 changes: 8 additions & 4 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
from dotenv import load_dotenv


def get_bool_env_var(env_var_name: str) -> bool:
def get_bool_env_var(env_var_name: str, default: bool = False) -> bool:
"""Get a boolean environment variable.
Args:
env_var_name: The name of the environment variable to retrieve.
default: The default value to return if the environment variable is not set.
Returns:
The value of the environment variable as a boolean.
"""
return os.environ.get(env_var_name, "").strip().lower() == "true"
ev = os.environ.get(env_var_name, "")
if ev == "" and default:
return default
return ev.strip().lower() == "true"


def get_int_env_var(env_var_name: str) -> int | None:
Expand Down Expand Up @@ -121,8 +125,8 @@ def get_env_vars(
start_date = validate_date_format("START_DATE")
end_date = validate_date_format("END_DATE")

sponsor_info = get_bool_env_var("SPONSOR_INFO")
link_to_profile = get_bool_env_var("LINK_TO_PROFILE")
sponsor_info = get_bool_env_var("SPONSOR_INFO", False)
link_to_profile = get_bool_env_var("LINK_TO_PROFILE", False)

# Separate repositories_str into a list based on the comma separator
repositories_list = []
Expand Down
81 changes: 81 additions & 0 deletions test_env_get_bool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Test the get_bool_env_var function"""

import os
import unittest
from unittest.mock import patch

from env import get_bool_env_var


class TestEnv(unittest.TestCase):
"""Test the get_bool_env_var function"""

@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_true(self):
"""Test that gets a boolean environment variable that exists and is true"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)

@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false(self):
"""Test that gets a boolean environment variable that exists and is false"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)

@patch.dict(
os.environ,
{
"TEST_BOOL": "nope",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false_due_to_invalid_value(self):
"""Test that gets a boolean environment variable that exists and is false
due to an invalid value
"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)

@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_true(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: true
"""
result = get_bool_env_var("DOES_NOT_EXIST", True)
self.assertTrue(result)

@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_false(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: false
"""
result = get_bool_env_var("DOES_NOT_EXIST", False)
self.assertFalse(result)


if __name__ == "__main__":
unittest.main()

0 comments on commit a30fc4e

Please sign in to comment.