4646 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4747 with :
4848 ref : ${{ inputs.overlay-commit }}
49+ fetch-depth : 0
50+
51+ - name : Detect modified workspaces
52+ id : modified
53+ env :
54+ TARGET_BRANCH : ${{ inputs.target-branch }}
55+ OVERLAY_COMMIT : ${{ inputs.overlay-commit }}
56+ run : |
57+ # Fetch target branch to compare
58+ git fetch origin "$TARGET_BRANCH"
59+
60+ # Get list of modified workspaces in this PR
61+ MODIFIED=$(git diff --name-only "origin/$TARGET_BRANCH" "$OVERLAY_COMMIT" | \
62+ grep '^workspaces/' | cut -d'/' -f2 | sort -u || true)
63+
64+ echo "Modified workspaces in this PR:"
65+ if [[ -n "$MODIFIED" ]]; then
66+ echo "$MODIFIED"
67+ else
68+ echo " (none)"
69+ fi
70+
71+ # Export as multiline output
72+ echo "workspaces<<EOF" >> "$GITHUB_OUTPUT"
73+ echo "$MODIFIED" >> "$GITHUB_OUTPUT"
74+ echo "EOF" >> "$GITHUB_OUTPUT"
4975
5076 - name : Detect workspaces with E2E tests and published PR images
5177 id : detect
5581 GITHUB_REPO : ${{ github.repository }}
5682 INPUT_WORKSPACE : ${{ inputs.workspace }}
5783 PR_NUMBER : ${{ inputs.pr-number }}
84+ MODIFIED_WORKSPACES : ${{ steps.modified.outputs.workspaces }}
85+ CODECOV_TOKEN : ${{ secrets.CODECOV_TOKEN }}
5886 run : |
5987 CANDIDATES=()
6088
@@ -117,11 +145,46 @@ jobs:
117145 EXISTS=$(gh api "/orgs/${REPO_OWNER}/packages/container/${PACKAGE_PATH_ENCODED}/versions" \
118146 --jq "[.[] | select(.metadata.container.tags[] == \"$IMAGE_TAG\")] | length" 2>/dev/null || echo "0")
119147
120- if [[ "$EXISTS" -gt 0 ]]; then
148+ if [[ "$EXISTS" -le 0 ]]; then
149+ echo " $ws — PR image not found, skipping (run /publish first)"
150+ continue
151+ fi
152+
153+ # PR image exists — now check if workspace needs coverage
154+ IS_MODIFIED=false
155+ if echo "$MODIFIED_WORKSPACES" | grep -qx "$ws"; then
156+ IS_MODIFIED=true
157+ fi
158+
159+ if [[ "$IS_MODIFIED" == "true" ]]; then
121160 VALID+=("$ws")
122- echo " $ws — PR image exists ( $IMAGE_NAME:$IMAGE_TAG)"
161+ echo " $ws — modified, will run coverage (image: $IMAGE_NAME:$IMAGE_TAG)"
123162 else
124- echo " $ws — PR image not found, skipping (run /publish first)"
163+ # Not modified — check if coverage exists in Codecov
164+ # Read upstream repo from source.json
165+ UPSTREAM_REPO=$(jq -r '.repo // ""' "workspaces/$ws/source.json" 2>/dev/null | sed 's|https://github.com/||; s|\.git$||')
166+ UPSTREAM_SHA=$(jq -r '."repo-ref" // ""' "workspaces/$ws/source.json" 2>/dev/null)
167+
168+ if [[ -z "$UPSTREAM_REPO" || -z "$UPSTREAM_SHA" || "$UPSTREAM_REPO" == "null" || "$UPSTREAM_SHA" == "null" ]]; then
169+ echo " $ws — cannot read source.json, skipping coverage check"
170+ continue
171+ fi
172+
173+ # Query Codecov for flag e2e-{workspace}
174+ # Use Codecov API v2: GET /api/v2/github/:owner/:repo/commits/:sha/flags
175+ CODECOV_RESPONSE=$(curl -s "https://codecov.io/api/v2/github/${UPSTREAM_REPO}/commits/${UPSTREAM_SHA}/flags" \
176+ -H "Authorization: bearer ${CODECOV_TOKEN}" 2>/dev/null || echo "{}")
177+
178+ # Check if flag "e2e-{workspace}" exists with coverage > 0
179+ FLAG_NAME="e2e-${ws}"
180+ HAS_COVERAGE=$(echo "$CODECOV_RESPONSE" | jq -r ".results[] | select(.flag_name == \"$FLAG_NAME\") | .coverage" 2>/dev/null || echo "null")
181+
182+ if [[ "$HAS_COVERAGE" == "null" || "$HAS_COVERAGE" == "0" || "$HAS_COVERAGE" == "" ]]; then
183+ VALID+=("$ws")
184+ echo " $ws — no existing coverage (flag: $FLAG_NAME not found), will run"
185+ else
186+ echo " $ws — has coverage ($HAS_COVERAGE%) and not modified, skipping"
187+ fi
125188 fi
126189 done
127190
@@ -147,20 +210,27 @@ jobs:
147210 script : |
148211 const body = `### ⚠️ E2E Coverage Tests Skipped
149212
150- No workspaces found with both:
151- - E2E test suite (\`workspaces/*/e2e-tests/\`)
152- - PR-built plugin images in GHCR (\`pr_${{ inputs.pr-number }}__*\`)
213+ No workspaces found needing coverage collection.
214+
215+ **Coverage runs for workspaces that:**
216+ - Have an E2E test suite (\`workspaces/*/e2e-tests/\`)
217+ - Have PR-built plugin images in GHCR (\`pr_${{ inputs.pr-number }}__*\`)
218+ - AND either:
219+ - Were modified in this PR, OR
220+ - Have no existing coverage in Codecov
153221
154- **Possible reasons:**
155- 1. You haven't run \`/publish\` yet → Images don't exist
222+ **Possible reasons for skipping :**
223+ 1. You haven't run \`/publish\` yet → PR images don't exist
156224 2. This PR doesn't modify any workspace with E2E tests
157- 3. PR images exist but workspace has no \`e2e-tests/\` directory
225+ 3. All workspaces with E2E tests already have coverage in Codecov
226+ 4. Workspace has no \`e2e-tests/\` directory
158227
159228 **If you need coverage:**
160- 1. Make sure your PR modifies a workspace that has \`e2e-tests/\`
161- 2. Comment \`/publish\` to build the plugin images
162- 3. Wait for publish to complete successfully
163- 4. Then comment \`/test e2e-ocp-helm\``;
229+ 1. Make sure your PR modifies a workspace that has \`e2e-tests/\`, OR
230+ 2. Ensure there are workspaces without existing coverage
231+ 3. Comment \`/publish\` to build the plugin images
232+ 4. Wait for publish to complete successfully
233+ 5. Coverage tests will run automatically (triggered by /publish success)`;
164234
165235 await github.rest.issues.createComment({
166236 ...context.repo,
0 commit comments