Skip to content

Basee2e (#122)

Basee2e (#122) #73

Workflow file for this run

name: CI
on:
push:
branches: [ main, master, feat/* ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master, develop ]
workflow_dispatch:
inputs:
push_image:
description: 'Push Docker image (for feat branches)'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
env:
# Common versions
GOLANGCI_VERSION: 'v2.4.0'
IMAGE_REGISTRY: bedag/storagegrid-operator
jobs:
lint:
name: Lint
permissions:
contents: read # for actions/checkout to fetch code
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: true
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: ${{ env.GOLANGCI_VERSION }}
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: true
- name: Download dependencies
run: go mod download
- name: Generate manifests and code
run: |
make manifests
make generate
- name: Run unit tests
run: make test
docker-build:
name: Docker Build and Push
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history for proper tagging
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image == 'true')
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata for Docker
id: meta
run: |
GIT_COMMIT=$(git rev-parse --short HEAD)
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g')
GIT_TAG=$(git describe --tags --exact-match 2>/dev/null || echo "")
TAGS="${{ env.IMAGE_REGISTRY }}:latest,${{ env.IMAGE_REGISTRY }}:${GIT_COMMIT}"
if [ -n "$GIT_TAG" ]; then
TAGS="${TAGS},${{ env.IMAGE_REGISTRY }}:${GIT_TAG}"
elif [ -n "$GIT_BRANCH" ]; then
TAGS="${TAGS},${{ env.IMAGE_REGISTRY }}:${GIT_BRANCH}"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "Docker tags: ${TAGS}"
- name: Determine if push is needed
id: should_push
run: |
if [ "${{ github.event_name }}" = "push" ] && ([ "${{ github.ref }}" = "refs/heads/main" ] || [[ "${{ github.ref }}" =~ ^refs/tags/ ]]); then
echo "push=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.push_image }}" = "true" ]; then
echo "push=true" >> $GITHUB_OUTPUT
else
echo "push=false" >> $GITHUB_OUTPUT
fi
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
file: ./Dockerfile
push: ${{ steps.should_push.outputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ env.IMAGE_REGISTRY }}:latest'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results.sarif'