diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml new file mode 100644 index 00000000..cb2931d4 --- /dev/null +++ b/.github/workflows/build-and-push.yaml @@ -0,0 +1,138 @@ +name: Build and Push + +on: + workflow_call: + +env: + REGISTRY_IMAGE: ghcr.io/${{ github.repository }} + +permissions: + packages: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + platform: + - linux/amd64 + - linux/arm64 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Prepare + run: | + platform=${{ matrix.platform }} + echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV + + - name: Get Build timestamp and branch name + run: | + echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV + echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV + + - name: Docker tags & labels + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + # generate Docker tags: + # - type=raw,VERSION -> branch name + # - type=ref,event=tag -> tag name + # - type=sha,format=long,prefix= -> commit sha + tags: | + type=raw,${{ env.VERSION }} + type=ref,event=tag + type=sha,format=long,prefix= + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push by digest + id: build + uses: docker/build-push-action@v6 + with: + platforms: ${{ matrix.platform }} + build-args: | + VERSION=${{ env.VERSION }} + BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} + COMMIT_HASH=${{ github.sha }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v4 + with: + name: digests-${{ env.PLATFORM_PAIR }} + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + runs-on: ubuntu-latest + needs: + - build + steps: + - name: Download digests + uses: actions/download-artifact@v4 + with: + path: /tmp/digests + pattern: digests-* + merge-multiple: true + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Get branch name + run: | + echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV + + - name: Docker tags & labels + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_IMAGE }} + # generate Docker tags: + # - type=raw,VERSION -> branch name + # - type=ref,event=tag -> tag name + # - type=sha,format=long,prefix= -> commit sha + tags: | + type=raw,${{ env.VERSION }} + type=ref,event=tag + type=sha,format=long,prefix= + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) + + - name: Inspect image + run: | + docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..18017e9a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,77 @@ +name: Continuous Integration + +on: + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + packages: write + id-token: write # Required for Codecov + +env: + GO_VERSION: 1.22 + +jobs: + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Cache envtest binaries + uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4 + with: + path: ./bin/ + key: binaries + - name: Setup Golang + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 + with: + go-version: "${{ env.GO_VERSION }}" + - name: Install envtest + run: make envtest + - name: Setup envtest + run: ./bin/setup-envtest use + - name: Run tests + run: make test + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@b9fd7d16f6d7d1b5d2bec1a2887e65ceed900238 # v4 + with: + use_oidc: true + + check-codegen: + name: Check Codegen + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Golang + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 + with: + go-version: "${{ env.GO_VERSION }}" + - name: Generate manifests + run: make manifests + - name: Check nothing has changed + run: | + git diff --exit-code ./manifests + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 + with: + go-version: "${{ env.GO_VERSION }}" + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6 + with: + version: v1.55 + args: --timeout=5m + + build-and-push: + uses: ./.github/workflows/build-and-push.yaml \ No newline at end of file diff --git a/.github/workflows/conventional-commits.yaml b/.github/workflows/conventional-commits.yaml index 5cecd488..a6e9d893 100644 --- a/.github/workflows/conventional-commits.yaml +++ b/.github/workflows/conventional-commits.yaml @@ -12,9 +12,7 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: 16 + - uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4 - name: commitlint (install) run: | npm install -g @commitlint/cli @commitlint/config-conventional diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 9ef13c2e..d774a967 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5 with: python-version: 3.x - - uses: actions/cache@v3 + - uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4 with: key: mkdocs-material-${{ github.sha }} path: .cache diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 678b40ea..00000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,123 +0,0 @@ -name: Main Continuous Integration - -on: - push: - branches: - - main - -permissions: - packages: write - -env: - GO_VERSION: 1.22 - BUILD_PLATFORMS: linux/amd64,linux/arm64 - -jobs: - unit-tests: - name: Unit Tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cache envtest binaries - uses: actions/cache@v3 - with: - path: ./bin/ - key: binaries - - name: Setup Golang - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - - name: Install envtest - run: make envtest - - name: Setup envtest - run: ./bin/setup-envtest use - - name: Run tests - run: make test - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - - check-codegen: - name: Check Codegen - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Golang - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - - name: Generate manifests - run: make manifests - - name: Check nothing has changed - run: | - git diff --exit-code ./manifests - - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.55 - args: --timeout=5m - - build-and-push: - name: Build & Push - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Get Build timestamp and branch name - run: | - echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV - echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV - - - name: Docker tags & labels - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }} - # generate Docker tags: - # - type=raw,VERSION -> branch name - # - type=ref,event=tag -> tag name - # - type=sha,format=long,prefix= -> commit sha - tags: | - type=raw,${{ env.VERSION }} - type=ref,event=tag - type=sha,format=long,prefix= - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v4 - with: - push: true - provenance: false - platforms: ${{ env.BUILD_PLATFORMS }} - build-args: | - VERSION=${{ env.VERSION }} - BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} - COMMIT_HASH=${{ github.sha }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml deleted file mode 100644 index 987525d4..00000000 --- a/.github/workflows/pr.yaml +++ /dev/null @@ -1,119 +0,0 @@ -name: Pull Request Continuous Integration - -on: - pull_request: - branches: - - main - -env: - GO_VERSION: 1.22 - BUILD_PLATFORMS: linux/amd64,linux/arm64 - -jobs: - unit-tests: - name: Unit Tests - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Cache envtest binaries - uses: actions/cache@v3 - with: - path: ./bin/ - key: binaries - - name: Setup Golang - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - - name: Install envtest - run: make envtest - - name: Setup envtest - run: ./bin/setup-envtest use - - name: Run tests - run: make test - - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 - - check-codegen: - name: Check Codegen - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Golang - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - - name: Generate manifests - run: make manifests - - name: Check nothing has changed - run: | - git diff --exit-code ./manifests - - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 - with: - go-version: "${{ env.GO_VERSION }}" - cache: false - - name: golangci-lint - uses: golangci/golangci-lint-action@v3 - with: - version: v1.55 - args: --timeout=5m - - build-and-push: - name: Build & Push - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Get Build timestamp and branch name - run: | - echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV - echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV - - - name: Docker tags & labels - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }} - # generate Docker tags: - # - type=raw,VERSION -> branch name - # - type=ref,event=tag -> tag name - # - type=sha,format=long,prefix= -> commit sha - tags: | - type=raw,${{ env.VERSION }} - type=ref,event=tag - type=sha,format=long,prefix= - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v4 - with: - provenance: false - platforms: ${{ env.BUILD_PLATFORMS }} - build-args: | - VERSION=${{ env.VERSION }} - BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} - COMMIT_HASH=${{ github.sha }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ae1ed5eb..63670b5b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,7 +7,6 @@ on: env: GO_VERSION: 1.22 - BUILD_PLATFORMS: linux/amd64,linux/arm64 permissions: contents: write @@ -28,7 +27,7 @@ jobs: run: git fetch --force --tags - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 with: go-version: "${{ env.GO_VERSION }}" @@ -39,10 +38,10 @@ jobs: echo "COMMIT_HASH=${{ github.sha }}" >> $GITHUB_ENV - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 + uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6 with: distribution: goreleaser - version: latest + version: '~> v2' args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -77,55 +76,4 @@ jobs: push_options: --force build-and-push: - name: Build & Push - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Get Build timestamp and branch name - run: | - echo "BUILD_TIMESTAMP=$(date +'%s')" >> $GITHUB_ENV - echo "VERSION=$( echo ${{ github.head_ref || github.ref_name }} | tr '/' '-' )" >> $GITHUB_ENV - - - name: Docker tags & labels - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }} - # generate Docker tags: - # - type=raw,VERSION -> branch name - # - type=ref,event=tag -> tag name - # - type=sha,format=long,prefix= -> commit sha - tags: | - type=raw,${{ env.VERSION }} - type=ref,event=tag - type=sha,format=long,prefix= - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to GHCR - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v4 - with: - push: true - provenance: false - platforms: ${{ env.BUILD_PLATFORMS }} - build-args: | - VERSION=${{ env.VERSION }} - BUILD_TIMESTAMP=${{ env.BUILD_TIMESTAMP }} - COMMIT_HASH=${{ github.sha }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max + uses: ./.github/workflows/build-and-push.yaml \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 49e0c5a1..fba2a862 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,40 +1,41 @@ +version: 2 before: hooks: - - go mod tidy + - go mod tidy builds: -- env: - - CGO_ENABLED=0 - - PACKAGE=github.com/padok-team/burrito - ldflags: - - -X ${PACKAGE}/internal/version.Version=${VERSION} - - -X ${PACKAGE}/internal/version.CommitHash=${COMMIT_HASH} - - -X ${PACKAGE}/internal/version.BuildTimestamp=${BUILD_TIMESTAMP} - goos: - - linux - main: ./ - binary: burrito + - env: + - CGO_ENABLED=0 + - PACKAGE=github.com/padok-team/burrito + ldflags: + - -X ${PACKAGE}/internal/version.Version=${VERSION} + - -X ${PACKAGE}/internal/version.CommitHash=${COMMIT_HASH} + - -X ${PACKAGE}/internal/version.BuildTimestamp=${BUILD_TIMESTAMP} + goos: + - linux + main: ./ + binary: burrito checksum: - name_template: 'checksums.txt' + name_template: "checksums.txt" snapshot: - name_template: '{{ .Tag }}-next' + version_template: "{{ .Tag }}-next" changelog: sort: asc use: github groups: - - title: Features - regexp: "^.*(feat:|feat\\/|feat(\\([^\\)]*\\)):).*" - order: 0 - - title: 'Bug fixes' - regexp: "^.*(fix:|fix\\/|fix(\\([^\\)]*\\)):).*" - order: 1 - - title: Others - order: 999 + - title: Features + regexp: "^.*(feat:|feat\\/|feat(\\([^\\)]*\\)):).*" + order: 0 + - title: "Bug fixes" + regexp: "^.*(fix:|fix\\/|fix(\\([^\\)]*\\)):).*" + order: 1 + - title: Others + order: 999 filters: exclude: - - '^docs' - - '^test' - - '^style' - - '^refactor' - - '^build' - - '^ci' - - '^chore(release)' + - "^docs" + - "^test" + - "^style" + - "^refactor" + - "^build" + - "^ci" + - "^chore(release)" diff --git a/Dockerfile b/Dockerfile index 06580c7c..b9ce7f3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,7 @@ ENV VITE_API_BASE_URL=/api RUN yarn build # Build the manager binary -FROM docker.io/library/golang:1.22.8@sha256:d22ae61b07d6e977d941b8d402e9a15b0638bac0d3f05e59f48f0d4b912760ec as builder +FROM docker.io/library/golang:1.22.8@sha256:d22ae61b07d6e977d941b8d402e9a15b0638bac0d3f05e59f48f0d4b912760ec AS builder ARG TARGETOS ARG TARGETARCH ARG PACKAGE=github.com/padok-team/burrito