Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update support for workflow_dispatch #51

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ This action provides the following outputs:

- Currently, code coverage profiles are uploaded as GitHub artifacts which automatically expire after 90 days.
In a repository which receives changes only infrequently, this might lead to issues when trying to compare
the code coverage of a pull request with the code coverage of the main branch (see fgrosse/go-coverage-report#5).
the code coverage of a pull request with the code coverage of the main branch (see fgrosse/go-coverage-report#5).
As a workaround, consider using `workflow_dispatch`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As a workaround, consider using `workflow_dispatch`.
As a workaround, consider using `workflow_dispatch` or `schedule`.

- Support **for forks** is limited since the necessary `GITHUB_TOKEN` permissions don't allow to post comments to the
pull request of the base repository (see fgrosse/go-coverage-report#15). If forks are important for you, this action
might not be the best solution.
Expand Down
7 changes: 6 additions & 1 deletion scripts/github-action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ end_group
start_group "Download code coverage results from target branch"
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=push --json=databaseId --limit=1 -q '.[] | .databaseId')
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
echo "::error::No successful run found on the target branch"
echo "::warning::No successful run found for 'push' event. Checking for 'workflow_dispatch' event..."
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=workflow_dispatch --json=databaseId --limit=1 -q '.[] | .databaseId')
fi

if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
echo "::error::No successful run found on the target branch for 'push' or 'workflow_dispatch' events."
Comment on lines +104 to +109

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could add more events, can we also check for schedule events? Ran into this issue as well. Thanks!

Suggested change
echo "::warning::No successful run found for 'push' event. Checking for 'workflow_dispatch' event..."
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=workflow_dispatch --json=databaseId --limit=1 -q '.[] | .databaseId')
fi
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
echo "::error::No successful run found on the target branch for 'push' or 'workflow_dispatch' events."
echo "::warning::No successful run found for 'push' event. Checking for 'workflow_dispatch' event..."
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=workflow_dispatch --json=databaseId --limit=1 -q '.[] | .databaseId')
fi
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
echo "::warning::No successful run found for 'workflow_dispatch' event. Checking for 'schedule' event..."
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=schedule --json=databaseId --limit=1 -q '.[] | .databaseId')
fi
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
echo "::error::No successful run found on the target branch for 'push' or 'workflow_dispatch' or 'schedule' events."

exit 1
fi

Expand Down