Skip to content

Commit

Permalink
Add support for finding reusable workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rajbos authored Sep 5, 2023
1 parent cb853d4 commit 62a08a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GITHUB_ACTOR=debugging
GITHUB_WORKSPACE=
GITHUB_OUTPUT=
GITHUB_WORKSPACE=github_workspace
GITHUB_OUTPUT=github_output_file
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
Src/PowerShell/summarized-actions.json
Src/PowerShell/github_output
Src/PowerShell/used-actions.json
Src/PowerShell/github_output_file
Src/PowerShell/entrypoint.ps1
Src/PowerShell/github_workspace/used-actions.json
14 changes: 12 additions & 2 deletions Src/PowerShell/entrypoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,18 @@ function main {
# 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"

if ($null -ne $env:GITHUB_WORKSPACE -and "" -ne $env:GITHUB_WORKSPACE) {
Write-Host "Writing actions to file in workspace: [$($env:GITHUB_WORKSPACE)]"
Set-Content -Value "$jsonObject" -Path "$filePath"
}
else {
Write-Host "Writing actions to file in current folder: [$($pwd)]"
$filePath = "./used-actions.json"
Set-Content -Value "$jsonObject" -Path "$filePath"
}

# write the name of the file to the output folder
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"
Expand Down
24 changes: 12 additions & 12 deletions Src/PowerShell/load-used-actions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ function SummarizeActionsUsed {

$summarized = @()
foreach ($action in $actions) {
$found = $summarized | Where-Object { $_.actionLink -eq $action.actionLink } # todo: summarize with reusable workflows as well
$found = $summarized | Where-Object { $_.actionLink -eq $action.actionLink -And $_.type -eq $action.type }
if ($null -ne $found) {
# action already found, add this info to it
# item already found, add this info to it
$newInfo = [PSCustomObject]@{
repo = $action.repo
workflowFileName = $action.workflowFileName
Expand All @@ -142,16 +142,17 @@ function SummarizeActionsUsed {
$found.count++
}
else {
# new action, create a new object
# new item, create a new object
$newItem = [PSCustomObject]@{
type = $action.type
actionLink = $action.actionLink
count = 1
workflows = @(
[PSCustomObject]@{
repo = $action.repo
workflowFileName = $action.workflowFileName
}
)
)
}
$summarized += $newItem
}
Expand All @@ -170,7 +171,7 @@ function LoadAllUsedActionsFromRepos {

# create hastable
$actions = @()
$i=0
#$i=0
foreach ($repo in $repos) {
if ($null -ne $repo -And $repo.full_name.Length -gt 0) {
Write-Host "Loading actions from repo: [$($repo.full_name)]"
Expand All @@ -180,13 +181,12 @@ function LoadAllUsedActionsFromRepos {

# comment out code below to stop after a certain number of repos to prevent issues with
# rate limiting on the load file count (that is not workin correctly)

$i++
if ($i -eq 2) {
# break on second result:
Write-Host "Breaking after [$i] repos"
return $actions
}
# $i++
# if ($i -eq 2) {
# # break on second result:
# Write-Host "Breaking after [$i] repos"
# return $actions
# }
}
}

Expand Down

0 comments on commit 62a08a9

Please sign in to comment.