diff --git a/.github/workflows/__test-action-matrix-outputs.yml b/.github/workflows/__test-action-matrix-outputs.yml index 832a041..65e61a8 100644 --- a/.github/workflows/__test-action-matrix-outputs.yml +++ b/.github/workflows/__test-action-matrix-outputs.yml @@ -4,8 +4,8 @@ on: workflow_call: jobs: - tests: - name: Tests for set/get matrix outputs + tests-1: + name: Arrange - Set first output strategy: matrix: os: @@ -15,45 +15,67 @@ jobs: steps: - uses: actions/checkout@v4 - - id: set-matrix-output-1 + - id: set-matrix-output uses: ./actions/set-matrix-output with: value: | { "test": "test content 1" } artifact-name: "test-matrix-outputs-${{ matrix.os }}" - - id: set-matrix-output-2 - uses: ./actions/set-matrix-output - with: - value: "" - artifact-name: "test-matrix-outputs-${{ matrix.os }}" - - - id: set-matrix-output-3 - uses: ./actions/set-matrix-output - with: - value: | - { "test": "test content 2" } - artifact-name: "test-matrix-outputs-${{ matrix.os }}" - - name: Check set matrix outputs shell: bash run: | EXPECTED_ARTIFACT_NAME="$GITHUB_RUN_ID-$GITHUB_RUN_NUMBER-test-matrix-outputs-${{ matrix.os }}" - if [ "${{ steps.set-matrix-output-1.outputs.artifact-name }}" != "$EXPECTED_ARTIFACT_NAME" ]; then + if [ "${{ steps.set-matrix-output.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 + tests-2: + name: Arrange - Set empty output + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 - if [ "${{ steps.set-matrix-output-3.outputs.artifact-name }}" != "$EXPECTED_ARTIFACT_NAME" ]; then - echo "Set matrix output 3 result is not valid" - exit 1 - fi + - uses: ./actions/set-matrix-output + with: + value: "" + artifact-name: "test-matrix-outputs-${{ matrix.os }}" + + tests-3: + name: Arrange - Set third output + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - uses: ./actions/set-matrix-output + with: + value: | + { "test": "test content 3" } + artifact-name: "test-matrix-outputs-${{ matrix.os }}" + + assert: + needs: [tests-1, tests-2, tests-3] + name: Assert - Check outputs + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 - id: get-matrix-outputs uses: ./actions/get-matrix-outputs @@ -65,7 +87,14 @@ jobs: run: | OUTPUT_RESULT='${{ steps.get-matrix-outputs.outputs.result }}' - if [ "$OUTPUT_RESULT" != '[{ "test": "test content 1" },{ "test": "test content 2" }]' ]; then + # Output result must be a json array of 2 entries + if [ "$(echo "$OUTPUT_RESULT" | jq -e '. | length')" != "2" ]; then + echo "Get matrix outputs result is not valid" + exit 1 + fi + + # Output result must contain the first and third entries + if [ "$(echo "$OUTPUT_RESULT" | jq -ce '. | sort')" != '[{"test":"test content 1"},{"test":"test content 3"}]' ]; then echo "Get matrix outputs result is not valid" exit 1 fi diff --git a/.github/workflows/need-fix-to-issue.yml b/.github/workflows/need-fix-to-issue.yml index e9d110f..069961a 100644 --- a/.github/workflows/need-fix-to-issue.yml +++ b/.github/workflows/need-fix-to-issue.yml @@ -32,10 +32,6 @@ on: type: string required: false -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: need-fix-to-issue: runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }} diff --git a/actions/get-matrix-outputs/action.yml b/actions/get-matrix-outputs/action.yml index 39f184c..939b535 100644 --- a/actions/get-matrix-outputs/action.yml +++ b/actions/get-matrix-outputs/action.yml @@ -16,6 +16,10 @@ inputs: description: "Define weather to remove the downloaded artifact after reading." required: false default: "true" + token: + description: GitHub token with read and write access to actions for the repository. + default: ${{ github.token }} + required: false outputs: result: description: "The matrix combined JSON outputs." @@ -34,10 +38,11 @@ runs: ARTIFACT_PATH="/tmp/$ARTIFACT_NAME" echo "artifact-path=$ARTIFACT_PATH" >> "$GITHUB_OUTPUT" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: ${{ steps.prepare-download.outputs.artifact-name }} path: ${{ steps.prepare-download.outputs.artifact-path }} + pattern: ${{ steps.prepare-download.outputs.artifact-name }}-* + merge-multiple: true - id: read-artifacts uses: actions/github-script@v7 @@ -64,6 +69,7 @@ runs: } - if: ${{ inputs.remove-artifact == 'true' }} - uses: geekyeggo/delete-artifact@v2 + uses: geekyeggo/delete-artifact@v4 with: - name: ${{ steps.prepare-download.outputs.artifact-name }} + token: ${{ inputs.token }} + name: ${{ steps.prepare-download.outputs.artifact-name }}-* diff --git a/actions/set-matrix-output/action.yml b/actions/set-matrix-output/action.yml index 87fd043..28b7669 100644 --- a/actions/set-matrix-output/action.yml +++ b/actions/set-matrix-output/action.yml @@ -34,31 +34,19 @@ runs: const artifactName = `${{ github.run_id }}-${{ github.run_number }}-${{ inputs.artifact-name }}`; core.setOutput("artifact-name", artifactName); - const artifactPath = join("/tmp",artifactName); - core.setOutput("artifact-path", artifactPath); - await io.mkdirP(artifactPath); - - const maxAttempts = 10; - let matrixOutputFile = ''; - for (let i = 1; i <= maxAttempts; i++) { - const uniquid = randomUUID(); - const timestamp = Date.now(); - const matrixOutputFileName = `${timestamp}-${artifactName}-${uniquid}.json`; + const uniquid = randomUUID(); + const timestamp = Date.now(); + const artifactUniqueName = `${artifactName}-${timestamp}-${uniquid}`; + core.setOutput("artifact-unique-name", artifactUniqueName); - matrixOutputFile = join(artifactPath, matrixOutputFileName); - if (!existsSync(matrixOutputFile)) { - break; - } - matrixOutputFile = ''; - } + const artifactDirPath = join("/tmp",artifactUniqueName); + await io.mkdirP(artifactDirPath); - if (!matrixOutputFile) { - core.setFailed(`Failed to find unique file name after ${maxAttempts} attempts`); - } - - writeFileSync(matrixOutputFile, `${{ inputs.value }}`); + const artifactPath = join(artifactDirPath, `${artifactUniqueName}.json`); + core.setOutput("artifact-path", artifactPath); + writeFileSync(artifactPath, `${{ inputs.value }}`); - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: - name: ${{ steps.prepare-upload.outputs.artifact-name }} + name: ${{ steps.prepare-upload.outputs.artifact-unique-name }} path: ${{ steps.prepare-upload.outputs.artifact-path }}