@@ -19,26 +19,31 @@ jobs:
19
19
contents : read
20
20
steps :
21
21
- name : Check the latest version
22
+ id : check_version
22
23
env :
23
24
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
24
- run : |
25
+ run : |
25
26
LATEST_VERSION=$(curl -sL https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
26
27
IMAGE_TAG=$(gh api -H "Accept: application/vnd.github+json" /orgs/sysdiglabs/packages/container/sysdig-cli-scanner/versions | jq -r 'sort_by(.created_at) | last | .metadata.container.tags[0]')
27
28
if [[ ${LATEST_VERSION} != ${IMAGE_TAG} ]]; then
28
29
echo "Container versions differ, building ${LATEST_VERSION}"
29
30
echo "IMAGE_TAG=${LATEST_VERSION}" >> ${GITHUB_ENV}
31
+ echo "should_continue=true" >> $GITHUB_OUTPUT
30
32
else
31
33
echo "Container already using latest version"
32
- exit 0
34
+ echo "should_continue=false" >> $GITHUB_OUTPUT
33
35
fi
34
36
35
37
- name : Checkout
38
+ if : steps.check_version.outputs.should_continue == 'true'
36
39
uses : actions/checkout@v2
37
40
38
41
- name : Set up Docker Buildx
42
+ if : steps.check_version.outputs.should_continue == 'true'
39
43
uses : docker/setup-buildx-action@v2
40
44
41
45
- name : Build and save
46
+ if : steps.check_version.outputs.should_continue == 'true'
42
47
uses : docker/build-push-action@v3
43
48
with :
44
49
context : ${{ env.DOCKERFILE_CONTEXT }}
@@ -49,13 +54,15 @@ jobs:
49
54
VERSION=${{ env.IMAGE_TAG }}
50
55
51
56
- name : Setup cache
57
+ if : steps.check_version.outputs.should_continue == 'true'
52
58
uses : actions/cache@v3
53
59
with :
54
60
path : cache
55
61
key : ${{ runner.os }}-cache-${{ hashFiles('**/sysdig-cli-scanner', '**/latest_version.txt', '**/db/main.db.meta.json', '**/scanner-cache/inlineScannerCache.db') }}
56
62
restore-keys : ${{ runner.os }}-cache-
57
63
58
64
- name : Download sysdig-cli-scanner if needed
65
+ if : steps.check_version.outputs.should_continue == 'true'
59
66
run : |
60
67
curl -sLO https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt
61
68
mkdir -p ${GITHUB_WORKSPACE}/cache/db/
68
75
fi
69
76
70
77
- name : Scan the image using sysdig-cli-scanner
78
+ if : steps.check_version.outputs.should_continue == 'true'
71
79
env :
72
80
SECURE_API_TOKEN : ${{ secrets.SECURE_API_TOKEN }}
73
81
run : |
@@ -78,14 +86,16 @@ jobs:
78
86
--dbpath=${GITHUB_WORKSPACE}/cache/db/ \
79
87
--cachepath=${GITHUB_WORKSPACE}/cache/scanner-cache/ ||true
80
88
81
- - name : Login to the registry
82
- uses : docker/login-action@v2
83
- with :
89
+ - name : Login to the registry
90
+ if : steps.check_version.outputs.should_continue == 'true'
91
+ uses : docker/login-action@v2
92
+ with :
84
93
registry : ${{ env.REGISTRY_HOST }}
85
94
username : ${{ github.repository_owner }}
86
95
password : ${{ secrets.GITHUB_TOKEN }}
87
96
88
97
- name : Push
98
+ if : steps.check_version.outputs.should_continue == 'true'
89
99
uses : docker/build-push-action@v3
90
100
with :
91
101
context : ${{ env.DOCKERFILE_CONTEXT }}
0 commit comments