Skip to content

Commit

Permalink
Refactor workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
MGaetan89 committed Feb 28, 2024
1 parent ef6fd27 commit 48f8ce6
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 32 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/techRadar/get_repositories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo repository_list_json=$(
gh repo list ${{ github.repository_owner }} \
--limit 1000 \
--source \
--no-archived \
--visibility public \
--json name,nameWithOwner,primaryLanguage,url \
--jq '. | tostring'
) >> $GITHUB_OUTPUT
59 changes: 59 additions & 0 deletions .github/workflows/techRadar/update_used_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

repository_names=$(
echo ${{ toJSON(steps.repository_list.outputs.repository_list_json) }} \
| jq '.[] | .nameWithOwner'
)

# Folder where temporary data will be stored
mkdir -p .packageManagers

# Load all the dependencies data
for name in $repository_names; do
# Get the list of dependencies by package manager
dependencies=$(
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$name/dependency-graph/sbom \
--jq '[ .sbom.packages.[] | { name: .name | sub("[a-zA-Z.]+[:/](?<package>.*)"; "\(.package)"), packageManager: .name | capture("(?<packageManager>[a-zA-Z.]+)[:/]").packageManager, version: .versionInfo } ] | reduce .[] as { $name, $packageManager, $version } ( {}; .[ $packageManager ] += [ $name + " v" + $version ] )'
)

# Extract the list of package managers
packageManagers=$(
echo $dependencies \
| jq -r '. | keys[]'
)

# Store the dependencies by package manager in specific files
for packageManager in $packageManagers; do
echo $dependencies \
| jq -r ".$packageManager[]" \
>> .packageManagers/$packageManager
done
done

# Filter the resulting dependencies
for file in $(ls .packageManagers); do
if [[ -s .packageManagers/$file ]]; then
cat .packageManagers/$file | sort | uniq > .packageManagers/${file}_sorted
mv .packageManagers/${file}_sorted .packageManagers/$file
else
rm .packageManagers/$file
fi
done

# Update the Markdown file with the extracted data
markdown_file="public/techRadar/used_dependencies.md"

echo -e "# Used dependencies\n" > $markdown_file

for file in $(ls .packageManagers); do
echo -e "## $file\n" >> $markdown_file

while read -r line; do
echo -e "- $line" >> $markdown_file
done < .packageManagers/$file

echo -e "" >> $markdown_file
done
5 changes: 5 additions & 0 deletions .github/workflows/techRadar/update_used_languages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo ${{ toJSON(steps.repository_list.outputs.repository_list_json) }} \
| jq '. | reduce .[] as { $name, $primaryLanguage, $url } ( {}; .[ $primaryLanguage.name | tostring ][$name] = $url )' \
| gomplate -d repositories=stdin:///in.json -f techRadar/used_languages.tmpl -o public/techRadar/used_languages.md
24 changes: 3 additions & 21 deletions .github/workflows/tech_radar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,15 @@ jobs:
id: repository_list
env:
GH_TOKEN: ${{ github.token }}
run: >
echo repository_list_json=$(
gh repo list ${{ github.repository_owner }}
--limit 1000
--source
--no-archived
--visibility public
--json name,nameWithOwner,primaryLanguage,url
--jq '. | tostring'
) >> $GITHUB_OUTPUT
run: ./.github/workflows/techRadar/get_repositories.sh

- name: Update the list of used languages
run: >
echo ${{ toJSON(steps.repository_list.outputs.repository_list_json) }}
| jq '. | reduce .[] as { $name, $primaryLanguage, $url } ( {}; .[ $primaryLanguage.name | tostring ][$name] = $url )'
| gomplate -d repositories=stdin:///in.json -f techRadar/used_languages.tmpl -o public/techRadar/used_languages.md
run: ./.github/workflows/techRadar/update_used_languages.sh

- name: Update the list of used dependencies
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/SRGSSR/pillarbox-android/dependency-graph/sbom \
--jq '.sbom.packages | reduce .[] as { $name, $versionInfo } ( {}; .[ $name | capture("(?<packageManager>[a-zA-Z.]+)[:/]").packageManager ][ $name | sub("[a-zA-Z.]+:(?<package>.*)"; "\(.package)") ] = $versionInfo )' \
| gomplate -d dependencies=stdin:///in.json -f techRadar/used_dependencies.tmpl -o public/techRadar/used_dependencies.md
run: ./.github/workflows/techRadar/update_used_dependencies.sh

- name: Commit the list of changes
run: |
Expand Down
Loading

0 comments on commit 48f8ce6

Please sign in to comment.