mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-27 05:37:15 -05:00
Fix E2E-only PRs and duplicate E2E test runs after PR merges (#35368)
* use master or release base branch correctly for e2e-test-change only * prevent duplicate run for PR already merged to master or release branch
This commit is contained in:
@@ -18,7 +18,7 @@ outputs:
|
||||
description: Whether the PR contains only E2E test changes (true/false)
|
||||
value: ${{ steps.check.outputs.e2e_test_only }}
|
||||
image_tag:
|
||||
description: Docker image tag to use (master for E2E-only, short SHA for mixed)
|
||||
description: Docker image tag to use (base branch ref for E2E-only, short SHA for mixed)
|
||||
value: ${{ steps.check.outputs.image_tag }}
|
||||
|
||||
runs:
|
||||
@@ -33,7 +33,8 @@ runs:
|
||||
INPUT_HEAD_SHA: ${{ inputs.head_sha }}
|
||||
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
|
||||
run: |
|
||||
# Resolve SHAs from PR number if not provided
|
||||
# Resolve SHAs and base branch from PR number if not provided
|
||||
BASE_REF=""
|
||||
if [ -z "$INPUT_BASE_SHA" ] || [ -z "$INPUT_HEAD_SHA" ]; then
|
||||
if [ -z "$INPUT_PR_NUMBER" ]; then
|
||||
echo "::error::Either base_sha/head_sha or pr_number must be provided"
|
||||
@@ -44,14 +45,24 @@ runs:
|
||||
PR_DATA=$(gh api "repos/${{ github.repository }}/pulls/${INPUT_PR_NUMBER}")
|
||||
INPUT_BASE_SHA=$(echo "$PR_DATA" | jq -r '.base.sha')
|
||||
INPUT_HEAD_SHA=$(echo "$PR_DATA" | jq -r '.head.sha')
|
||||
BASE_REF=$(echo "$PR_DATA" | jq -r '.base.ref')
|
||||
|
||||
if [ -z "$INPUT_BASE_SHA" ] || [ "$INPUT_BASE_SHA" = "null" ] || \
|
||||
[ -z "$INPUT_HEAD_SHA" ] || [ "$INPUT_HEAD_SHA" = "null" ]; then
|
||||
echo "::error::Could not resolve SHAs for PR #${INPUT_PR_NUMBER}"
|
||||
exit 1
|
||||
fi
|
||||
elif [ -n "$INPUT_PR_NUMBER" ]; then
|
||||
# SHAs provided but we still need the base branch ref
|
||||
BASE_REF=$(gh api "repos/${{ github.repository }}/pulls/${INPUT_PR_NUMBER}" --jq '.base.ref')
|
||||
fi
|
||||
|
||||
# Default to master if base ref could not be determined
|
||||
if [ -z "$BASE_REF" ] || [ "$BASE_REF" = "null" ]; then
|
||||
BASE_REF="master"
|
||||
fi
|
||||
echo "PR base branch: ${BASE_REF}"
|
||||
|
||||
SHORT_SHA="${INPUT_HEAD_SHA::7}"
|
||||
|
||||
# Get changed files - try git first, fall back to API
|
||||
@@ -85,8 +96,9 @@ runs:
|
||||
|
||||
# Set outputs
|
||||
echo "e2e_test_only=${E2E_TEST_ONLY}" >> $GITHUB_OUTPUT
|
||||
if [ "$E2E_TEST_ONLY" = "true" ]; then
|
||||
echo "image_tag=master" >> $GITHUB_OUTPUT
|
||||
if [ "$E2E_TEST_ONLY" = "true" ] && \
|
||||
{ [ "$BASE_REF" = "master" ] || [[ "$BASE_REF" =~ ^release-[0-9]+\.[0-9]+$ ]]; }; then
|
||||
echo "image_tag=${BASE_REF}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "image_tag=${SHORT_SHA}" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
name: E2E Tests (full)
|
||||
name: E2E Tests (pull request)
|
||||
on:
|
||||
# Argo Events Trigger (automated):
|
||||
# - Triggered by: Enterprise CI/docker-image status check (success)
|
||||
@@ -72,16 +72,31 @@ jobs:
|
||||
# Argo Events trigger: commit SHA provided, resolve PR number
|
||||
if [ -n "$INPUT_COMMIT_SHA" ]; then
|
||||
echo "Automated trigger: resolving PR number from commit ${INPUT_COMMIT_SHA}"
|
||||
PR_NUMBER=$(gh api "repos/${{ github.repository }}/commits/${INPUT_COMMIT_SHA}/pulls" \
|
||||
--jq '.[0].number // empty' 2>/dev/null || echo "")
|
||||
if [ -n "$PR_NUMBER" ]; then
|
||||
echo "Found PR #${PR_NUMBER} for commit ${INPUT_COMMIT_SHA}"
|
||||
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
|
||||
echo "COMMIT_SHA=${INPUT_COMMIT_SHA}" >> $GITHUB_OUTPUT
|
||||
else
|
||||
PR_DATA=$(gh api "repos/${{ github.repository }}/commits/${INPUT_COMMIT_SHA}/pulls" \
|
||||
--jq '.[0] // empty' 2>/dev/null || echo "")
|
||||
PR_NUMBER=$(echo "$PR_DATA" | jq -r '.number // empty' 2>/dev/null || echo "")
|
||||
if [ -z "$PR_NUMBER" ]; then
|
||||
echo "::error::No PR found for commit ${INPUT_COMMIT_SHA}. This workflow is for PRs only."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found PR #${PR_NUMBER} for commit ${INPUT_COMMIT_SHA}"
|
||||
|
||||
# Skip if PR is already merged to master or a release branch.
|
||||
# The e2e-tests-on-merge workflow handles post-merge E2E tests.
|
||||
PR_MERGED=$(echo "$PR_DATA" | jq -r '.merged_at // empty' 2>/dev/null || echo "")
|
||||
PR_BASE_REF=$(echo "$PR_DATA" | jq -r '.base.ref // empty' 2>/dev/null || echo "")
|
||||
if [ -n "$PR_MERGED" ]; then
|
||||
if [ "$PR_BASE_REF" = "master" ] || [[ "$PR_BASE_REF" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
|
||||
echo "PR #${PR_NUMBER} is already merged to ${PR_BASE_REF}. Skipping - handled by e2e-tests-on-merge workflow."
|
||||
echo "PR_NUMBER=" >> $GITHUB_OUTPUT
|
||||
echo "COMMIT_SHA=" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_OUTPUT
|
||||
echo "COMMIT_SHA=${INPUT_COMMIT_SHA}" >> $GITHUB_OUTPUT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
@@ -90,6 +105,7 @@ jobs:
|
||||
exit 1
|
||||
|
||||
- name: ci/check-e2e-test-only
|
||||
if: steps.resolve.outputs.PR_NUMBER != ''
|
||||
id: e2e-check
|
||||
uses: ./.github/actions/check-e2e-test-only
|
||||
with:
|
||||
@@ -98,6 +114,7 @@ jobs:
|
||||
|
||||
check-changes:
|
||||
needs: resolve-pr
|
||||
if: needs.resolve-pr.outputs.PR_NUMBER != ''
|
||||
runs-on: ubuntu-24.04
|
||||
outputs:
|
||||
should_run: "${{ steps.check.outputs.should_run }}"
|
||||
|
||||
Reference in New Issue
Block a user