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

newrelic-java-examples Scala example #44

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5169af6
Add basic fossa workflow
elaguerta-nr Oct 31, 2023
f3b1066
Merge pull request #1 from newrelic-csec/add-fossa-workflow
elaguerta-nr Oct 31, 2023
02e6d0c
fixup: move fossa workflow into .github/workflows
elaguerta-nr Oct 31, 2023
4bd1324
Merge pull request #2 from newrelic-csec/add-fossa-workflow
elaguerta-nr Oct 31, 2023
c12ccee
Delete .github/fossa.yml
elaguerta-nr Nov 1, 2023
10154ef
Check for fossa targets before running fossa analyze
elaguerta-nr Nov 1, 2023
80ff431
Fixup: capture output as text
elaguerta-nr Nov 1, 2023
433e611
Try adding checkout action as context
elaguerta-nr Nov 1, 2023
3b784d3
Add fossa analyze step
elaguerta-nr Nov 1, 2023
49dae3e
Try setting zeroFossaTargets property if no targets found
elaguerta-nr Nov 2, 2023
0a9a823
Fixup: indentation
elaguerta-nr Nov 2, 2023
fe24cf5
If targets found, remove zeroFossaTargets custom property
elaguerta-nr Nov 2, 2023
7ac770e
Try adding write-all permissions
elaguerta-nr Nov 2, 2023
2b1f819
Revert "Try adding write-all permissions"
elaguerta-nr Nov 2, 2023
566d838
Try using a PAT
elaguerta-nr Nov 2, 2023
f98fd24
Specify a PAT with org-admin access for updating custom properties
elaguerta-nr Nov 2, 2023
a94d81f
Fixup: Use environment variables to save context vars
elaguerta-nr Nov 2, 2023
899ebf1
Fixup: double quotes to expand env variables
elaguerta-nr Nov 2, 2023
2f3e0e2
debug: echo json data
elaguerta-nr Nov 2, 2023
7417551
Fixup: remove owner from repo var
elaguerta-nr Nov 2, 2023
abe7654
Consolidate curl call to update custom property
elaguerta-nr Nov 2, 2023
b310dbc
Feat: check for errors from fossa list-targets
elaguerta-nr Nov 3, 2023
781cd99
fixup: extra spaces
elaguerta-nr Nov 3, 2023
90b7456
Update fossa.yml
elaguerta-nr Nov 7, 2023
3c32b3c
Fixup: try running list-targets with set -e
elaguerta-nr Nov 7, 2023
0a43319
Fixups: error handling and logging
elaguerta-nr Nov 7, 2023
55b4895
try removing set -e
elaguerta-nr Nov 7, 2023
3110679
Log list targets output
elaguerta-nr Nov 7, 2023
0597c54
Check for "error" in list-targets
elaguerta-nr Nov 7, 2023
b98f4d8
Add exit 1 condition if list-targets errored
elaguerta-nr Nov 7, 2023
9908364
Add logic for flagging on fossa analyze
elaguerta-nr Nov 7, 2023
6e741ed
Try adding a curl before running fossa analyze
elaguerta-nr Nov 7, 2023
681f687
Fixup: close if statement
elaguerta-nr Nov 7, 2023
cd86fe7
Add policy flag to fossa analyze
elaguerta-nr Nov 7, 2023
bc1857e
Update fossa.yml
elaguerta-nr Nov 13, 2023
a1b8500
Fixup: variable syntax
elaguerta-nr Nov 13, 2023
179a007
Fixup: missing closing quote
elaguerta-nr Nov 13, 2023
547fc79
Separate fossa analyze stdout and stderr into 2 tmp files
elaguerta-nr Nov 13, 2023
841875e
Create fossa-scala.yml
elaguerta-nr Nov 13, 2023
5bd6254
Fixup: typo
elaguerta-nr Nov 13, 2023
643d502
Setup github action according to scala-sbt docs
elaguerta-nr Nov 14, 2023
3a734a6
Revert step to use JDK
elaguerta-nr Nov 14, 2023
5d5d130
Download newrelic.jar, for newrelic-java-examples
elaguerta-nr Nov 14, 2023
a966403
fixup: use owner/repo to identify github.repository
elaguerta-nr Nov 14, 2023
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
87 changes: 87 additions & 0 deletions .github/workflows/fossa-scala.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: FOSSA CLI Analysis - Scala
on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
workflow_dispatch:

jobs:
fossa:
runs-on: ubuntu-latest
env:
FOSSA_API_KEY: ${{secrets.FOSSA_API_KEY}}
ORG: ${{ github.repository_owner }}
REPO: ${{ github.repository }}
ORG_ADMIN_PAT: ${{ secrets.ELAGUERTA_PAT }}

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3
- name: Download newrelic.jar
if: ${{ github.repository == 'newrelic-csec/newrelic-java-examples' }}
run: |
mkdir newrelic-java-agent/scala/segment-api-synchronous/libs
curl https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic.jar --output newrelic-java-agent/scala/segment-api-synchronous/libs/newrelic.jar
- id: fossa-list-targets
name: Run fossa list-targets
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
export LIST_TARGETS_OUT_FILE=${{ runner.temp }}/list-targets_out.txt
export LIST_TARGETS_ERR_FILE=${{ runner.temp }}/list-targets_err.txt

fossa list-targets --format text 1>$LIST_TARGETS_OUT_FILE 2>$LIST_TARGETS_ERR_FILE

if [[ $(grep -i "error" $LIST_TARGETS_ERR_FILE | wc -l) -gt 0 ]]
then
echo "::error::fossa list-targets ran with errors."
cat $LIST_TARGETS_ERR_FILE
echo "HAS_FOSSA_TARGETS=Error" >> "$GITHUB_OUTPUT"
elif [[ $(cat $LIST_TARGETS_OUT_FILE | wc -l) -gt 0 ]]
then
echo "::notice::Fossa found analysis targets."
cat $LIST_TARGETS_OUT_FILE
echo "HAS_FOSSA_TARGETS=True" >> "$GITHUB_OUTPUT"
else
echo "::warning::Fossa did not find any analysis targets."
echo "HAS_FOSSA_TARGETS=False" >> "$GITHUB_OUTPUT"
fi
- name: Set hasFossaTargets custom property
run: |
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ORG_ADMIN_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"hasFossaTargets","value":"'"${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS }}"'"}]}'
- id: fossa-analyze
name: Run fossa analyze
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'True'}}
run: |
export ANALYZE_OUT_FILE=${{ runner.temp }}/analyze_out.txt
export ANALZYE_ERR_FILE=${{ runner.temp }}/analyze_err.txt
fossa analyze --policy='New Relic Public Github' 1>$ANALYZE_OUT_FILE 2>$ANALZYE_ERR_FILE
if [[ $(grep -i "error" $ANALYZE_ERR_FILE | wc -l) -gt 0 ]]
then
echo "::error::fossa analyze ran with errors."
cat $ANALYZE_ERR_FILE
echo "FOSSA_ANALYZE_RESULT=Error" >> "$GITHUB_OUTPUT"
else
cat $ANALYZE_OUT_FILE
echo "FOSSA_ANALYZE_RESULT=Success" >> "$GITHUB_OUTPUT"
fi
- name: Set fossaAnalyzeResult custom property
run: |
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ORG_ADMIN_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaAnalyzeResult","value":"'"${{ steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT }}"'"}]}'
- name: Exit
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'Error' || steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT == 'Error' }}
run: exit 1
83 changes: 83 additions & 0 deletions .github/workflows/fossa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: FOSSA CLI Analysis
on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
workflow_dispatch:

jobs:
fossa:
runs-on: ubuntu-latest
env:
FOSSA_API_KEY: ${{secrets.FOSSA_API_KEY}}
ORG: ${{ github.repository_owner }}
REPO: ${{ github.repository }}
ORG_ADMIN_PAT: ${{ secrets.ELAGUERTA_PAT }}

strategy:
fail-fast: false

steps:
- uses: actions/checkout@v3
- id: fossa-list-targets
name: Run fossa list-targets
run: |
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash
export LIST_TARGETS_OUT_FILE=${{ runner.temp }}/list-targets_out.txt
export LIST_TARGETS_ERR_FILE=${{ runner.temp }}/list-targets_err.txt

fossa list-targets --format text 1>$LIST_TARGETS_OUT_FILE 2>$LIST_TARGETS_ERR_FILE

if [[ $(grep -i "error" $LIST_TARGETS_ERR_FILE | wc -l) -gt 0 ]]
then
echo "::error::fossa list-targets ran with errors."
cat $LIST_TARGETS_ERR_FILE
echo "HAS_FOSSA_TARGETS=Error" >> "$GITHUB_OUTPUT"
elif [[ $(cat $LIST_TARGETS_OUT_FILE | wc -l) -gt 0 ]]
then
echo "::notice::Fossa found analysis targets."
cat $LIST_TARGETS_OUT_FILE
echo "HAS_FOSSA_TARGETS=True" >> "$GITHUB_OUTPUT"
else
echo "::warning::Fossa did not find any analysis targets."
echo "HAS_FOSSA_TARGETS=False" >> "$GITHUB_OUTPUT"
fi
- name: Set hasFossaTargets custom property
run: |
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ORG_ADMIN_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"hasFossaTargets","value":"'"${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS }}"'"}]}'
- id: fossa-analyze
name: Run fossa analyze
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'True'}}
run: |
export ANALYZE_OUT_FILE=${{ runner.temp }}/analyze_out.txt
export ANALZYE_ERR_FILE=${{ runner.temp }}/analyze_err.txt
fossa analyze --policy='New Relic Public Github' 1>$ANALYZE_OUT_FILE 2>$ANALZYE_ERR_FILE
if [[ $(grep -i "error" $ANALYZE_ERR_FILE | wc -l) -gt 0 ]]
then
echo "::error::fossa analyze ran with errors."
cat $ANALYZE_ERR_FILE
echo "FOSSA_ANALYZE_RESULT=Error" >> "$GITHUB_OUTPUT"
else
cat $ANALYZE_OUT_FILE
echo "FOSSA_ANALYZE_RESULT=Success" >> "$GITHUB_OUTPUT"
fi
- name: Set fossaAnalyzeResult custom property
run: |
curl -L \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $ORG_ADMIN_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaAnalyzeResult","value":"'"${{ steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT }}"'"}]}'
- name: Exit
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'Error' || steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT == 'Error' }}
run: exit 1

Loading