Skip to content

Commit 1dfe145

Browse files
Updates coverity as instructed in mvn_01 (#37)
1 parent b498349 commit 1dfe145

1 file changed

Lines changed: 71 additions & 32 deletions

File tree

.github/workflows/coverity.yml

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,99 @@
1-
name: Coverity Scan
1+
name: Coverity
22

33
on: push
44

55
jobs:
66
verify:
77
name: Verify Code
88
runs-on: ubuntu-latest
9+
if: ${{ startsWith(github.repository, 'teragrep/') }}
910

1011
env:
1112
COVERITY: coverity_tool
1213

1314
steps:
14-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1516
with:
1617
fetch-depth: 0
1718

18-
- name: Set up JDK 11
19-
uses: actions/setup-java@v3
20-
with:
21-
java-version: '11'
22-
distribution: 'temurin'
23-
server-id: github
24-
settings-path: ${{ github.workspace }}
19+
- name: Install jq
20+
run: sudo apt-get update && sudo apt-get install jq
2521

2622
- name: Get version
27-
run: echo "RELEASE_VERSION=$(git describe --tags)" >> $GITHUB_ENV
23+
run: printf "RELEASE_VERSION=%q\n" "$(git describe --tags)" >> $GITHUB_ENV
24+
25+
- name: Setup Maven Central
26+
uses: actions/setup-java@v4
27+
with:
28+
java-version: 11
29+
distribution: 'adopt'
30+
31+
- name: Cache Local Maven Repository
32+
uses: actions/cache@v4
33+
with:
34+
path: ~/.m2/repository
35+
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
2836

29-
- name: Test run
30-
run: mvn -B -Drevision=${{ env.RELEASE_VERSION }} -Dsha1= -Dchangelist= verify -s ${{ github.workspace }}/settings.xml
31-
env:
32-
GITHUB_TOKEN: ${{ github.token }}
37+
- name: Download Coverity distribution md5sum for cache key
38+
run: wget https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_TOKEN }}&project_id=${{ vars.COVERITY_PROJECT_URL_ID }}&md5=1" -O coverity_tool.md5
3339

34-
- name: Cache Coverity
35-
id: cache_coverity
36-
uses: actions/cache@v2
40+
- name: Cache pull Coverity distribution, extracted
41+
id: cache-pull-coverity-distribution
42+
uses: actions/cache@v4
3743
with:
38-
path: ${{ env.COVERITY }}
39-
key: coverity
44+
path: ${{ runner.temp }}/${{ env.COVERITY }}
45+
key: ${{ runner.os }}-coverity-${{ hashFiles('coverity_tool.md5') }}
46+
47+
- name: Move coverity_tool.md5 file so it won't conflict with maven
48+
run: mv coverity_tool.md5 ${RUNNER_TEMP}/coverity_tool.md5
4049

41-
- name: Download Coverity
42-
if: steps.cache_coverity.outputs.cache-hit != 'true'
50+
- name: Download and extract Coverity distribution if cache-miss
51+
if: steps.cache-pull-coverity-distribution.outputs.cache-hit != 'true'
4352
run: |
44-
wget --quiet https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_TOKEN }}&project=dpf_02" -O ${{ env.COVERITY }}.tgz
45-
mkdir -p ${{ env.COVERITY }}
46-
tar zxvf ${{ env.COVERITY }}.tgz -C ${{ env.COVERITY }} --strip-components 1
53+
wget --quiet https://scan.coverity.com/download/linux64 --post-data "token=${{ secrets.COVERITY_TOKEN }}&project_id=${{ vars.COVERITY_PROJECT_URL_ID }}" -O ${RUNNER_TEMP}/${{ env.COVERITY }}.tgz
54+
mkdir -p ${RUNNER_TEMP}/${{ env.COVERITY }}
55+
tar zxf ${RUNNER_TEMP}/${{ env.COVERITY }}.tgz -C ${RUNNER_TEMP}/${{ env.COVERITY }} --strip-components 1
4756
4857
- name: Compile Coverity
4958
run: |
50-
${{ env.COVERITY }}/bin/cov-build --dir cov-int mvn -B -Drevision=${{ env.RELEASE_VERSION }} -Dsha1= -Dchangelist= clean compile -s ${{ github.workspace }}/settings.xml
51-
tar czvf dpf_02.tgz cov-int
59+
${RUNNER_TEMP}/${{ env.COVERITY }}/bin/cov-build --dir ${RUNNER_TEMP}/cov-int mvn -B -Drevision=${{ env.RELEASE_VERSION }} -Dsha1= -Dchangelist= -Dmaven.test.skip.exec=true clean verify
60+
cd ${RUNNER_TEMP} && tar czvf ${{ vars.COVERITY_PROJECT_URL_ID }}.tgz cov-int
61+
62+
- name: Wait for Coverity analysis slot
63+
run: |
64+
while true; do
65+
curl -X POST -d version=${{ env.RELEASE_VERSION }} -d description="automated upload" -d email=${{ secrets.COVERITY_EMAIL }} -d token=${{ secrets.COVERITY_TOKEN }} -d file_name="${{ vars.COVERITY_PROJECT_URL_ID }}.tgz" https://scan.coverity.com/projects/${{ vars.COVERITY_PROJECT_URL_ID }}/builds/init -o ${RUNNER_TEMP}/response;
66+
67+
if grep -q 'build submission quota' ${RUNNER_TEMP}/response; then
68+
cat ${RUNNER_TEMP}/response
69+
echo 'Giving up, submission quota met'
70+
exit 1
71+
fi;
72+
73+
if grep -q 'already in the queue' ${RUNNER_TEMP}/response; then
74+
cat ${RUNNER_TEMP}/response
75+
echo 'Waiting for 15 seconds and retrying'
76+
sleep 15
77+
else
78+
break
79+
fi
80+
done
81+
82+
- name: Prepare response url
83+
run: printf "RESPONSE_URL=%q\n" "$(jq -r '.url' ${RUNNER_TEMP}/response)" >> $GITHUB_ENV
5284

5385
- name: Upload to Coverity
5486
run: |
55-
curl --silent --form token=${{ secrets.COVERITY_TOKEN }} \
56-
--form email=${{ secrets.COVERITY_EMAIL }} \
57-
--form file=@dpf_02.tgz \
58-
--form version="${GITHUB_REF##*/}" \
59-
--form description="automated upload" \
60-
https://scan.coverity.com/builds?project=dpf_02
87+
curl -X PUT --header 'Content-Type: application/json' --upload-file ${RUNNER_TEMP}/${{ vars.COVERITY_PROJECT_URL_ID }}.tgz ${{ env.RESPONSE_URL }}
88+
89+
- name: Prepare build id
90+
run: printf "COVERITY_BUILD_ID=%q\n" "$(jq -r '.build_id' ${RUNNER_TEMP}/response)" >> $GITHUB_ENV
91+
92+
- name: Build Coverity Submit URL
93+
run: printf 'COVERITY_SUBMIT_URL=%q/%s/builds/%s/enqueue' "https://scan.coverity.com/projects" "${{ vars.COVERITY_PROJECT_URL_ID }}" "${{ env.COVERITY_BUILD_ID }}" >> $GITHUB_ENV
94+
95+
- name: Trigger Coverity analysis
96+
run: curl -X PUT -d token=${{ secrets.COVERITY_TOKEN }} ${{ env.COVERITY_SUBMIT_URL }}
97+
98+
- name: Restore coverity_tool.md5 file so caches can be generated
99+
run: mv ${RUNNER_TEMP}/coverity_tool.md5 coverity_tool.md5

0 commit comments

Comments
 (0)