From b68b5ac8dca098c19d674e336cb40f6cf67153fe Mon Sep 17 00:00:00 2001 From: Rob Bos Date: Fri, 21 Jul 2023 09:11:13 +0000 Subject: [PATCH] Adding support for an output file instead of json string (which can become to big) --- .devcontainer/devcontainer.json | 40 +++++++++++++++++++++++++++++++++ .github/workflows/testing.yml | 17 +++++++++++++- Src/PowerShell/entrypoint.ps1 | 12 ++++++++-- action.yml | 2 ++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5fb2dc2 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/powershell +{ + "name": "PowerShell", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/powershell:lts-debian-11", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "true", + "username": "vscode", + "upgradePackages": "false", + "nonFreePackages": "true" + }, + "ghcr.io/devcontainers/features/github-cli:1": {} + }, + + "postCreateCommand": "sudo chsh vscode -s \"$(which pwsh)\"", + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "terminal.integrated.defaultProfile.linux": "pwsh" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-vscode.powershell" + ] + } + } + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index b7bc59b..3ed252a 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -35,7 +35,22 @@ jobs: Write-Host "Found [$($actions.Length)] actions" Set-Content -Value "Found [$($actions.Length)] actions" -Path $env:GITHUB_STEP_SUMMARY } - + + - shell: pwsh + run: | + # check the output file location to contain the expected content + Write-Host "Found actions file location here [${{ steps.load-actions.outputs.actions-file }}]" + $content = Get-Content -Path '${{ steps.load-actions.outputs.actions-file }}' + $actions = $content | ConvertFrom-Json + if ($actions.Length -le 0) { + Set-Content -Value "No actions found" -Path $env:GITHUB_STEP_SUMMARY + throw "No actions found" + } + else { + Write-Host "Found [$($actions.Length)] actions" + Set-Content -Value "Found [$($actions.Length)] actions" -Path $env:GITHUB_STEP_SUMMARY + } + - name: Upload result file as artefact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: diff --git a/Src/PowerShell/entrypoint.ps1 b/Src/PowerShell/entrypoint.ps1 index 7738cd9..bd23a77 100644 --- a/Src/PowerShell/entrypoint.ps1 +++ b/Src/PowerShell/entrypoint.ps1 @@ -28,9 +28,17 @@ function main { # wite the file outside of the container so we can pick it up Write-Host "Found [$($actions.Count)] actions " #Write-Verbose $actions | ConvertTo-Json -Depth 10 - $jsonObject = ($actions | ConvertTo-Json -Depth 10 -Compress) - Set-Content -Value "actions='$jsonObject'" -Path $env:GITHUB_OUTPUT + $jsonObject = ($actions | ConvertTo-Json -Depth 10 -Compress) + Set-Content -Value "$jsonObject" -Path $filePath + + # store the json in a file and write the path to the output variable + $filePath = $env:GITHUB_WORKSPACE/used-actions.json + Set-Content -Value "actions-file='$filePath'" -Path $env:GITHUB_OUTPUT Write-Host "Stored actions in the actions output. Use $${{ steps..outputs.actions }} in next action to load the json" + Write-Host "Stored actions file in the actions output. Use $${{ steps..outputs.actions-file }} in next action to load the file" + + # write json content to output variable for backward compatibility (this used to be the only way to get the json) + Set-Content -Value "actions='$jsonObject'" -Path $env:GITHUB_OUTPUT } try { diff --git a/action.yml b/action.yml index d1e0970..17535d1 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,8 @@ inputs: outputs: actions: description: 'List of all actions used in the organization' + actions-file: + description: 'Location of the file containing the list of all actions used in the organization' runs: using: 'docker' image: 'Dockerfile'