From 42af4015f216f3e6b785b41c09fb476e04a6b2eb Mon Sep 17 00:00:00 2001 From: Alex Cohen Date: Thu, 30 Jan 2025 13:41:19 -0500 Subject: [PATCH 1/3] fix temp cleanup --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c29a86f..6240e16 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23.3 require ( github.com/Checkmarx/containers-images-extractor v1.0.3 - github.com/Checkmarx/containers-syft-packages-extractor v1.0.5 + github.com/Checkmarx/containers-syft-packages-extractor v1.0.6-0.20250130183701-3874a3497983 github.com/Checkmarx/containers-types v1.0.0 github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index 2b57451..ed0d27b 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Checkmarx/containers-images-extractor v1.0.3 h1:v/F9PxR0YxVHY5I3mizgpBhARQXKFVwDsNz/d8AKQow= github.com/Checkmarx/containers-images-extractor v1.0.3/go.mod h1:cHtEnS5wlG7bTImOkhTjyZQ9mRurNLWPbnVqmQl94dk= -github.com/Checkmarx/containers-syft-packages-extractor v1.0.5 h1:wFrO/bx+tyldwnCQEujoHd1WyVzeJJkVovCBhIq4h5s= -github.com/Checkmarx/containers-syft-packages-extractor v1.0.5/go.mod h1:a2Qdlu/FAhptH8u+flWUAodc15JSeQFvIshs9RmIRJU= +github.com/Checkmarx/containers-syft-packages-extractor v1.0.6-0.20250130183701-3874a3497983 h1:jPFfsFsfCx9NPKTskVkzW1XZCkE9ISSpJ4Dd+hddKgM= +github.com/Checkmarx/containers-syft-packages-extractor v1.0.6-0.20250130183701-3874a3497983/go.mod h1:cYpRbQpG/7zSC+NCnKbm3omFpP2dNJ4FFUwVPJmrtsU= github.com/Checkmarx/containers-types v1.0.0 h1:H3bAbFnb4GqrAuYww63Ts1S3XmiLt+m8aqLuL/D9pz8= github.com/Checkmarx/containers-types v1.0.0/go.mod h1:yp956K0amnEYogUnVOjuVTe1euNr/0qkgB+NhaqW4M8= github.com/CycloneDX/cyclonedx-go v0.9.2 h1:688QHn2X/5nRezKe2ueIVCt+NRqf7fl3AVQk+vaFcIo= From aa0cd28524a3a8e03057595bb9d2a2a510852170 Mon Sep 17 00:00:00 2001 From: Alex Cohen Date: Fri, 31 Jan 2025 11:17:22 -0500 Subject: [PATCH 2/3] Add workflows --- .github/workflows/ci.yml | 36 +++++++++++++++++++++ .github/workflows/release.yml | 60 +++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e25f8b8 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: Checkmarx One CLI + +on: + pull_request: + +jobs: + unit-tests: + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Set up Go version + uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 + with: + go-version-file: "go.mod" + + - run: go version + + - name: go test with coverage + run: | + go run gotest.tools/gotestsum@latest --format testdox -- -coverprofile=cover.out ./pkg/containerResolver... + + - name: Check if total coverage is greater then 80 + shell: bash + run: | + CODE_COV=$(go tool cover -func cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}') + EXPECTED_CODE_COV=80 + var=$(awk 'BEGIN{ print "'$CODE_COV'"<"'$EXPECTED_CODE_COV'" }') + if [ "$var" -eq 1 ];then + echo "Your code coverage is too low. Coverage precentage is: $CODE_COV" + exit 1 + else + echo "Your code coverage test passed! Coverage precentage is: $CODE_COV" + exit 0 + fi \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..90334a4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: Release Containers resolver Go module new version + +on: + pull_request: + types: + - closed + branches: + - main + +jobs: + tag-and-release: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Get and Format the PR Title + id: get_pr_title + run: | + pr_title="${{ github.event.pull_request.title }}" + # Use grep with regex to extract the format (AST-000) from the title + formatted_title=$(echo "$pr_title" | grep -oE "\(AST-[0-9]+\)") + # If formatted_title is empty, set a default value or handle the error + if [ -z "$formatted_title" ]; then + echo "No valid format found in PR title." + exit 1 + fi + echo "formatted_title=$formatted_title" >> $GITHUB_ENV + + - name: Fetch All Tags + run: git fetch --tags + + - name: Get Latest Tag + id: get_tag + run: | + latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) + echo "tag=${latest_tag}" >> $GITHUB_ENV + + - name: Bump Patch Version + id: bump + uses: cbrgm/semver-bump-action@v1.0.30 + with: + current-version: ${{ env.tag }} + bump-level: patch + + - name: Create a new tag + run: | + new_tag=${{ steps.bump.outputs.new_version }} + git tag $new_tag -m "${{ env.formatted_title }}" + git push origin $new_tag + + - name: Create release from tag + uses: actions/create-release@v1 + with: + tag_name: ${{ steps.bump.outputs.new_version }} + release_name: Release ${{ steps.bump.outputs.new_version }} + body: ${{ steps.get_pr_title.outputs.pr_title }} + draft: false + prerelease: false \ No newline at end of file From ba2ae9f5a870eb0a1d477fd8aec7d974775c8742 Mon Sep 17 00:00:00 2001 From: Alex Cohen Date: Fri, 31 Jan 2025 11:23:23 -0500 Subject: [PATCH 3/3] Add workflows --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e25f8b8..a6f4e4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Checkmarx One CLI +name: Checkmarx One Containers-Resolver on: pull_request: @@ -21,11 +21,11 @@ jobs: run: | go run gotest.tools/gotestsum@latest --format testdox -- -coverprofile=cover.out ./pkg/containerResolver... - - name: Check if total coverage is greater then 80 + - name: Check if total coverage is greater then 70 shell: bash run: | CODE_COV=$(go tool cover -func cover.out | grep total | awk '{print substr($3, 1, length($3)-1)}') - EXPECTED_CODE_COV=80 + EXPECTED_CODE_COV=70 var=$(awk 'BEGIN{ print "'$CODE_COV'"<"'$EXPECTED_CODE_COV'" }') if [ "$var" -eq 1 ];then echo "Your code coverage is too low. Coverage precentage is: $CODE_COV"