Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submit dependency report to github #22

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions .github/workflows/dependencyReport.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Submit dependencies
on: push
on:
push:
branches:
- main
permissions:
contents: write
jobs:
library:
runs-on: ubuntu-22.04
Expand All @@ -10,5 +15,23 @@ jobs:
distribution: temurin
java-version: 17
cache: gradle
- run: .scripts/dependency_report_generate.sh -m library -c allSourceSetsCompileDependenciesMetadata -o dependencies_library_raw
- run: echo "SCANNED_AT=$(TZ=UTC date +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
- run: .scripts/dependency_report_generate.sh -m library -c allSourceSetsCompileDependenciesMetadata > dependencies_library_raw
- run: .scripts/github/dependency_report_as_github_json.sh -i dependencies_library_raw -n library -s $(TZ=UTC date +"%Y-%m-%dT%H:%M:%SZ") > dependencies_library.github.json
- run: |
echo RESPONSE_CODE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/$GITHUB_REPOSITORY/dependency-graph/snapshots \
--data-binary "@dependencies_library.github.json" \
-o /dev/null \
-w '%{http_code}') >> $GITHUB_ENV
- run: |
if [[ "$RESPONSE_CODE" == "201" ]];
then
exit 0
else
echo "Dependency submission failed with HTTP code $RESPONSE_CODE"
exit 1
fi
17 changes: 12 additions & 5 deletions .scripts/dependency_report_generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ mkdir -p $DIR_TMP

print_usage()
{
echo "Usage: $0 -m <module> -c <configuration> -o <output_file>"
echo "Usage: $0 -m <module> -c <configuration>"
}

while getopts ":m:c:o:" OPT; do
while getopts ":m:c:" OPT; do
case $OPT in
m) MODULE="$OPTARG"
;;
c) CONFIGURATION="$OPTARG"
;;
o) FILE_OUTPUT="$OPTARG"
;;
?) print_usage
exit 1
;;
esac
done
if [ -z "${MODULE+x}" ]; then
print_usage
exit 1
fi
if [ -z "${CONFIGURATION+x}" ]; then
print_usage
exit 1
fi


read -r -d '' -a WITH_ADJUSTED < <(./gradlew --console=plain "$MODULE":dependencies --configuration "$CONFIGURATION" | grep --color=never -o "\S*:.*:.*" | grep --color=never -v "/" | awk 'NR > 1' | tr -d " (*)" && printf '\0' )

Expand All @@ -41,4 +48,4 @@ for DEPENDENCY in "${RESOLVED[@]}"
do
echo "$DEPENDENCY" >> $FILE_TMP
done
sort -u $FILE_TMP > "$FILE_OUTPUT"
sort -u $FILE_TMP
82 changes: 82 additions & 0 deletions .scripts/github/dependency_report_as_github_json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
set -e

DIR_TMP="build/report_dependencies_github_json"
rm -rf $DIR_TMP || true
mkdir -p $DIR_TMP

print_usage()
{
echo "Usage: $0 -i <input_file> -n <manifest_name> -s <scanned_at>"
}

while getopts ":i:n:s:" OPT; do
case $OPT in
i) INPUT_FILE="$OPTARG"
;;
n) MANIFEST_NAME="$OPTARG"
;;
s) SCANNED_AT="$OPTARG"
;;
?) print_usage
exit 1
;;
esac
done
if [ -z "${INPUT_FILE+x}" ]; then
print_usage
exit 1
fi
if [ -z "${MANIFEST_NAME+x}" ]; then
print_usage
exit 1
fi
if [ -z "${SCANNED_AT+x}" ]; then
print_usage
exit 1
fi

JSON=$(jq --null-input \
--argjson VERSION 1 \
--arg SHA "$GITHUB_SHA" \
--arg REF "$GITHUB_REF" \
--arg CORRELATOR "$GITHUB_WORKFLOW"_"$GITHUB_JOB" \
--arg RUN_ID "$GITHUB_RUN_ID" \
--arg HTML_URL "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" \
--arg DETECTOR_NAME "$GITHUB_REPOSITORY" \
--arg DETECTOR_VERSION 1 \
--arg DETECTOR_URL "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \
--arg SCANNED "$SCANNED_AT" \
--arg MANIFEST_NAME "$MANIFEST_NAME" \
'
{
"version":$VERSION,
"sha":$SHA,
"ref":$REF,
"job":{
"correlator":$CORRELATOR,
"id":$RUN_ID,
"html_url":$HTML_URL
},
"detector":{
"name":$DETECTOR_NAME,
"version":$DETECTOR_VERSION,
"url":$DETECTOR_URL
},
"scanned":$SCANNED,
"manifests":{
($MANIFEST_NAME):{
"name":$MANIFEST_NAME,
"resolved":{
}
}
}
}
')

for LINE in $(cat $INPUT_FILE)
do
JSON=$(jq '.manifests.'$MANIFEST_NAME'.resolved += {"'$LINE'": {}}' <<< $JSON)
done

jq -r tostring <<< $JSON
Loading