Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/__test-action-matrix-outputs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
18 changes: 14 additions & 4 deletions actions/get-matrix-outputs/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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<<EOF" >> "$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 }}
21 changes: 16 additions & 5 deletions actions/set-matrix-output/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}