From f2677ffa3e37b3f2ddf48d958c06f7da340cca9b Mon Sep 17 00:00:00 2001 From: lwpk110 Date: Fri, 29 Nov 2024 12:02:16 +0800 Subject: [PATCH 1/2] ci: refactor gh workflow --- .github/workflows/lint.yml | 41 +++++++++++ .github/workflows/main.yml | 120 -------------------------------- .github/workflows/publish.yml | 35 ++++++++++ .github/workflows/release.yml | 127 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 64 +++++++++++++++++ README.md | 2 +- 6 files changed, 268 insertions(+), 121 deletions(-) create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..90222cb --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,41 @@ +name: Lint + +on: + push: + branches: + - "main" + pull_request: + + +jobs: + markdown-lint: + name: Markdown Lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Run markdownlint + uses: DavidAnson/markdownlint-cli2-action@v18 + with: + globs: | + README.*.md + docs/*.md + + + golang-lint: + name: golang-lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Run linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f0a129d..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: main - -on: ['push', 'pull_request'] - -jobs: - markdown-lint: - name: Markdown Lint - runs-on: ubuntu-22.04 - steps: - - name: Checkout Code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Lint Code Base - uses: github/super-linter@v4 - env: - VALIDATE_MARKDOWN: true - VALIDATE_ALL_CODEBASE: false - DEFAULT_BRANCH: main - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - LINTER_RULES_PATH: / - MARKDOWN_CONFIG_FILE: .markdownlint.yml - - - golang-test: - name: Golang Test - runs-on: ubuntu-22.04 - strategy: - matrix: - go-version: ['1.23'] - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - uses: actions/checkout@v4 - - name: Setup Go ${{ matrix.go-version }} - uses: actions/setup-go@v4 - with: - go-version: ${{ matrix.go-version }} - - name: Display Go version - run: go version - - name: Install dependencies - run: go get ./... - - name: Test with Go - run: make test - - - golang-lint: - name: golang-lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: '1.23' - cache: false - - name: golangci-lint - run: | - make lint - - - chainsaw-test: - name: Chainsaw Test - runs-on: ubuntu-22.04 - strategy: - matrix: - k8s-version: ['1.26.14', '1.27.11'] - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 - with: - go-version: '1.23' - cache: false - - name: Create KinD clustet - env: - KINDTEST_K8S_VERSION: ${{ matrix.k8s-version}} - KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - run: make kind-create - - name: Chainsaw test setup - env: - KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} - KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - run: make chainsaw-setup - - name: Test with Chainsaw - env: - KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} - KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} - run: make chainsaw-test - - - deploy-operator: - name: Deploy operator - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository_owner == 'zncdatadev' }} - runs-on: ubuntu-22.04 - needs: - - golang-lint - - golang-test - - chainsaw-test - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 1 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - platforms: linux/amd64,linux/arm64 - - name: Login to quay.io - uses: docker/login-action@v2 - with: - registry: quay.io - username: ${{ secrets.QUAY_USERNAME }} - password: ${{ secrets.QUAY_PASSWORD }} - - name: Build and push operator - run: | - make docker-buildx diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..19a8df8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,35 @@ +name: Publish + +on: + push: + branches: + - main + + +jobs: + publish-image: + name: Publish Image + if: ${{ github.repository_owner == 'zncdatadev' }} + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: Login to quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Build and push operator + run: | + make docker-buildx diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..59e4e18 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,127 @@ +name: Release + +on: + push: + tags: + - '*' + + +env: + VERSION: ${{ github.ref_name }} + + +jobs: + markdown-lint: + name: Markdown Lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Run markdownlint + uses: DavidAnson/markdownlint-cli2-action@v18 + with: + globs: | + README.*.md + docs/*.md + + + golang-lint: + name: golang-lint + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Run linter + uses: golangci/golangci-lint-action@v6 + with: + version: v1.61 + + golang-test: + name: Golang Test + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Running Tests + run: | + go mod tidy + make test + + + chainsaw-test: + name: Chainsaw Test + runs-on: ubuntu-latest + strategy: + matrix: + k8s-version: ['1.26.15', '1.27.16'] + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Create KinD clustet pur + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version}} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make kind-create + + - name: Chainsaw test setup + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make chainsaw-setup + + - name: Test with Chainsaw + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make chainsaw-test + + + release-image: + name: Release Image + if: ${{ github.repository_owner == 'zncdatadev' }} + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64,linux/arm64 + + - name: Login to quay.io + uses: docker/login-action@v2 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Build and push operator + + run: | + make docker-buildx diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..aef8e9b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,64 @@ + +name: Test + +on: + push: + branches: + - "main" + pull_request: + + +jobs: + golang-test: + name: Golang Test + runs-on: ubuntu-latest + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Running Tests + run: | + go mod tidy + make test + + + chainsaw-test: + name: Chainsaw Test + runs-on: ubuntu-latest + strategy: + matrix: + k8s-version: ['1.26.15', '1.27.16'] + steps: + - name: Clone the code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '~1.23' + + - name: Create KinD clustet pur + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version}} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make kind-create + + - name: Chainsaw test setup + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make chainsaw-setup + + - name: Test with Chainsaw + env: + KINDTEST_K8S_VERSION: ${{ matrix.k8s-version }} + KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + KIND_KUBECONFIG: kind-kubeconfig-${{ matrix.k8s-version }} + run: make chainsaw-test diff --git a/README.md b/README.md index 2e68b46..93779fd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kubedoop Operator for Apache Kafka -[![Build](https://github.com/zncdatadev/kafka-operator/actions/workflows/main.yml/badge.svg)](https://github.com/zncdatadev/kafka-operator/actions/workflows/main.yml) +[![Build](https://github.com/zncdatadev/kafka-operator/actions/workflows/publish.yml/badge.svg)](https://github.com/zncdatadev/kafka-operator/actions/workflows/publish.yml) [![LICENSE](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go Report Card](https://goreportcard.com/badge/github.com/zncdatadev/kafka-operator)](https://goreportcard.com/report/github.com/zncdatadev/kafka-operator) [![Artifact HUB](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/kafka-operator)](https://artifacthub.io/packages/helm/kubedoop/kafka-operator) From 4b0cc3d59275ee3bed241289b66029b3321abfca Mon Sep 17 00:00:00 2001 From: lwpk110 Date: Fri, 29 Nov 2024 17:39:20 +0800 Subject: [PATCH 2/2] ci: update release workflow to include linting and testing dependencies --- .github/workflows/release.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59e4e18..d7c218a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -102,6 +102,11 @@ jobs: name: Release Image if: ${{ github.repository_owner == 'zncdatadev' }} runs-on: ubuntu-latest + needs: + - markdown-lint + - golang-lint + - golang-test + - chainsaw-test steps: - name: Clone the code uses: actions/checkout@v4