Skip to content

fix(deletion): rework deletion handling and reflect phases properly (… #88

fix(deletion): rework deletion handling and reflect phases properly (…

fix(deletion): rework deletion handling and reflect phases properly (… #88

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@df4cb1c069e1874edd31b4311f1884172cec0e10
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
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@82606bf257cbaff209d206a39f5134f0cfbfd2ee
with:
version: ${{ env.GOLANGCI_VERSION }}
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
- name: Set up Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
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@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
fetch-depth: 0 # Fetch all history for proper tagging
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5
- 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@650006c6eb7dba73a995cc03b0b2d7f5ca915bee
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@f9f3042f7e2789586610d6e8b85c8f03e5195baf
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'