Skip to content

Commit

Permalink
Enable output file instead of json string (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos authored Jul 21, 2023
1 parent 098d989 commit e19cd06
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 7 deletions.
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
42 changes: 39 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
path: |
actions.json
used-actions.json
15 changes: 12 additions & 3 deletions Src/PowerShell/entrypoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.<step id>.outputs.actions }} in next action to load the json"
Write-Host "Stored actions file in the actions output. Use $${{ steps.<step id>.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 {
Expand Down
2 changes: 1 addition & 1 deletion Src/PowerShell/load-used-actions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit e19cd06

Please sign in to comment.