Skip to content

Commit b6496ac

Browse files
authored
Add input to configure GitHub Actions workflow filename (#44)
* Enable configuring the GITHUB_BASELINE_WORKFLOW_REF * Update Inputs section in README.md * Add required: false
1 parent 4dec721 commit b6496ac

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
```yaml
115115
inputs:
116116
version:
117-
description: 'The exact version of the go-coverage-report tool to use.'
117+
description: 'The exact version tag of the go-coverage-report tool to use.'
118118
required: true
119119
default: "v1.1.1"
120120

@@ -142,16 +142,25 @@ inputs:
142142
required: false
143143
default: "github.com/${{ github.repository }}"
144144

145-
trim:
146-
description: 'Trim a prefix in the "Impacted Packages" column of the markdown report.'
147-
required: false
148-
149145
skip-comment:
150146
description: |
151147
Skip creating or updating the pull request comment. This may be useful when you want
152148
to generate the coverage report and modify it in your own scripts.
153149
required: false
154150
default: 'false'
151+
152+
trim:
153+
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
154+
required: false
155+
156+
github-baseline-workflow-ref:
157+
description: |
158+
The ref of the GitHub actions Workflow that produces the baseline coverage.
159+
By default, the GitHub Actions Workflow ref is used
160+
(e.g. "octocat/hello-world/.github/workflows/my-workflow.yml@refs/heads/my_branch").
161+
You can aso just pass the name of the Workflow file directly (e.g. "my-workflow.yml").
162+
default: ${{ github.workflow_ref }}
163+
required: false
155164
```
156165
157166
### Outputs

action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ inputs:
4646
description: Trim a prefix in the "Impacted Packages" column of the markdown report.
4747
required: false
4848

49+
github-baseline-workflow-ref:
50+
description: |
51+
The ref of the GitHub actions Workflow that produces the baseline coverage.
52+
By default, the GitHub Actions Workflow ref is used
53+
(e.g. "octocat/hello-world/.github/workflows/my-workflow.yml@refs/heads/my_branch").
54+
You can aso just pass the name of the Workflow file directly (e.g. "my-workflow.yml").
55+
default: ${{ github.workflow_ref }}
56+
required: false
57+
4958
outputs:
5059
coverage_report:
5160
description: 'The generated coverage report in Markdown format.'
@@ -81,8 +90,8 @@ runs:
8190
env:
8291
GH_REPO: ${{ github.repository }}
8392
GH_TOKEN: ${{ github.token }}
84-
GITHUB_WORKFLOW_REF: ${{ github.workflow_ref }}
85-
GITHUB_BASE_REF: ${{ github.base_ref }}
93+
GITHUB_BASELINE_WORKFLOW_REF: ${{ inputs.github-baseline-workflow-ref }}
94+
TARGET_BRANCH: ${{ github.base_ref }}
8695
CHANGED_FILES_PATH: .github/outputs/all_modified_files.json
8796
COVERAGE_ARTIFACT_NAME: ${{ inputs.coverage-artifact-name }}
8897
COVERAGE_FILE_NAME: ${{ inputs.coverage-file-name }}

scripts/github-action.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ this in the workflow file:
2424
env: …
2525
2626
You can use the following environment variables to configure the script:
27-
- GITHUB_WORKFLOW: The name of the Workflow (default: CI)
28-
- GITHUB_WORKFLOW_REF: The ref path to the workflow to use instead of GITHUB_WORKFLOW (optional)
29-
- GITHUB_BASE_REF: The base branch to compare the coverage results against (default: main)
27+
- GITHUB_BASELINE_WORKFLOW: The name of the GitHub actions Workflow that produces the baseline coverage (default: CI)
28+
- GITHUB_BASELINE_WORKFLOW_REF: The ref path to the workflow to use instead of GITHUB_BASELINE_WORKFLOW (optional)
29+
- TARGET_BRANCH: The base branch to compare the coverage results against (default: main)
3030
- COVERAGE_ARTIFACT_NAME: The name of the artifact containing the code coverage results (default: code-coverage)
3131
- COVERAGE_FILE_NAME: The name of the file containing the code coverage results (default: coverage.txt)
3232
- CHANGED_FILES_PATH: The path to the file containing the list of changed files (default: .github/outputs/all_modified_files.json)
@@ -44,8 +44,8 @@ fi
4444
GITHUB_REPOSITORY=$1
4545
GITHUB_PULL_REQUEST_NUMBER=$2
4646
GITHUB_RUN_ID=$3
47-
GITHUB_WORKFLOW=${GITHUB_WORKFLOW:-CI}
48-
TARGET_BRANCH=${GITHUB_BASE_REF:-main}
47+
GITHUB_BASELINE_WORKFLOW=${GITHUB_BASELINE_WORKFLOW:-CI}
48+
TARGET_BRANCH=${TARGET_BRANCH:-main}
4949
COVERAGE_ARTIFACT_NAME=${COVERAGE_ARTIFACT_NAME:-code-coverage}
5050
COVERAGE_FILE_NAME=${COVERAGE_FILE_NAME:-coverage.txt}
5151

@@ -75,9 +75,9 @@ if [[ -z ${GITHUB_OUTPUT+x} ]]; then
7575
exit 1
7676
fi
7777

78-
# If GITHUB_WORKFLOW_REF is defined, extract the workflow file path from it and use it instead of GITHUB_WORKFLOW
79-
if [[ -n ${GITHUB_WORKFLOW_REF+x} ]]; then
80-
GITHUB_WORKFLOW=$(basename "${GITHUB_WORKFLOW_REF%%@*}")
78+
# If GITHUB_BASELINE_WORKFLOW_REF is defined, extract the workflow file path from it and use it instead of GITHUB_BASELINE_WORKFLOW
79+
if [[ -n ${GITHUB_BASELINE_WORKFLOW_REF+x} ]]; then
80+
GITHUB_BASELINE_WORKFLOW=$(basename "${GITHUB_BASELINE_WORKFLOW_REF%%@*}")
8181
fi
8282

8383
export GH_REPO="$GITHUB_REPOSITORY"
@@ -99,7 +99,7 @@ rm -r "/tmp/gh-run-download-$GITHUB_RUN_ID"
9999
end_group
100100

101101
start_group "Download code coverage results from target branch"
102-
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_WORKFLOW" --event=push --json=databaseId --limit=1 -q '.[] | .databaseId')
102+
LAST_SUCCESSFUL_RUN_ID=$(gh run list --status=success --branch="$TARGET_BRANCH" --workflow="$GITHUB_BASELINE_WORKFLOW" --event=push --json=databaseId --limit=1 -q '.[] | .databaseId')
103103
if [ -z "$LAST_SUCCESSFUL_RUN_ID" ]; then
104104
echo "::error::No successful run found on the target branch"
105105
exit 1

0 commit comments

Comments
 (0)