Skip to content

Commit b49419d

Browse files
authored
Merge pull request #26 from saadmk11/release-type
Add Option to use Release Types (major, minor, patch) for Updates
2 parents 815d943 + f586819 commit b49419d

6 files changed

Lines changed: 195 additions & 90 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ jobs:
8585
# [Optional] Use The Latest Release Tag/Commit SHA or Default Branch Commit SHA to update the actions
8686
# options: "release-tag" (default), "release-commit-sha", "default-branch-sha"'
8787
update_version_with: 'release-tag'
88+
# [Optional] A comma separated string of release types (major, minor, patch) to use when updating the actions
89+
# If not specified, all releases will be used
90+
# By default, all (major, minor, patch) release types are used to update the actions
91+
# Only applicable for `release-tag` and `release-commit-sha` update_version_with options
92+
# options: "all" (default), "major", "minor", "patch"
93+
release_types: 'all'
8894
# [Optional] A comma separated string (usernames) which denotes the users
8995
# that should be added as reviewers to the pull request
9096
pull_request_user_reviewers: "octocat, hubot, other_user"

action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ inputs:
3636
description: 'Use Latest Release Tag/Commit SHA or Default Branch Commit SHA to update. options: "release-tag" (default), "release-commit-sha", "default-branch-sha"'
3737
required: false
3838
default: 'release-tag'
39+
release_types:
40+
description: 'A comma separated string of release types (major, minor, patch) to use when updating the actions. If not specified, all releases will be used. options: "all" (default), "major", "minor", "patch"'
41+
required: false
42+
default: 'all'
3943
pull_request_user_reviewers:
4044
description: 'A comma separated string (usernames) which denotes the users that should be added as reviewers to the pull request'
4145
required: false

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PyYAML~=6.0.0
2+
packaging~=21.3
23
requests~=2.28.1
34
github-action-utils~=1.0.2

src/config.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
DEFAULT_BRANCH_COMMIT_SHA,
1515
]
1616

17+
MAJOR_RELEASE = "major"
18+
MINOR_RELEASE = "minor"
19+
PATCH_RELEASE = "patch"
20+
21+
ALL_RELEASE_TYPES = [MAJOR_RELEASE, MINOR_RELEASE, PATCH_RELEASE]
22+
1723

1824
class ActionEnvironment(NamedTuple):
1925
repository: str
@@ -42,6 +48,7 @@ class Configuration(NamedTuple):
4248
update_version_with: str = LATEST_RELEASE_TAG
4349
pull_request_user_reviewers: set[str] = set()
4450
pull_request_team_reviewers: set[str] = set()
51+
release_types: list[str] = ALL_RELEASE_TYPES
4552

4653
@property
4754
def git_commit_author(self) -> str:
@@ -72,6 +79,7 @@ def get_user_config(cls, env: Mapping[str, str | None]) -> dict[str, str | None]
7279
"commit_message": env.get("INPUT_COMMIT_MESSAGE"),
7380
"ignore_actions": env.get("INPUT_IGNORE"),
7481
"update_version_with": env.get("INPUT_UPDATE_VERSION_WITH"),
82+
"release_types": env.get("INPUT_RELEASE_TYPES"),
7583
"pull_request_user_reviewers": env.get("INPUT_PULL_REQUEST_USER_REVIEWERS"),
7684
"pull_request_team_reviewers": env.get("INPUT_PULL_REQUEST_TEAM_REVIEWERS"),
7785
}
@@ -122,6 +130,22 @@ def clean_pull_request_team_reviewers(value: Any) -> set[str] | None:
122130
return {s.strip() for s in value.strip().split(",") if s}
123131
return None
124132

133+
@staticmethod
134+
def clean_release_types(value: Any) -> list[str] | None:
135+
if value and isinstance(value, str):
136+
values = [s.strip() for s in value.lower().strip().split(",") if s]
137+
if values == ["all"]:
138+
return ALL_RELEASE_TYPES
139+
elif all(i in ALL_RELEASE_TYPES for i in values):
140+
return values
141+
else:
142+
gha_utils.error(
143+
"Invalid input for `release_types` field, "
144+
f"expected one/all of {ALL_RELEASE_TYPES} but got `{value}`"
145+
)
146+
raise SystemExit(1)
147+
return None
148+
125149
@staticmethod
126150
def clean_skip_pull_request(value: Any) -> bool | None:
127151
if value in [1, "1", True, "true", "True"]:

0 commit comments

Comments
 (0)