@@ -49,40 +49,54 @@ 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
60+ working-directory : ${{ inputs.path }}
5561 run : |
5662 echo "Checking JUnit reports SHA"
5763 UPLOAD_SHA_ARTIFACT=${{ inputs.upload-artifact }}
5864 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
65+ if [ -f "../${{ inputs.artifact-path }}/junit-reports-sha.txt" ]; then
66+ SAVED_SHA=$(cat "../${{ inputs.artifact-path }}/junit-reports-sha.txt")
67+ echo "Checking out saved SHA '$SAVED_SHA' for repeatable test distribution"
68+ git fetch --quiet
69+ if git rev-parse --verify "$SAVED_SHA^{commit}" >/dev/null 2>&1; then
70+ git checkout --quiet "$SAVED_SHA"
6271 UPLOAD_SHA_ARTIFACT=false
63- CHECKOUT_REF=$(cat junit-reports-sha.txt)
72+ else
73+ echo "Error: Saved SHA '$SAVED_SHA' is not a valid commit. Aborting checkout." >&2
74+ exit 1
6475 fi
6576 else
66- mkdir ${{ inputs.artifact-path }} || true
67- fi
68- if [ "$UPLOAD_SHA_ARTIFACT" == "true" ]; then
69- echo "Checking out JUnit reports from branch $CHECKOUT_REF"
70- else
71- echo "Checking out JUnit reports from previously used SHA $CHECKOUT_REF"
77+ # no SHA artifact exists, handle branch checkout and potentially create new SHA artifact
78+ if git ls-remote --exit-code --heads origin "$CHECKOUT_REF"; then
79+ echo "Switching to existing branch: $CHECKOUT_REF"
80+ git fetch --quiet
81+ git switch "$CHECKOUT_REF"
82+ else
83+ echo "Branch $CHECKOUT_REF does not exist, no JUnit test reports available"
84+ cd ..
85+ rm -rf "${{ inputs.path }}"
86+ mkdir -p "${{ inputs.path }}"
87+ UPLOAD_SHA_ARTIFACT=false
88+ fi
7289 fi
7390 # we can only upload the artifact once, so only do this on the first split
7491 if [ "${{ inputs.split-index }}" != "0" ]; then
7592 echo "Skipping upload of JUnit reports SHA on this index"
7693 UPLOAD_SHA_ARTIFACT=false
94+ elif [ "$UPLOAD_SHA_ARTIFACT" == "true" ]; then
95+ echo "Will upload JUnit reports SHA for branch $CHECKOUT_REF"
96+ else
97+ echo "Will not upload JUnit reports SHA"
7798 fi
7899 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 }}
86100
87101 - name : Save JUnit reports SHA
88102 if : ${{ steps.junit-reports-sha.outputs.upload-artifact == 'true' }}
91105 run : |
92106 SHA=$(git rev-parse HEAD)
93107 echo "Saving JUnit reports SHA $SHA"
94- cd ../${{ inputs.artifact-path }}
108+ mkdir -p "../${{ inputs.artifact-path }}"
109+ cd "../${{ inputs.artifact-path }}"
95110 echo -n "$SHA" > junit-reports-sha.txt
96111
97112 - name : Upload JUnit report SHA
0 commit comments