diff --git a/.github/scripts/install_deps.sh b/.github/scripts/install_deps.sh deleted file mode 100755 index fca1b25a..00000000 --- a/.github/scripts/install_deps.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -apt-get install -y cmake g++ expect libssl-dev - -# install protoc -wget https://github.com/protocolbuffers/protobuf/releases/download/v21.10/protoc-21.10-linux-x86_64.zip -unzip protoc-21.10-linux-x86_64.zip -d .local -mv "$(pwd)/.local/bin/protoc" /bin/ -mv "$(pwd)/.local/include/google" /usr/include/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 74b47247..689c699c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,98 +4,46 @@ on: schedule: - cron: "00 19 * * *" # run ci periodically at 3 am pull_request: - branches: [ main ] + branches: [main] env: - CI_RUST_TOOLCHAIN: 1.70.0 + GO_VERSION: '1.21' jobs: - outdated: - name: Outdated + format: + name: Format runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/install@v0.1 - with: - crate: cargo-outdated - version: latest - - run: cargo outdated --workspace + - name: Checkout code + uses: actions/checkout@v3 - audit: - name: Audit - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - crate: cargo-audit - use-tool-cache: true - - uses: actions-rs/audit-check@v1.2.0 - with: - token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ${{env.GO_VERSION}} - check: - runs-on: ubuntu-latest - name: Check - steps: - - uses: actions/checkout@v2 - - run: sudo bash ./.github/scripts/install_deps.sh - - uses: actions-rs/toolchain@v1 - with: - profile: default - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - override: true - - uses: Swatinem/rust-cache@v2 - - uses: actions-rs/cargo@v1 - with: - command: check + - name: Format code + uses: iamnotaturtle/auto-gofmt@v1.0 + with: + # This part is also where you can pass other options, for example: + only_changed: True - fmt: - name: Format + lint: + name: Lint Check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: default - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - override: true - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - name: Checkout code + uses: actions/checkout@v3 - test: - runs-on: ubuntu-latest - name: Test - steps: - - uses: actions/checkout@v2 - - run: sudo bash ./.github/scripts/install_deps.sh - - uses: actions-rs/toolchain@v1 + - name: Setup Go + uses: actions/setup-go@v4 with: - profile: default - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - override: true - - uses: Swatinem/rust-cache@v2 - - uses: actions-rs/cargo@v1 - with: - command: test + go-version: ${{env.GO_VERSION}} - clippy: - runs-on: ubuntu-latest - name: Clippy - steps: - - uses: actions/checkout@v2 - - run: sudo bash ./.github/scripts/install_deps.sh - - uses: actions-rs/toolchain@v1 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 with: - profile: default - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - override: true - - uses: Swatinem/rust-cache@v2 - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --all-targets --all-features -- -D warnings + version: v1.54.2 commit: name: Commit Message Validation @@ -118,7 +66,8 @@ jobs: name: Spell Check runs-on: ubuntu-latest steps: - - name: Checkout Actions Repository - uses: actions/checkout@v2 - - name: Check Spelling - uses: crate-ci/typos@master + - name: Checkout Actions Repository + uses: actions/checkout@v2 + + - name: Check Spelling + uses: crate-ci/typos@master diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index fdd78539..00000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Coverage - -on: - push: - branches: - - main - pull_request: - branches: [ main ] - -env: - CI_RUST_TOOLCHAIN: 1.70.0 - -jobs: - coverage: - name: Coverage - runs-on: ubuntu-latest - env: - CARGO_TERM_COLOR: always - steps: - - uses: actions/checkout@v3 - - run: sudo bash ./.github/scripts/install_deps.sh - - uses: Swatinem/rust-cache@v2 - - name: Install Rust - run: rustup update stable - - name: Install cargo-llvm-cov - uses: taiki-e/install-action@cargo-llvm-cov - - name: Generate code coverage - run: cargo llvm-cov --all-features --lib --workspace --codecov --output-path codecov.info - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - files: codecov.info - fail_ci_if_error: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index eeaa77b3..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,126 +0,0 @@ -name: Docker Image - -on: - workflow_dispatch: { } - workflow_call: { } - -env: - CI_RUST_TOOLCHAIN: 1.70.0 - REPOSITORY: xline-kv - -jobs: - push_image: - name: Push Docker Image - runs-on: ${{ matrix.job.os }} - strategy: - fail-fast: false - matrix: - job: - - os: ubuntu-latest - platform: linux/amd64 - target: x86_64-unknown-linux-gnu - cross_image: x86_64-linux-gnu - - os: ubuntu-latest - platform: linux/arm64 - target: aarch64-unknown-linux-gnu - cross_image: aarch64-linux-gnu - package: - - xline-operator - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Setup Custom Image for ${{ matrix.job.cross_image }} - uses: docker/build-push-action@v2 - with: - context: .github/scripts - file: .github/scripts/${{ matrix.job.target }}.Dockerfile - tags: ${{ matrix.job.cross_image }}:latest - load: true - cache-from: type=gha - cache-to: type=gha,mode=max - - - name: Install Toolchain - uses: dtolnay/rust-toolchain@v1 - with: - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - target: ${{ matrix.job.target }} - - - uses: Swatinem/rust-cache@v2 - with: - cache-on-failure: true - key: '${{ matrix.job.target }}' - - - name: Install cross - uses: baptiste0928/cargo-install@v2 - with: - crate: cross - cache-key: '${{ matrix.job.target }}' - - - name: Build Binary - run: | - cross build --target ${{ matrix.job.target }} --release --bin ${{ matrix.package }} - - - name: Move Cross-compiled Binary - run: | - mv ./target/${{ matrix.job.target }}/release/${{ matrix.package }} ./build - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Login to Github Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ env.REPOSITORY }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set up Image ID - run: | - IMAGE_ID=ghcr.io/${{ env.REPOSITORY }}/${{ matrix.package }} - echo IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') >> $GITHUB_ENV - - - name: Build Image - id: build_image - uses: docker/build-push-action@v4 - with: - context: ./build - file: ./build/${{ matrix.package }}.Dockerfile - platforms: ${{ matrix.job.platform }} - outputs: type=image,name=${{ env.IMAGE_ID }},push-by-digest=true,name-canonical=true,push=true - - - name: Export Digest - run: | - mkdir -p /tmp/digests - digest="${{ steps.build_image.outputs.digest }}" - touch "/tmp/digests/${digest#sha256:}" - - - name: Upload Digest - uses: actions/upload-artifact@v3 - with: - name: digests-${{ matrix.package }} - path: /tmp/digests/* - if-no-files-found: error - retention-days: 1 - - - name: Export Version - run: | - mkdir -p /tmp/versions - version=$(cargo metadata --no-deps --format-version 1 | jq '.packages[] | select(.name == "${{ matrix.package }}") | .version' | tr -d '"') - touch "/tmp/versions/${version}" - touch "/tmp/versions/$(git rev-parse --short HEAD)" - - - name: Upload Version - uses: actions/upload-artifact@v3 - with: - name: versions-${{ matrix.package }} - path: /tmp/versions/* - if-no-files-found: error - retention-days: 1 - - merge_image: - needs: push_image - uses: ./.github/workflows/merge_image.yml diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml deleted file mode 100644 index 26619ed1..00000000 --- a/.github/workflows/e2e.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: E2E - -on: - pull_request: - branches: - - main - workflow_dispatch: { } - -# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency -concurrency: - group: ${{ github.workflow }}-${{ github.actor }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true - -env: - CI_RUST_TOOLCHAIN: 1.70.0 - KIND_VERSION: v0.20.0 - -jobs: - validation: - name: 'Validation' - runs-on: ubuntu-latest - strategy: - matrix: - k8s: [ v1.25.3, v1.26.0, v1.27.3 ] - steps: - - uses: actions/checkout@v2 - - run: sudo bash ./.github/scripts/install_deps.sh - - name: 'Install Kind' - run: | - wget https://github.com/kubernetes-sigs/kind/releases/download/${{ env.KIND_VERSION }}/kind-linux-amd64 - chmod +x kind-linux-amd64 - mv kind-linux-amd64 /usr/local/bin/kind - - name: 'Install Toolchain' - uses: dtolnay/rust-toolchain@v1 - with: - toolchain: ${{ env.CI_RUST_TOOLCHAIN }} - - uses: Swatinem/rust-cache@v2 - - name: 'Build Image' - run: | - cargo build --release - cd build - cp ../target/release/xline-operator . - docker build . -t xline-kv/xline-operator:latest -f operator.Dockerfile - - name: 'E2E CI' - env: - KIND_CLUSTER_IMAGE: kindest/node:${{ matrix.k8s }} - run: bash ./tests/e2e/e2e.sh -p ci - - name: clean - if: failure() - run: bash ./tests/e2e/e2e.sh -c - - name: upload kind logs - if: always() - uses: actions/upload-artifact@v3 - with: - name: xline_kind_log_${{ matrix.k8s }} - path: /tmp/xlineoperator/e2e-kind diff --git a/.github/workflows/merge_image.yml b/.github/workflows/merge_image.yml deleted file mode 100644 index 3b677e20..00000000 --- a/.github/workflows/merge_image.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Merge Image - -on: - workflow_call: { } - -env: - REPOSITORY: xline-kv - -jobs: - merge_image: - runs-on: ubuntu-latest - name: Merge Docker Image - strategy: - fail-fast: false - matrix: - package: - - xline-operator - steps: - - name: Download Digests - uses: actions/download-artifact@v3 - with: - name: digests-${{ matrix.package }} - path: /tmp/digests - - - name: Download Versions - uses: actions/download-artifact@v3 - with: - name: versions-${{ matrix.package }} - path: /tmp/versions - - - name: Set up Image ID - run: | - IMAGE_ID=ghcr.io/${{ env.REPOSITORY }}/${{ matrix.package }} - echo IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') >> $GITHUB_ENV - - - name: Export Digests - working-directory: /tmp/digests - run: | - echo digests=$(printf '${{ env.IMAGE_ID }}@sha256:%s ' *) >> $GITHUB_ENV - - - name: Export Tags - working-directory: /tmp/versions - run: | - echo tags=$(printf -- '-t ${{ env.IMAGE_ID }}:%s ' *) >> $GITHUB_ENV - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to Github Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ env.REPOSITORY }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Push Manifest - run: | - docker buildx imagetools create \ - -t ${{ env.IMAGE_ID }}:latest \ - ${{ env.tags }} \ - ${{ env.digests }} - - - name: Inspect Manifest - run: | - docker buildx imagetools inspect ${{ env.IMAGE_ID }}:latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 895d6e20..00000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Release - -on: - push: - tags: - - "v*" - -jobs: - create_release: - name: Create Release - runs-on: ubuntu-latest - steps: - - name: Create Release - id: create_release - uses: actions/create-release@v1.0.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: false - prerelease: false - - publish_image: - name: Publish Image - uses: ./.github/workflows/docker.yml - secrets: inherit diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8d7f9ec5..1c4e3850 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,12 +20,12 @@ repos: rev: v1.16.0 hooks: - id: typos - - repo: https://github.com/dnephin/pre-commit-golang - rev: v0.5.1 + - repo: https://github.com/Bahjat/pre-commit-golang + rev: v1.0.2 hooks: - - id: go-fmt - - id: go-imports - - id: go-mod-tidy + - id: go-fmt-import + - id: gofumpt + - id: golangci-lint - repo: local hooks: - id: conventional-commit-msg-validation