CI #2896
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
- renovate/** | |
schedule: | |
- cron: '0 13 * * *' | |
jobs: | |
chart-lint: | |
name: Helm chart Lint | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 10 | |
strategy: | |
matrix: | |
kubernetes-version: ["v1.30.0", "v1.29.5", "v1.28.3", "v1.27.5", "v1.26.8"] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: helm/chart-testing-action@v2.6.1 | |
- name: Lint charts | |
run: ct --config .github/ct.yaml lint --debug | |
- name: Check for changed installable charts | |
id: list-changed | |
run: | | |
changed=$(ct --config .github/ct.yaml list-changed) | |
if [[ -n "$changed" ]]; then | |
echo "::set-output name=changed::true" | |
fi | |
- name: Run helm unit tests | |
if: steps.list-changed.outputs.changed == 'true' | |
run: | | |
helm plugin install https://github.com/helm-unittest/helm-unittest | |
for chart in $(ct --config .github/ct.yaml list-changed); do | |
if [ -d "$chart/tests/" ]; then | |
helm unittest $chart | |
else | |
echo "No unit tests found for $chart" | |
fi | |
done | |
- name: Setup Minikube | |
uses: manusa/actions-setup-minikube@v2.11.0 | |
if: steps.list-changed.outputs.changed == 'true' | |
with: | |
minikube version: v1.33.1 | |
kubernetes version: ${{ matrix.kubernetes-version }} | |
github token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/setup-go@v5 | |
if: steps.list-changed.outputs.changed == 'true' | |
with: | |
go-version-file: 'go.mod' | |
- name: Create image for chart testing | |
if: steps.list-changed.outputs.changed == 'true' | |
run: | | |
GOOS=linux GOARCH=amd64 make build # Set GOOS and GOARCH explicitly since Dockerfile expects them in the binary name | |
DOCKER_BUILDKIT=1 docker build -t e2e/newrelic-infra-operator:test . | |
minikube image load e2e/newrelic-infra-operator:test | |
kubectl create ns ct | |
- name: Test install charts | |
if: steps.list-changed.outputs.changed == 'true' | |
run: ct install --namespace ct --config .github/ct.yaml --debug | |
- name: Test upgrade charts | |
if: steps.list-changed.outputs.changed == 'true' | |
run: ct install --namespace ct --config .github/ct.yaml --debug --upgrade | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
strategy: | |
fail-fast: false | |
matrix: | |
goos: [ linux ] | |
goarch: [ amd64, arm64, arm ] | |
env: | |
GOOS: ${{ matrix.goos }} | |
GOARCH: ${{ matrix.goarch }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
# A cache entry is will be generated for `key`, and attempted to restore. | |
# If `key` is not found, any partial match for `restore-keys` will be attempted. | |
# Regardless of whether `key` was found or not, it will be created at the end of the run. | |
# With this mechanism, we ensure caches are cycled regularly. | |
- name: Go modules cache | |
uses: actions/cache@v4.0.2 | |
with: | |
path: ~/go/pkg/mod | |
key: gomod-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
gomod- | |
- name: Build cache | |
uses: actions/cache@v4.0.2 | |
with: | |
path: ~/.cache/go-build | |
key: gobuild-${{ matrix.goos }}-${{ matrix.goarch }}-${{ github.sha }} | |
restore-keys: | | |
gobuild-${{ matrix.goos }}-${{ matrix.goarch }} | |
- name: Build binary | |
run: make build | |
- name: Build Docker image | |
if: matrix.goos == 'linux' && matrix.goarch == 'amd64' | |
run: make image | |
- name: Run CI checks | |
if: matrix.goos == 'linux' && matrix.goarch == 'amd64' | |
run: make ci | |
integration: | |
name: Run integration and test-e2e tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Check out code into the Go module directory | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
id: go | |
- name: Go modules cache | |
uses: actions/cache@v4.0.2 | |
with: | |
path: ~/go/pkg/mod | |
key: gomod-${{ hashFiles('**/go.sum') }} | |
restore-keys: | | |
gomod- | |
- name: Build cache | |
uses: actions/cache@v4.0.2 | |
with: | |
path: ~/.cache/go-build | |
key: gobuild-linux-amd64-${{ github.sha }} | |
restore-keys: | | |
gobuild-linux-amd64 | |
- name: Install kind | |
run: go install sigs.k8s.io/kind@v0.11.1 | |
- name: Create k8s Kind Cluster | |
run: make kind-up | |
- name: Run tests | |
run: make test | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 | |
with: | |
fail_ci_if_error: false | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- name: Run integration tests | |
run: make test-integration | |
- name: Build Docker image | |
run: make image-push IMAGE_REPO=localhost:5000/newrelic-infra-operator | |
- name: Create Helm release | |
env: | |
KUBECONFIG: ./kubeconfig | |
run: | | |
helm install newrelic-infra-operator ./charts/newrelic-infra-operator \ | |
--dependency-update \ | |
--values ./values-dev.yaml \ | |
--set image.repository=localhost:5000/newrelic-infra-operator | |
- name: Run test-e2e tests | |
run: make test-e2e | |
static-analysis: | |
name: Static analysis and linting | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
- uses: newrelic/newrelic-infra-checkers@v1 | |
with: | |
golangci-lint-config: golangci-lint | |
# - name: Semgrep | |
# uses: returntocorp/semgrep-action@v1 | |
# with: | |
# auditOn: push | |
- name: golangci-lint | |
uses: golangci/golangci-lint-action@v6 | |
continue-on-error: ${{ github.event_name != 'pull_request' }} | |
with: | |
only-new-issues: true | |
args: --timeout 3m | |
codespell: | |
name: Codespell | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Codespell test | |
uses: codespell-project/actions-codespell@master | |
with: | |
check_filenames: true | |
check_hidden: true | |
skip: ./.git,go.sum | |
ignore_words_list: enver,NotIn |