@@ -49,40 +49,57 @@ runs:
4949 name : ${{ inputs.artifact-name }}
5050 path : ${{ inputs.artifact-path }}
5151
52+ - name : Checkout repository
53+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
54+ with :
55+ path : ${{ inputs.path }}
56+
5257 - name : Check JUnit reports SHA
5358 id : junit-reports-sha
5459 shell : bash
5560 run : |
5661 echo "Checking JUnit reports SHA"
5762 UPLOAD_SHA_ARTIFACT=${{ inputs.upload-artifact }}
5863 CHECKOUT_REF=${{ inputs.git-branch }}
59- if [ -d ${{ inputs.artifact-path }} ]; then
60- cd ${{ inputs.artifact-path }}
61- if [ -f junit-reports-sha.txt ]; then
64+
65+ # Check if we have a SHA artifact - if so, always use that SHA for repeatable test distribution
66+ if [ -f ${{ inputs.artifact-path }}/junit-reports-sha.txt ]; then
67+ SAVED_SHA=$(cat ${{ inputs.artifact-path }}/junit-reports-sha.txt)
68+ echo "Found existing SHA artifact: $SAVED_SHA"
69+ cd ${{ inputs.path }}
70+ echo "Checking out specific SHA: $SAVED_SHA for repeatable test distribution"
71+ git fetch --quiet
72+ git checkout $SAVED_SHA
73+ UPLOAD_SHA_ARTIFACT=false
74+ else
75+ # No SHA artifact exists, handle branch checkout and potentially create new SHA artifact
76+ if [ ! -d ${{ inputs.artifact-path }} ]; then
77+ mkdir ${{ inputs.artifact-path }} || true
78+ fi
79+ cd ${{ inputs.path }}
80+ if git ls-remote --exit-code --heads origin $CHECKOUT_REF; then
81+ echo "Switching to existing branch: $CHECKOUT_REF"
82+ git fetch --quiet
83+ git switch $CHECKOUT_REF
84+ else
85+ echo "Branch $CHECKOUT_REF does not exist, staying on default branch"
6286 UPLOAD_SHA_ARTIFACT=false
63- CHECKOUT_REF=$(cat junit-reports-sha.txt)
6487 fi
65- else
66- mkdir ${{ inputs.artifact-path }} || true
6788 fi
89+
6890 if [ "$UPLOAD_SHA_ARTIFACT" == "true" ]; then
69- echo "Checking out JUnit reports from branch $CHECKOUT_REF"
91+ echo "Will upload JUnit reports SHA for branch $CHECKOUT_REF"
7092 else
71- echo "Checking out JUnit reports from previously used SHA $CHECKOUT_REF "
93+ echo "Will not upload JUnit reports SHA"
7294 fi
95+
7396 # we can only upload the artifact once, so only do this on the first split
7497 if [ "${{ inputs.split-index }}" != "0" ]; then
7598 echo "Skipping upload of JUnit reports SHA on this index"
7699 UPLOAD_SHA_ARTIFACT=false
77100 fi
101+
78102 echo "upload-artifact=${UPLOAD_SHA_ARTIFACT}" >> "$GITHUB_OUTPUT"
79- echo "ref=${CHECKOUT_REF}" >> "$GITHUB_OUTPUT"
80-
81- - name : Checkout repository
82- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
83- with :
84- path : ${{ inputs.path }}
85- ref : ${{ steps.junit-reports-sha.outputs.ref }}
86103
87104 - name : Save JUnit reports SHA
88105 if : ${{ steps.junit-reports-sha.outputs.upload-artifact == 'true' }}
0 commit comments