Skip to content

Commit a7dd4d4

Browse files
authored
Don't continue to build container if no new version (#71)
1 parent f340074 commit a7dd4d4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

.github/workflows/sysdig-cli-scanner.yaml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,31 @@ jobs:
1919
contents: read
2020
steps:
2121
- name: Check the latest version
22+
id: check_version
2223
env:
2324
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24-
run: |
25+
run: |
2526
LATEST_VERSION=$(curl -sL https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt)
2627
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]')
2728
if [[ ${LATEST_VERSION} != ${IMAGE_TAG} ]]; then
2829
echo "Container versions differ, building ${LATEST_VERSION}"
2930
echo "IMAGE_TAG=${LATEST_VERSION}" >> ${GITHUB_ENV}
31+
echo "should_continue=true" >> $GITHUB_OUTPUT
3032
else
3133
echo "Container already using latest version"
32-
exit 0
34+
echo "should_continue=false" >> $GITHUB_OUTPUT
3335
fi
3436
3537
- name: Checkout
38+
if: steps.check_version.outputs.should_continue == 'true'
3639
uses: actions/checkout@v2
3740

3841
- name: Set up Docker Buildx
42+
if: steps.check_version.outputs.should_continue == 'true'
3943
uses: docker/setup-buildx-action@v2
4044

4145
- name: Build and save
46+
if: steps.check_version.outputs.should_continue == 'true'
4247
uses: docker/build-push-action@v3
4348
with:
4449
context: ${{ env.DOCKERFILE_CONTEXT }}
@@ -49,13 +54,15 @@ jobs:
4954
VERSION=${{ env.IMAGE_TAG }}
5055
5156
- name: Setup cache
57+
if: steps.check_version.outputs.should_continue == 'true'
5258
uses: actions/cache@v3
5359
with:
5460
path: cache
5561
key: ${{ runner.os }}-cache-${{ hashFiles('**/sysdig-cli-scanner', '**/latest_version.txt', '**/db/main.db.meta.json', '**/scanner-cache/inlineScannerCache.db') }}
5662
restore-keys: ${{ runner.os }}-cache-
5763

5864
- name: Download sysdig-cli-scanner if needed
65+
if: steps.check_version.outputs.should_continue == 'true'
5966
run: |
6067
curl -sLO https://download.sysdig.com/scanning/sysdig-cli-scanner/latest_version.txt
6168
mkdir -p ${GITHUB_WORKSPACE}/cache/db/
@@ -68,6 +75,7 @@ jobs:
6875
fi
6976
7077
- name: Scan the image using sysdig-cli-scanner
78+
if: steps.check_version.outputs.should_continue == 'true'
7179
env:
7280
SECURE_API_TOKEN: ${{ secrets.SECURE_API_TOKEN }}
7381
run: |
@@ -78,14 +86,16 @@ jobs:
7886
--dbpath=${GITHUB_WORKSPACE}/cache/db/ \
7987
--cachepath=${GITHUB_WORKSPACE}/cache/scanner-cache/ ||true
8088
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:
8493
registry: ${{ env.REGISTRY_HOST }}
8594
username: ${{ github.repository_owner }}
8695
password: ${{ secrets.GITHUB_TOKEN }}
8796

8897
- name: Push
98+
if: steps.check_version.outputs.should_continue == 'true'
8999
uses: docker/build-push-action@v3
90100
with:
91101
context: ${{ env.DOCKERFILE_CONTEXT }}

0 commit comments

Comments
 (0)