diff --git a/.github/workflows/__test-action-matrix-outputs.yml b/.github/workflows/__test-action-matrix-outputs.yml index 1216195..ebd74c5 100644 --- a/.github/workflows/__test-action-matrix-outputs.yml +++ b/.github/workflows/__test-action-matrix-outputs.yml @@ -5,8 +5,13 @@ on: jobs: tests: - name: Tests for set/get matrix outputs - runs-on: ubuntu-latest + name: Tests for set/get matrix outputs + strategy: + matrix: + os: + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index b10742d..689d893 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -30,11 +30,11 @@ on: required: false secrets: github-token: - description: 'Token for the repository. See https://github.com/actions/first-interaction#usage' + description: "Token for the repository. See https://github.com/actions/first-interaction#usage" jobs: greeting: - runs-on: ${{ fromJson(inputs.runs-on) }} + runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }} steps: - uses: actions/first-interaction@v1 with: diff --git a/actions/get-matrix-outputs/action.yml b/actions/get-matrix-outputs/action.yml index da1a8e6..9e01468 100644 --- a/actions/get-matrix-outputs/action.yml +++ b/actions/get-matrix-outputs/action.yml @@ -40,14 +40,25 @@ runs: path: ${{ steps.prepare-download.outputs.artifact-path }} - id: read-artifacts - shell: bash - run: | - RESULT=$(jq -sc "." ${{ steps.prepare-download.outputs.artifact-path }}/*.json) - echo "result<> "$GITHUB_OUTPUT" && echo "$RESULT" >> "$GITHUB_OUTPUT" && echo "EOF" >> "$GITHUB_OUTPUT" + uses: actions/github-script@v6 + with: + script: | + const { readFileSync } = require('fs'); - - if: ${{ inputs.remove-artifact == 'true' }} - shell: bash - run: rm -rf ${{ steps.prepare-download.outputs.artifact-path }} + const artifactPath = `${{ steps.prepare-download.outputs.artifact-path }}`; + const globber = await glob.create(`${artifactPath}/*.json`, {followSymbolicLinks: false}); + const artifactFiles = await globber.glob(); + + core.debug(`Found ${artifactFiles.length} files in ${artifactPath}`); + + const result = artifactFiles.map(file => readFileSync(file, 'utf8')).join(","); + + const shouldRemoveArtifact = `${{ inputs.remove-artifact }}` === 'true'; + if(shouldRemoveArtifact) { + await io.rmRF(artifactPath); + } + + return `[${result}]`; - if: ${{ inputs.remove-artifact == 'true' }} uses: geekyeggo/delete-artifact@v2 diff --git a/actions/set-matrix-output/action.yml b/actions/set-matrix-output/action.yml index 4b717b3..20fc598 100644 --- a/actions/set-matrix-output/action.yml +++ b/actions/set-matrix-output/action.yml @@ -24,31 +24,36 @@ runs: using: "composite" steps: - id: prepare-upload - shell: bash - run: | - # 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="$ARTIFACT_PATH/${{ inputs.artifact-name }}-$(uuidgen).json" - if [ ! -f "$MATRIX_OUTPUT_FILE" ]; then - break - fi - MATRIX_OUTPUT_FILE="" - done - if [ -z "$MATRIX_OUTPUT_FILE" ]; then - echo "Failed to find unique file name after $MAX_ATTEMPTS attempts" - exit 1 - fi - - echo '${{ inputs.value }}' > "$MATRIX_OUTPUT_FILE" + uses: actions/github-script@v6 + with: + script: | + const { join } = require('path'); + const { existsSync, writeFileSync } = require('fs'); + const { randomUUID } = require('crypto'); + + 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(); + matrixOutputFile = join(artifactPath, `${artifactName}-${uniquid}.json`); + if (!existsSync(matrixOutputFile)) { + break; + } + matrixOutputFile = ''; + } + + if (!matrixOutputFile) { + core.setFailed(`Failed to find unique file name after ${maxAttempts} attempts`); + } + + writeFileSync(matrixOutputFile, `${{ inputs.value }}`); - uses: actions/upload-artifact@v3 with: