From e19cd061dac5eb2f45d1df01a0ffcd7b5aa0a255 Mon Sep 17 00:00:00 2001 From: Rob Bos Date: Fri, 21 Jul 2023 16:51:13 +0200 Subject: [PATCH] Enable output file instead of json string (#58) --- .devcontainer/devcontainer.json | 40 ++++++++++++++++++++++++++ .github/workflows/testing.yml | 42 ++++++++++++++++++++++++++-- Src/PowerShell/entrypoint.ps1 | 15 ++++++++-- Src/PowerShell/load-used-actions.ps1 | 2 +- action.yml | 2 ++ 5 files changed, 94 insertions(+), 7 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..4feac08 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -35,12 +35,30 @@ jobs: Write-Host "Found [$($actions.Length)] actions" Set-Content -Value "Found [$($actions.Length)] actions" -Path $env:GITHUB_STEP_SUMMARY } - + + - shell: pwsh + name: check the output file location to contain the expected content + run: | + # check the output file location to contain the expected content + Write-Host "Got 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: name: actions-${{ env.GITHUB_REPOSITORY_OWNER }} - path: actions.json + path: | + actions.json + used-actions.json load-all-used-actions-other-org: runs-on: ubuntu-latest @@ -71,9 +89,27 @@ jobs: Write-Host "Found [$($actions.Length)] actions" Set-Content -Value "Found [$($actions.Length)] actions" -Path $env:GITHUB_STEP_SUMMARY } + + - shell: pwsh + name: check the output file location to contain the expected content + run: | + # check the output file location to contain the expected content + Write-Host "Got 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: name: actions-${{ env.organization }} - path: actions.json \ No newline at end of file + path: | + actions.json + used-actions.json diff --git a/Src/PowerShell/entrypoint.ps1 b/Src/PowerShell/entrypoint.ps1 index 7738cd9..21e2c91 100644 --- a/Src/PowerShell/entrypoint.ps1 +++ b/Src/PowerShell/entrypoint.ps1 @@ -27,10 +27,19 @@ 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) + + # store the json in a file and write the path to the output variable + $fileName = "used-actions.json" + $filePath = "$($env:GITHUB_WORKSPACE)/$fileName" + + Set-Content -Value "$jsonObject" -Path "$filePath" + Set-Content -Value "actions-file=$fileName" -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 from the $$GITHUB_WORKSPACE folder" + + # write json content to output variable for backward compatibility (this used to be the only way to get the json) + Add-Content -Value "actions='$jsonObject'" -Path $env:GITHUB_OUTPUT } try { diff --git a/Src/PowerShell/load-used-actions.ps1 b/Src/PowerShell/load-used-actions.ps1 index 0628b36..2677418 100644 --- a/Src/PowerShell/load-used-actions.ps1 +++ b/Src/PowerShell/load-used-actions.ps1 @@ -190,7 +190,7 @@ function main() { $fileName = "summarized-actions.json" $jsonObject = ($summarizeActions | ConvertTo-Json -Depth 10) New-Item -Path $fileName -Value $jsonObject -Force | Out-Null - Write-Host "Stored the summarized usage info into this file: [$fileName]" + Write-Host "Stored the summarized usage info into this file: [$fileName] in this directory: [$PWD]" # upload the data into the marketplaceRepo #Write-Host "Found [$($actionsFound.actions.Length)] actions in use!" 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'