Skip to content

Commit 4679b89

Browse files
goruhaRoseSecurity
andauthored
Add GPG Key ID (#39) (#40)
* Add GPG Key ID (#39) * Update action.yml --------- Co-authored-by: RoseSecurity <[email protected]>
1 parent 47f09ab commit 4679b89

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ inputs:
4141
description: "Skip creation of remote branches and pull requests. Only print list of affected componented into file that is defined in 'outputs.affected-components-file'"
4242
required: false
4343
default: 'false'
44+
gpg-key-id:
45+
description: "GPG key ID to sign commits. Default ''"
46+
required: false
47+
default: ''
4448
pr-labels:
4549
description: "Comma or new line separated list of labels that will added on PR creation. Default: `component-update`"
4650
required: false
@@ -70,6 +74,7 @@ runs:
7074
EXCLUDE: ${{ inputs.exclude }}
7175
LOG_LEVEL: ${{ inputs.log-level }}
7276
DRY_RUN: ${{ inputs.dry-run }}
77+
GPG_KEY_ID: ${{ inputs.gpg-key-id }}
7378
PR_LABELS: ${{ inputs.pr-labels }}
7479
PR_TITLE_TEMPLATE: ${{ inputs.pr-title-template }}
7580
PR_BODY_TEMPLATE: ${{ inputs.pr-body-template }}

entrypoint.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ python3 src/main.py \
1818
--exclude "${EXCLUDE}" \
1919
--log-level ${LOG_LEVEL} \
2020
--dry-run ${DRY_RUN} \
21+
--gpg-key-id "${GPG_KEY_ID}" \
2122
--pr-labels "${PR_LABELS}" \
2223
--pr-title-template "${PR_TITLE_TEMPLATE}" \
2324
--pr-body-template "${PR_BODY_TEMPLATE}" \
@@ -28,4 +29,4 @@ affected=$(jq -c '.' < affected-components.json)
2829
echo "affected=$affected" >> $GITHUB_OUTPUT
2930

3031
[[ "$affected" == "[]" ]] && has_affected_stacks=true || has_affected_stacks=false
31-
echo "has-affected-stacks=$has_affected_stacks" >> $GITHUB_OUTPUT
32+
echo "has-affected-stacks=$has_affected_stacks" >> $GITHUB_OUTPUT

src/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def __init__(self,
1616
go_getter_tool: str,
1717
dry_run: bool,
1818
affected_components_file: str = '',
19+
gpg_key_id: str = '',
1920
pr_title_template: str = '',
2021
pr_body_template: str = '',
2122
pr_labels: str = 'component-update'):
@@ -30,6 +31,7 @@ def __init__(self,
3031
self.dry_run: bool = dry_run
3132
self.components_download_dir: str = io.create_tmp_dir()
3233
self.skip_component_repo_fetching: bool = False
34+
self.gpg_key_id: str = gpg_key_id
3335
self.pr_title_template: str = pr_title_template
3436
self.pr_body_template: str = pr_body_template
3537
self.pr_labels: List[str] = utils.parse_comma_or_new_line_separated_list(pr_labels)

src/github_provider.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ def create_branch_and_push_all_changes(self, repo_dir: str, branch_name: str, co
8989

9090
repo.git.checkout(new_branch)
9191
repo.git.add("-A")
92-
repo.index.commit(commit_message)
92+
93+
if self.__config.gpg_key_id:
94+
repo.index.commit(commit_message, gpg_sign=True, gpg_signing_key=self.__config.gpg_key_id)
95+
else:
96+
repo.index.commit(commit_message)
9397

9498
if not self.__config.dry_run:
9599
repo.git.push("--set-upstream", "origin", branch_name)

src/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ def main(github_api_token: str, config: Config):
6969
show_default=True,
7070
default="affected_components.json",
7171
help="Path to output file that will contain list of affected components in json format")
72+
@click.option('--gpg-key-id',
73+
required=False,
74+
show_default=True,
75+
default="",
76+
help="GPG key ID to sign commits")
7277
@click.option('--pr-title-template',
7378
required=False,
7479
show_default=True,
@@ -96,6 +101,7 @@ def cli_main(github_api_token,
96101
log_level,
97102
dry_run,
98103
affected_components_file,
104+
gpg_key_id,
99105
pr_title_template,
100106
pr_body_template,
101107
pr_labels):
@@ -113,6 +119,7 @@ def cli_main(github_api_token,
113119
go_getter_tool,
114120
dry_run,
115121
affected_components_file,
122+
gpg_key_id,
116123
pr_title_template,
117124
pr_body_template,
118125
pr_labels)

0 commit comments

Comments
 (0)