Skip to content

Commit b31d626

Browse files
authored
Merge pull request #10 from spectrocloud-labs/chore-add-release-test
chore: add github workflows
2 parents 04d2fcf + be53017 commit b31d626

File tree

2 files changed

+195
-0
lines changed

2 files changed

+195
-0
lines changed

.github/workflows/release.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- '[0-9]+.[0-9]+.x'
8+
workflow_dispatch:
9+
10+
env:
11+
REGISTRY: quay.io
12+
GITHUB_PAGES_BRANCH: gh_pages
13+
14+
defaults:
15+
run:
16+
shell: bash
17+
18+
jobs:
19+
release-please:
20+
permissions:
21+
contents: write # for google-github-actions/release-please-action to create release commit
22+
pull-requests: write # for google-github-actions/release-please-action to create release PR
23+
runs-on: [self-hosted, Linux, X64, validator]
24+
outputs:
25+
releases_created: ${{ steps.release.outputs.releases_created }}
26+
tag_name: ${{ steps.release.outputs.tag_name }}
27+
# Release-please creates a PR that tracks all changes
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
31+
32+
- uses: google-github-actions/release-please-action@a37ac6e4f6449ce8b3f7607e4d97d0146028dc0b # v4
33+
id: release
34+
with:
35+
command: manifest
36+
token: ${{secrets.PAT}}
37+
default-branch: main
38+
39+
release-charts:
40+
needs: release-please
41+
permissions:
42+
contents: write
43+
runs-on: [self-hosted, Linux, X64, validator]
44+
if: needs.release-please.outputs.releases_created == 'true'
45+
steps:
46+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
47+
- name: Publish Helm chart
48+
uses: stefanprodan/helm-gh-pages@master
49+
with:
50+
token: ${{ secrets.PAT }}
51+
charts_dir: chart
52+
owner: spectrocloud-labs
53+
branch: ${{ env.GITHUB_PAGES_BRANCH }}
54+
commit_username: spectrocloud-labs-bot
55+
commit_email: [email protected]
56+
57+
build-container:
58+
if: needs.release-please.outputs.releases_created == 'true'
59+
needs:
60+
- release-please
61+
runs-on: [self-hosted, Linux, X64, validator]
62+
permissions:
63+
contents: write
64+
packages: write
65+
id-token: write
66+
env:
67+
IMAGE_TAG: quay.io/spectrocloud-labs/validator-plugin-kubescape:${{ needs.release-please.outputs.tag_name }}
68+
IMAGE_NAME: validator-plugin-kubescape
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
72+
with:
73+
submodules: recursive
74+
75+
- name: Set up Docker Buildx
76+
id: buildx
77+
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3
78+
79+
- name: Login to GitHub Container Registry
80+
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
81+
with:
82+
registry: "quay.io"
83+
username: tgillson
84+
password: ${{ secrets.QUAY_TOKEN }}
85+
86+
- name: Build Docker Image
87+
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5
88+
with:
89+
context: .
90+
file: ./Dockerfile
91+
platforms: linux/amd64,linux/arm64
92+
target: production
93+
tags: |
94+
${{ env.IMAGE_TAG }}
95+
builder: ${{ steps.buildx.outputs.name }}
96+
push: true
97+
cache-from: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_TAG }}
98+
cache-to: type=gha,scope=${{ github.ref_name }}-${{ env.IMAGE_TAG }}
99+
100+
- name: Generate SBOM
101+
uses: anchore/sbom-action@9fece9e20048ca9590af301449208b2b8861333b # v0.15.9
102+
with:
103+
image: ${{ env.IMAGE_TAG }}
104+
artifact-name: sbom-${{ env.IMAGE_NAME }}
105+
output-file: ./sbom-${{ env.IMAGE_NAME }}.spdx.json
106+
107+
- name: Attach SBOM to release
108+
uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2
109+
with:
110+
tag_name: ${{ needs.release-please.outputs.tag_name }}
111+
files: ./sbom-${{ env.IMAGE_NAME }}.spdx.json

.github/workflows/test.yaml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: test-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
test-unit:
16+
name: Run Unit Tests
17+
runs-on: [self-hosted, Linux, X64, validator]
18+
steps:
19+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
23+
with:
24+
go-version-file: go.mod
25+
26+
- name: Test
27+
run: make test
28+
29+
- name: Workaround for https://github.com/codecov/feedback/issues/263
30+
run: |
31+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
32+
33+
- name: Codecov
34+
uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4
35+
with:
36+
file: ./cover.out
37+
fail_ci_if_error: true
38+
token: ${{ secrets.CODECOV_TOKEN }}
39+
40+
test-chart:
41+
name: Run Helm Chart Tests
42+
runs-on: [self-hosted, Linux, X64, validator]
43+
if: "!(contains(github.head_ref, 'release-please') || contains(github.ref, 'release-please'))"
44+
steps:
45+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
46+
with:
47+
fetch-depth: 0
48+
49+
- name: Set up Helm
50+
uses: azure/setup-helm@b7246b12e77f7134dc2d460a3d5bad15bbe29390 # v4
51+
with:
52+
version: v3.11.2
53+
54+
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
55+
with:
56+
python-version: '3.9'
57+
check-latest: true
58+
59+
- name: Set up chart-testing
60+
uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992 # v2.6.1
61+
62+
- name: Run chart-testing (list-changed)
63+
id: list-changed
64+
run: |
65+
set -ex
66+
changed=$(ct list-changed --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }})
67+
echo $changed
68+
if [[ -n "$changed" ]]; then
69+
echo "changed=true" >> "$GITHUB_OUTPUT"
70+
fi
71+
72+
- name: Run chart-testing (lint)
73+
if: steps.list-changed.outputs.changed == 'true'
74+
run: |
75+
cd $GITHUB_WORKSPACE
76+
ct lint --validate-maintainers=false --check-version-increment=false --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }}
77+
78+
- name: Create kind cluster
79+
if: steps.list-changed.outputs.changed == 'true'
80+
uses: helm/kind-action@99576bfa6ddf9a8e612d83b513da5a75875caced # v1.9.0
81+
82+
- name: Run chart-testing (install)
83+
if: steps.list-changed.outputs.changed == 'true'
84+
run: ct install --chart-dirs chart --target-branch ${{ github.event.repository.default_branch }}

0 commit comments

Comments
 (0)