diff --git a/.github/workflows/__test-action-matrix-outputs.yml b/.github/workflows/__test-action-matrix-outputs.yml index 063f1b61..90e69e70 100644 --- a/.github/workflows/__test-action-matrix-outputs.yml +++ b/.github/workflows/__test-action-matrix-outputs.yml @@ -9,16 +9,32 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: ./actions/set-matrix-output + - id: set-matrix-output-1 + uses: ./actions/set-matrix-output with: value: '"test content 1"' artifact-name: "test-matrix-outputs" - - uses: ./actions/set-matrix-output + - id: set-matrix-output-2 + uses: ./actions/set-matrix-output with: value: '"test content 2"' artifact-name: "test-matrix-outputs" + - name: Check set matrix outputs + run: | + EXPECTED_ARTIFACT_NAME="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-test-matrix-outputs" + + if [ "${{ steps.set-matrix-output-1.outputs.artifact-name }}" != "$EXPECTED_ARTIFACT_NAME" ]; then + echo "Set matrix output 1 result is not valid" + exit 1 + fi + + if [ "${{ steps.set-matrix-output-2.outputs.artifact-name }}" != "$EXPECTED_ARTIFACT_NAME" ]; then + echo "Set matrix output 2 result is not valid" + exit 1 + fi + - id: get-matrix-outputs uses: ./actions/get-matrix-outputs with: @@ -33,8 +49,8 @@ jobs: - name: Check artifacts have been deleted run: | - ARTIFACTS_PATH="/tmp/test-matrix-outputs" + ARTIFACTS_PATH="/tmp/$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-test-matrix-outputs" if [ -d "$ARTIFACTS_PATH" ]; then echo "Artifacts have not been deleted" exit 1 - fi + fi diff --git a/actions/get-matrix-outputs/action.yml b/actions/get-matrix-outputs/action.yml index bc3bea47..41ddb466 100644 --- a/actions/get-matrix-outputs/action.yml +++ b/actions/get-matrix-outputs/action.yml @@ -24,17 +24,27 @@ outputs: runs: using: "composite" steps: + - id: prepare-download + shell: bash + run: | + # Forge the unique artifact name for the current workflow + ARTIFACT_NAME="${{ github.run_id }}-${{ github.run_number }}-${{ inputs.artifact-name }}" + echo "artifact-name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT" + + ARTIFACT_PATH="/tmp/$ARTIFACT_NAME" + echo "artifact-path=$ARTIFACT_PATH" >> "$GITHUB_OUTPUT" + - uses: actions/download-artifact@v3 with: - name: ${{ inputs.artifact-name }} - path: /tmp/${{ inputs.artifact-name }} + name: ${{ steps.prepare-download.outputs.artifact-name }} + path: ${{ steps.prepare-download.outputs.artifact-path }} - id: read-artifacts shell: bash run: | - RESULT=$(jq -sc "." /tmp/${{ inputs.artifact-name }}/*.json) + RESULT=$(jq -sc "." ${{ steps.prepare-download.outputs.artifact-path }}/*.json) echo "result<> "$GITHUB_OUTPUT" && echo "$RESULT" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT" - if: ${{ inputs.remove-artifact == 'true' }} shell: bash - run: rm -rf /tmp/${{ inputs.artifact-name }} + run: rm -rf ${{ steps.prepare-download.outputs.artifact-path }} diff --git a/actions/set-matrix-output/action.yml b/actions/set-matrix-output/action.yml index a4f54248..4b717b3e 100644 --- a/actions/set-matrix-output/action.yml +++ b/actions/set-matrix-output/action.yml @@ -15,18 +15,29 @@ inputs: artifact-name: description: "The name of the artifact to upload." required: true +outputs: + artifact-name: + description: "The real unique name of the uploaded artifact." + value: ${{ steps.prepare-upload.outputs.artifact-name }} runs: using: "composite" steps: - - shell: bash + - id: prepare-upload + shell: bash run: | - mkdir -p "/tmp/${{ inputs.artifact-name }}" + # Define a unique artifact name for the current workflow + ARTIFACT_NAME="${{ github.run_id }}-${{ github.run_number }}-${{ inputs.artifact-name }}" + echo "artifact-name=$ARTIFACT_NAME" >> "$GITHUB_OUTPUT" + + ARTIFACT_PATH="/tmp/$ARTIFACT_NAME" + echo "artifact-path=$ARTIFACT_PATH" >> "$GITHUB_OUTPUT" + mkdir -p "$ARTIFACT_PATH" MAX_ATTEMPTS=10 MATRIX_OUTPUT_FILE="" for i in $(seq 1 $MAX_ATTEMPTS); do - MATRIX_OUTPUT_FILE="/tmp/${{ inputs.artifact-name }}/${{ inputs.artifact-name }}-$(uuidgen).json" + MATRIX_OUTPUT_FILE="$ARTIFACT_PATH/${{ inputs.artifact-name }}-$(uuidgen).json" if [ ! -f "$MATRIX_OUTPUT_FILE" ]; then break fi @@ -41,5 +52,5 @@ runs: - uses: actions/upload-artifact@v3 with: - name: ${{ inputs.artifact-name }} - path: /tmp/${{ inputs.artifact-name }} + name: ${{ steps.prepare-upload.outputs.artifact-name }} + path: ${{ steps.prepare-upload.outputs.artifact-path }}