Skip to content

Commit

Permalink
Rename actor option (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jun 5, 2023
1 parent b66cb73 commit afcff83
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Expand Up @@ -300,7 +300,7 @@ jobs:
-e "INPUT_LOG_LEVEL" \
-e "INPUT_ROOT_LOG_LEVEL" \
-e "INPUT_GITHUB_TOKEN" \
-e "INPUT_GITHUB_ACTOR" \
-e "INPUT_GITHUB_TOKEN_ACTOR" \
-e "INPUT_GITHUB_RETRIES" \
-e "INPUT_COMMIT" \
-e "INPUT_COMMENT_TITLE" \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -274,7 +274,7 @@ The list of most notable options:
|:-----|:-----:|:----------|
|`commit`|`${{env.GITHUB_SHA}}`|An alternative commit SHA to which test results are published. The `push` and `pull_request`events are handled, but for other [workflow events](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#push) `GITHUB_SHA` may refer to different kinds of commits. See [GitHub Workflow documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) for details.|
|`github_token`|`${{github.token}}`|An alternative GitHub token, other than the default provided by GitHub Actions runner.|
|`github_actor`|`github-actions`|Used to find older comment to update. Note: this does not change the bot name while commenting. If you use any other GH app, you need provide that app name here. Otherwise all your run will create a new comment.|
|`github_token_actor`|`github-actions`|The name of the GitHub app that owns the GitHub API Access Token (see github_token). Used to identify pull request comments created by this action during earlier runs. Has to be set when `github_token` is set to a GitHub app installation token (other than GitHub actions). Otherwise, existing comments will not be updated, but new comments created. Note: this does not change the bot name of the pull request comments.|
|`github_retries`|`10`|Requests to the GitHub API are retried this number of times. The value must be a positive integer or zero.|
|`seconds_between_github_reads`|`0.25`|Sets the number of seconds the action waits between concurrent read requests to the GitHub API.|
|`seconds_between_github_writes`|`2.0`|Sets the number of seconds the action waits between concurrent write requests to the GitHub API.|
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Expand Up @@ -7,8 +7,8 @@ inputs:
description: 'GitHub API Access Token.'
default: ${{ github.token }}
required: false
github_actor:
description: 'The name of the actor that runs this action. Defaults to "github-actions"'
github_token_actor:
description: 'The name of the GitHub app that owns the GitHub API Access Token (see github_token). Used to identify pull request comments created by this action during earlier runs. Has to be set when `github_token` is set to a GitHub app installation token (other than GitHub actions). Otherwise, existing comments will not be updated, but new comments created. Note: this does not change the bot name of the pull request comments. Defaults to "github-actions".'
default: 'github-actions'
required: false
github_retries:
Expand Down
6 changes: 3 additions & 3 deletions composite/action.yml
Expand Up @@ -7,8 +7,8 @@ inputs:
description: 'GitHub API Access Token.'
default: ${{ github.token }}
required: false
github_actor:
description: 'The name of the actor that runs this action. Defaults to "github-actions"'
github_token_actor:
description: 'The name of the GitHub app that owns the GitHub API Access Token (see github_token). Used to identify pull request comments created by this action during earlier runs. Has to be set when `github_token` is set to a GitHub app installation token (other than GitHub actions). Otherwise, existing comments will not be updated, but new comments created. Note: this does not change the bot name of the pull request comments. Defaults to "github-actions".'
default: 'github-actions'
required: false
github_retries:
Expand Down Expand Up @@ -208,7 +208,7 @@ runs:
echo '##[endgroup]'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
GITHUB_ACTOR: ${{ inputs.github_actor }}
GITHUB_TOKEN_ACTOR: ${{ inputs.github_token_actor }}
GITHUB_RETRIES: ${{ inputs.github_retries }}
COMMIT: ${{ inputs.commit }}
CHECK_NAME: ${{ inputs.check_name }}
Expand Down
6 changes: 4 additions & 2 deletions python/publish/publisher.py
Expand Up @@ -734,8 +734,10 @@ def get_pull_request_comments(self, pull: PullRequest, order_by_updated: bool) -
.get('nodes')

def get_action_comments(self, comments: List[Mapping[str, Any]], is_minimized: Optional[bool] = False):
comment_body_start = f'## {self._settings.comment_title}\n'
comment_body_indicators = ['\nresults for commit ', '\nResults for commit ']
return list([comment for comment in comments
if comment.get('author', {}).get('login') == self._settings.actor
and (is_minimized is None or comment.get('isMinimized') == is_minimized)
and comment.get('body', '').startswith(f'## {self._settings.comment_title}\n')
and ('\nresults for commit ' in comment.get('body') or '\nResults for commit ' in comment.get('body'))])
and comment.get('body', '').startswith(comment_body_start)
and any(indicator in comment.get('body', '') for indicator in comment_body_indicators)])
3 changes: 1 addition & 2 deletions python/publish_test_results.py
Expand Up @@ -442,7 +442,6 @@ def get_settings(options: dict, gha: GithubAction) -> Settings:
annotations = get_annotations_config(options, event)
suite_logs_mode = get_var('REPORT_SUITE_LOGS', options) or default_report_suite_logs
ignore_runs = get_bool_var('IGNORE_RUNS', options, default=False)
actor = get_var('GITHUB_ACTOR', options) or 'github-actions'

fail_on = get_var('FAIL_ON', options) or 'test failures'
check_var(fail_on, 'FAIL_ON', 'Check fail mode', fail_on_modes)
Expand All @@ -459,7 +458,7 @@ def get_settings(options: dict, gha: GithubAction) -> Settings:

settings = Settings(
token=get_var('GITHUB_TOKEN', options),
actor=actor,
actor=get_var('GITHUB_TOKEN_ACTOR', options) or 'github-actions',
api_url=api_url,
graphql_url=graphql_url,
api_retries=int(retries),
Expand Down
13 changes: 9 additions & 4 deletions python/test/test_action_script.py
Expand Up @@ -267,9 +267,14 @@ def test_get_settings_event_file(self):

self.do_test_get_settings(EVENT_FILE=filepath, expected=self.get_settings(event=event, event_file=filepath))

def test_get_settings_github_actor(self):
self.do_test_get_settings(GITHUB_ACTOR='other-actor', expected=self.get_settings(actor='other-actor'))
self.do_test_get_settings(GITHUB_ACTOR=None, expected=self.get_settings(actor='github-actions'))
def test_get_settings_github_token(self):
self.do_test_get_settings(GITHUB_TOKEN='token-one', expected=self.get_settings(token='token-one'))
self.do_test_get_settings(GITHUB_TOKEN='token-two', expected=self.get_settings(token='token-two'))
# see test_get_settings_missing_github_vars

def test_get_settings_github_token_actor(self):
self.do_test_get_settings(GITHUB_TOKEN_ACTOR='other-actor', expected=self.get_settings(actor='other-actor'))
self.do_test_get_settings(GITHUB_TOKEN_ACTOR=None, expected=self.get_settings(actor='github-actions'))

def test_get_settings_github_api_url(self):
self.do_test_get_settings(GITHUB_API_URL='https://api.github.onpremise.com', expected=self.get_settings(api_url='https://api.github.onpremise.com'))
Expand Down Expand Up @@ -627,7 +632,7 @@ def do_test_get_settings(self,
TEST_CHANGES_LIMIT='10', # not an int
CHECK_NAME='check name', # defaults to 'Test Results'
GITHUB_TOKEN='token',
GITHUB_ACTOR='actor',
GITHUB_TOKEN_ACTOR='actor',
GITHUB_REPOSITORY='repo',
COMMIT='commit', # defaults to get_commit_sha(event, event_name)
FILES='all-files',
Expand Down

0 comments on commit afcff83

Please sign in to comment.