Skip to content

Commit 49b003c

Browse files
authored
Merge pull request #305 from github/jm_workflow_types
chore: standardize github action types
2 parents c5ebce3 + a87cac5 commit 49b003c

File tree

7 files changed

+204
-124
lines changed

7 files changed

+204
-124
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/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

.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/release.yml

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,92 @@
11
---
2-
name: Release
2+
name: Release
33

4-
on:
5-
workflow_dispatch:
6-
pull_request_target:
7-
types:
8-
- closed
9-
branches:
10-
- main
4+
on:
5+
workflow_dispatch:
6+
pull_request_target:
7+
types: [ closed ]
8+
branches: [ main ]
119

12-
permissions:
13-
contents: read
10+
permissions:
11+
contents: read
1412

15-
jobs:
16-
create_release:
17-
# release if
18-
# manual deployment OR
19-
# merged to main and labelled with release labels
20-
if: |
21-
(github.event_name == 'workflow_dispatch') ||
22-
(github.event.pull_request.merged == true &&
23-
(contains(github.event.pull_request.labels.*.name, 'breaking') ||
24-
contains(github.event.pull_request.labels.*.name, 'feature') ||
25-
contains(github.event.pull_request.labels.*.name, 'vuln') ||
26-
contains(github.event.pull_request.labels.*.name, 'release')))
27-
outputs:
28-
full-tag: ${{ steps.release-drafter.outputs.tag_name }}
29-
short-tag: ${{ steps.get_tag_name.outputs.SHORT_TAG }}
30-
body: ${{ steps.release-drafter.outputs.body }}
31-
runs-on: ubuntu-latest
32-
permissions:
33-
contents: write
34-
pull-requests: read
35-
steps:
36-
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
37-
id: release-drafter
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
with:
41-
config-name: release-drafter.yml
42-
publish: true
43-
- name: Get the short tag
44-
id: get_tag_name
45-
run: |
46-
short_tag=$(echo ${{ steps.release-drafter.outputs.tag_name }} | cut -d. -f1)
47-
echo "SHORT_TAG=$short_tag" >> $GITHUB_OUTPUT
48-
create_action_images:
49-
needs: create_release
50-
runs-on: ubuntu-latest
51-
permissions:
52-
packages: write
53-
env:
54-
REGISTRY: ghcr.io
55-
IMAGE_NAME: github/issue_metrics # different than repo name (underscore instead of dash)
56-
steps:
57-
- name: Set up Docker Buildx
58-
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb
59-
- name: Log in to the Container registry
60-
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
61-
with:
62-
registry: ${{ env.REGISTRY }}
63-
username: ${{ github.actor }}
64-
password: ${{ secrets.GITHUB_TOKEN }}
65-
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
66-
- name: Push Docker Image
67-
if: ${{ success() }}
68-
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
69-
with:
70-
context: .
71-
file: ./Dockerfile
72-
push: true
73-
tags: |
74-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
75-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.create_release.outputs.full-tag }}
76-
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.create_release.outputs.short-tag }}
77-
platforms: linux/amd64
78-
provenance: false
79-
sbom: false
80-
create_discussion:
81-
needs: create_release
82-
runs-on: ubuntu-latest
83-
permissions:
84-
discussions: write
85-
steps:
86-
- name: Create an announcement discussion for release
87-
uses: abirismyname/create-discussion@6e6ef67e5eeb042343ef8b3d8d0f5d545cbdf024
88-
env:
89-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90-
with:
91-
title: ${{ needs.create_release.outputs.full-tag }}
92-
body: ${{ needs.create_release.outputs.body }}
93-
repository-id: ${{ secrets.RELEASE_DISCUSSION_REPOSITORY_ID }}
94-
category-id: ${{ secrets.RELEASE_DISCUSSION_CATEGORY_ID }}
13+
jobs:
14+
create_release:
15+
# release if
16+
# manual deployment OR
17+
# merged to main and labelled with release labels
18+
if: |
19+
(github.event_name == 'workflow_dispatch') ||
20+
(github.event.pull_request.merged == true &&
21+
(contains(github.event.pull_request.labels.*.name, 'breaking') ||
22+
contains(github.event.pull_request.labels.*.name, 'feature') ||
23+
contains(github.event.pull_request.labels.*.name, 'vuln') ||
24+
contains(github.event.pull_request.labels.*.name, 'release')))
25+
outputs:
26+
full-tag: ${{ steps.release-drafter.outputs.tag_name }}
27+
short-tag: ${{ steps.get_tag_name.outputs.SHORT_TAG }}
28+
body: ${{ steps.release-drafter.outputs.body }}
29+
runs-on: ubuntu-latest
30+
permissions:
31+
contents: write
32+
pull-requests: read
33+
steps:
34+
- uses: release-drafter/release-drafter@3f0f87098bd6b5c5b9a36d49c41d998ea58f9348
35+
id: release-drafter
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
with:
39+
config-name: release-drafter.yml
40+
publish: true
41+
- name: Get the short tag
42+
id: get_tag_name
43+
run: |
44+
short_tag=$(echo ${{ steps.release-drafter.outputs.tag_name }} | cut -d. -f1)
45+
echo "SHORT_TAG=$short_tag" >> $GITHUB_OUTPUT
46+
create_action_images:
47+
needs: create_release
48+
runs-on: ubuntu-latest
49+
permissions:
50+
packages: write
51+
env:
52+
REGISTRY: ghcr.io
53+
IMAGE_NAME: github/issue_metrics # different than repo name (underscore instead of dash)
54+
steps:
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb
57+
- name: Log in to the Container registry
58+
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
59+
with:
60+
registry: ${{ env.REGISTRY }}
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
64+
- name: Push Docker Image
65+
if: ${{ success() }}
66+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
67+
with:
68+
context: .
69+
file: ./Dockerfile
70+
push: true
71+
tags: |
72+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
73+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.create_release.outputs.full-tag }}
74+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.create_release.outputs.short-tag }}
75+
platforms: linux/amd64
76+
provenance: false
77+
sbom: false
78+
create_discussion:
79+
needs: create_release
80+
runs-on: ubuntu-latest
81+
permissions:
82+
discussions: write
83+
steps:
84+
- name: Create an announcement discussion for release
85+
uses: abirismyname/create-discussion@6e6ef67e5eeb042343ef8b3d8d0f5d545cbdf024
86+
env:
87+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88+
with:
89+
title: ${{ needs.create_release.outputs.full-tag }}
90+
body: ${{ needs.create_release.outputs.body }}
91+
repository-id: ${{ secrets.RELEASE_DISCUSSION_REPOSITORY_ID }}
92+
category-id: ${{ secrets.RELEASE_DISCUSSION_CATEGORY_ID }}

.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

config.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,20 @@ def __repr__(self):
102102
)
103103

104104

105-
def get_bool_env_var(env_var_name: str) -> bool:
105+
def get_bool_env_var(env_var_name: str, default: bool = False) -> bool:
106106
"""Get a boolean environment variable.
107107
108108
Args:
109109
env_var_name: The name of the environment variable to retrieve.
110+
default: The default value to return if the environment variable is not set.
110111
111112
Returns:
112113
The value of the environment variable as a boolean.
113114
"""
114-
return os.environ.get(env_var_name, "").strip().lower() == "true"
115+
ev = os.environ.get(env_var_name, "")
116+
if ev == "" and default:
117+
return default
118+
return ev.strip().lower() == "true"
115119

116120

117121
def get_int_env_var(env_var_name: str) -> int | None:
@@ -177,12 +181,12 @@ def get_env_vars(test: bool = False) -> EnvVars:
177181
ignore_users_list = ignore_users.split(",")
178182

179183
# Hidden columns
180-
hide_author = get_bool_env_var("HIDE_AUTHOR")
181-
hide_label_metrics = get_bool_env_var("HIDE_LABEL_METRICS")
182-
hide_time_to_answer = get_bool_env_var("HIDE_TIME_TO_ANSWER")
183-
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE")
184-
hide_time_to_first_response = get_bool_env_var("HIDE_TIME_TO_FIRST_RESPONSE")
185-
enable_mentor_count = get_bool_env_var("ENABLE_MENTOR_COUNT")
184+
hide_author = get_bool_env_var("HIDE_AUTHOR", False)
185+
hide_label_metrics = get_bool_env_var("HIDE_LABEL_METRICS", False)
186+
hide_time_to_answer = get_bool_env_var("HIDE_TIME_TO_ANSWER", False)
187+
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
188+
hide_time_to_first_response = get_bool_env_var("HIDE_TIME_TO_FIRST_RESPONSE", False)
189+
enable_mentor_count = get_bool_env_var("ENABLE_MENTOR_COUNT", False)
186190
min_mentor_comments = os.getenv("MIN_MENTOR_COMMENTS", "10")
187191
max_comments_eval = os.getenv("MAX_COMMENTS_EVAL", "20")
188192
heavily_involved_cutoff = os.getenv("HEAVILY_INVOLVED_CUTOFF", "3")

test_config_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_get_bool_env_var function"""
2+
3+
import os
4+
import unittest
5+
from unittest.mock import patch
6+
7+
from config 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)