Skip to content

Commit

Permalink
Merge pull request #26 from saadmk11/release-type
Browse files Browse the repository at this point in the history
Add Option to use Release Types (major, minor, patch) for Updates
  • Loading branch information
saadmk11 authored Oct 22, 2022
2 parents 815d943 + f586819 commit b49419d
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 90 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ jobs:
# [Optional] Use The Latest Release Tag/Commit SHA or Default Branch Commit SHA to update the actions
# options: "release-tag" (default), "release-commit-sha", "default-branch-sha"'
update_version_with: 'release-tag'
# [Optional] A comma separated string of release types (major, minor, patch) to use when updating the actions
# If not specified, all releases will be used
# By default, all (major, minor, patch) release types are used to update the actions
# Only applicable for `release-tag` and `release-commit-sha` update_version_with options
# options: "all" (default), "major", "minor", "patch"
release_types: 'all'
# [Optional] A comma separated string (usernames) which denotes the users
# that should be added as reviewers to the pull request
pull_request_user_reviewers: "octocat, hubot, other_user"
Expand Down
4 changes: 4 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ inputs:
description: 'Use Latest Release Tag/Commit SHA or Default Branch Commit SHA to update. options: "release-tag" (default), "release-commit-sha", "default-branch-sha"'
required: false
default: 'release-tag'
release_types:
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"'
required: false
default: 'all'
pull_request_user_reviewers:
description: 'A comma separated string (usernames) which denotes the users that should be added as reviewers to the pull request'
required: false
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PyYAML~=6.0.0
packaging~=21.3
requests~=2.28.1
github-action-utils~=1.0.2
24 changes: 24 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
DEFAULT_BRANCH_COMMIT_SHA,
]

MAJOR_RELEASE = "major"
MINOR_RELEASE = "minor"
PATCH_RELEASE = "patch"

ALL_RELEASE_TYPES = [MAJOR_RELEASE, MINOR_RELEASE, PATCH_RELEASE]


class ActionEnvironment(NamedTuple):
repository: str
Expand Down Expand Up @@ -42,6 +48,7 @@ class Configuration(NamedTuple):
update_version_with: str = LATEST_RELEASE_TAG
pull_request_user_reviewers: set[str] = set()
pull_request_team_reviewers: set[str] = set()
release_types: list[str] = ALL_RELEASE_TYPES

@property
def git_commit_author(self) -> str:
Expand Down Expand Up @@ -72,6 +79,7 @@ def get_user_config(cls, env: Mapping[str, str | None]) -> dict[str, str | None]
"commit_message": env.get("INPUT_COMMIT_MESSAGE"),
"ignore_actions": env.get("INPUT_IGNORE"),
"update_version_with": env.get("INPUT_UPDATE_VERSION_WITH"),
"release_types": env.get("INPUT_RELEASE_TYPES"),
"pull_request_user_reviewers": env.get("INPUT_PULL_REQUEST_USER_REVIEWERS"),
"pull_request_team_reviewers": env.get("INPUT_PULL_REQUEST_TEAM_REVIEWERS"),
}
Expand Down Expand Up @@ -122,6 +130,22 @@ def clean_pull_request_team_reviewers(value: Any) -> set[str] | None:
return {s.strip() for s in value.strip().split(",") if s}
return None

@staticmethod
def clean_release_types(value: Any) -> list[str] | None:
if value and isinstance(value, str):
values = [s.strip() for s in value.lower().strip().split(",") if s]
if values == ["all"]:
return ALL_RELEASE_TYPES
elif all(i in ALL_RELEASE_TYPES for i in values):
return values
else:
gha_utils.error(
"Invalid input for `release_types` field, "
f"expected one/all of {ALL_RELEASE_TYPES} but got `{value}`"
)
raise SystemExit(1)
return None

@staticmethod
def clean_skip_pull_request(value: Any) -> bool | None:
if value in [1, "1", True, "true", "True"]:
Expand Down
Loading

0 comments on commit b49419d

Please sign in to comment.