diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..06d9396 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Rust +target/ + +# Test +_test_output_dir +outputs +_datas +_logs diff --git a/.github/actions/setup-cross/action.yml b/.github/actions/setup-cross/action.yml new file mode 100644 index 0000000..a79f51d --- /dev/null +++ b/.github/actions/setup-cross/action.yml @@ -0,0 +1,17 @@ +name: Setup Cross +description: Install cargo cross +inputs: + version: + description: Cross Version + required: false + default: "0.2.4" +runs: + using: "composite" + steps: + - uses: actions-rs/cargo@v1 + with: + command: version + - shell: bash + run: | + curl -fsSLo /tmp/cross.tar.gz https://github.com/cross-rs/cross/releases/download/v${{ inputs.version }}/cross-x86_64-unknown-linux-gnu.tar.gz + tar -C ~/.cargo/bin -zxvf /tmp/cross.tar.gz diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..b0a564a --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,22 @@ +changelog: + exclude: + labels: + - pr-chore + authors: + - Mergify + categories: + - title: Exciting New Features ✨ + labels: + - pr-feature + - title: Thoughtful Bug Fix 🔧 + labels: + - pr-bugfix + - title: Code Refactor 🎉 + labels: + - pr-refactor + - title: Build/Testing/CI Infra Changes 🔌 + labels: + - pr-build + - title: Documentation 📔 + labels: + - pr-doc diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..7b1ec6e --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,75 @@ +name: dev + +on: + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + test: + timeout-minutes: 30 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -Dwarnings + - uses: actions-rs/cargo@v1 + with: + command: build + - uses: actions-rs/cargo@v1 + with: + command: test + args: --verbose + + build_linux: + timeout-minutes: 30 + name: build_linux_${{ matrix.arch }}_${{matrix.platform}} + runs-on: ubuntu-latest + strategy: + matrix: + arch: + - x86_64 + platform: + - musl + - gnu + steps: + - uses: actions/checkout@v3 + - id: target + run: echo ::set-output name=target::${{ matrix.arch }}-unknown-linux-${{ matrix.platform }} + - uses: ./.github/actions/setup-cross + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target=${{ steps.target.outputs.target }} + + build_macos: + timeout-minutes: 30 + name: build_macos_${{ matrix.arch }} + runs-on: macos-latest + strategy: + matrix: + arch: + - aarch64 + steps: + - uses: actions/checkout@v3 + - id: target + run: echo ::set-output name=target::${{ matrix.arch }}-apple-darwin + - name: Rust setup + uses: actions-rs/cargo@v1 + with: + command: version + - name: Cross setup + if: matrix.arch == 'aarch64' + run: | + rustup target add aarch64-apple-darwin + echo "JEMALLOC_SYS_WITH_LG_PAGE=14" >> $GITHUB_ENV + - name: Build Binary + run: | + cargo build --target=${{ steps.target.outputs.target }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e9d5621 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,143 @@ +name: release + +on: + push: + tags: + - "v*" + schedule: + # Release at 00:00 UTC+8 + - cron: '0 16 * * *' + workflow_dispatch: + +jobs: + create_release: + name: create release + runs-on: ubuntu-latest + outputs: + version: ${{ steps.generated-tag.outputs.tag }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get latest tag + id: get-latest-tag + run: | + echo "::set-output name=tag::`gh release list -L 1 | cut -f 1`" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Bump version + id: generated-tag + uses: actions/github-script@v6 + with: + script: | + if (context.ref.startsWith("refs/tags/")) { + let tag = context.ref.replace("refs/tags/", ""); + core.setOutput('tag', tag); + console.log(`This event pushed a tag ${tag}, return directly.`) + return + } + let tag = "${{ steps.get-latest-tag.outputs.tag }}"; + let result = /v(\d+)\.(\d+)\.(\d+)/g.exec(tag); + if (result === null) { + throw `The previous tag ${{ steps.get-latest-tag.outputs.tag }} is invalid, ignoring`; + } + let major = result[1]; + let minor = result[2]; + let patch = (parseInt(result[3]) + 1).toString(); + let next_tag = `v${major}.${minor}.${patch}-nightly`; + console.log(`This event is triggered, return generated ${next_tag}.`) + core.setOutput('tag', next_tag) + - name: Create github release if not exist + # Reference: https://cli.github.com/manual/gh_release_create + run: | + echo "Create a release for ${{ steps.generated-tag.outputs.tag }}" + gh release create ${{ steps.generated-tag.outputs.tag }} --generate-notes -p + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish_macos: + name: macos assets + runs-on: macos-11 + needs: create_release + strategy: + fail-fast: false + matrix: + arch: + - x86_64 + - aarch64 + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Get target + id: target + run: echo ::set-output name=target::${{ matrix.arch }}-apple-darwin + - name: Rust setup + uses: actions-rs/cargo@v1 + with: + command: version + - name: Cross setup + if: matrix.arch == 'aarch64' + run: | + rustup target add aarch64-apple-darwin + echo "JEMALLOC_SYS_WITH_LG_PAGE=14" >> $GITHUB_ENV + - name: Build Binary + run: | + cargo build --release --target=${{ steps.target.outputs.target }} + - name: Pack binaries + run: | + brew install gnu-tar + sudo /usr/sbin/purge + mkdir -p release/${{ steps.target.outputs.target }}/bin + cp ./target/${{ steps.target.outputs.target }}/release/ethtel release/${{ steps.target.outputs.target }}/bin/ + rm -f release/${{ steps.target.outputs.target }}/bin/*.d + cp -r ./schemas release/${{ steps.target.outputs.target }}/schemas + gtar -C ./release/${{ steps.target.outputs.target }} -czvf ethtel-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.tar.gz bin schemas + - name: Update release to github + shell: bash + # Reference: https://cli.github.com/manual/gh_release_upload + run: gh release upload ${{ inputs.version }} ethtel-${{ inputs.version }}-${{ inputs.target }}.* --clobber + env: + GH_TOKEN: ${{ inputs.github_token }} + + publish_linux: + name: linux assets + runs-on: ubuntu-latest + needs: create_release + strategy: + fail-fast: false + matrix: + arch: + - x86_64 + - aarch64 + platform: + - musl + - gnu + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Get target + id: target + run: echo ::set-output name=target::${{ matrix.arch }}-unknown-linux-${{ matrix.platform }} + - uses: ./.github/actions/setup-cross + - name: Build Binary + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target=${{ steps.target.outputs.target }} + - name: Pack binaries + run: | + brew install gnu-tar + sudo /usr/sbin/purge + mkdir -p release/${{ steps.target.outputs.target }}/bin + cp ./target/${{ steps.target.outputs.target }}/release/ethtel release/${{ steps.target.outputs.target }}/bin/ + rm -f release/${{ steps.target.outputs.target }}/bin/*.d + cp -r ./schemas release/${{ steps.target.outputs.target }}/schemas + gtar -C ./release/${{ steps.target.outputs.target }} -czvf ethtel-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.tar.gz bin schemas + - name: Update release to github + shell: bash + # Reference: https://cli.github.com/manual/gh_release_upload + run: gh release upload ${{ inputs.version }} ethtel-${{ inputs.version }}-${{ inputs.target }}.* --clobber + env: + GH_TOKEN: ${{ inputs.github_token }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index e970c30..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: Rust - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Build - run: cargo build - - name: Run lint - run: cargo clippy -- -Dwarnings - - name: Run unit tests - run: cargo test --verbose \ No newline at end of file diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..2d4ff10 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,24 @@ +[build.env] +passthrough = [ + "BUILD_DIR", + "CARGO_INCREMENTAL", + "CARGO_PROFILE_RELEASE_OPT_LEVEL", + "CARGO_PROFILE_RELEASE_CODEGEN_UNITS", + "RUST_BACKTRACE", + "RUST_LOG", + "VECTOR_BUILD_DESC", + "JEMALLOC_SYS_WITH_LG_PAGE", + "JEMALLOC_SYS_WITH_LG_HUGEPAGE", +] + +[target.aarch64-unknown-linux-gnu] +pre-build = ["dpkg --add-architecture arm64 && apt-get update && apt-get install -y libssl-dev libssl-dev:arm64"] + +[target.x86_64-unknown-linux-gnu] +pre-build = ["apt-get update && apt-get install -y libssl-dev"] + +[target.aarch64-unknown-linux-musl] +dockerfile = "./docker/cross/Dockerfile.aarch64-unknown-linux-musl" + +[target.x86_64-unknown-linux-musl] +dockerfile = "./docker/cross/Dockerfile.x86_64-unknown-linux-musl" diff --git a/docker/cross/Dockerfile.aarch64-unknown-linux-musl b/docker/cross/Dockerfile.aarch64-unknown-linux-musl new file mode 100644 index 0000000..de2b664 --- /dev/null +++ b/docker/cross/Dockerfile.aarch64-unknown-linux-musl @@ -0,0 +1,7 @@ +FROM ghcr.io/cross-rs/aarch64-unknown-linux-musl:main + +COPY docker/cross/openssl.sh / +RUN bash /openssl.sh linux-aarch64 aarch64-linux-musl- +ENV OPENSSL_DIR=/openssl \ + OPENSSL_INCLUDE_DIR=/openssl/include \ + OPENSSL_LIB_DIR=/openssl/lib diff --git a/docker/cross/Dockerfile.x86_64-unknown-linux-musl b/docker/cross/Dockerfile.x86_64-unknown-linux-musl new file mode 100644 index 0000000..1693ef9 --- /dev/null +++ b/docker/cross/Dockerfile.x86_64-unknown-linux-musl @@ -0,0 +1,7 @@ +FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:main + +COPY docker/cross/openssl.sh / +RUN bash /openssl.sh linux-x86_64 x86_64-linux-musl- +ENV OPENSSL_DIR=/openssl \ + OPENSSL_INCLUDE_DIR=/openssl/include \ + OPENSSL_LIB_DIR=/openssl/lib diff --git a/docker/cross/openssl.sh b/docker/cross/openssl.sh new file mode 100755 index 0000000..78a88a7 --- /dev/null +++ b/docker/cross/openssl.sh @@ -0,0 +1,49 @@ +set -ex + +main() { + local version=1.0.2t + local os=$1 \ + triple=$2 + + local dependencies=( + ca-certificates + curl + m4 + make + perl + ) + + # NOTE cross toolchain must be already installed + apt-get update + local purge_list=() + for dep in ${dependencies[@]}; do + if ! dpkg -L $dep; then + apt-get install --no-install-recommends -y $dep + purge_list+=($dep) + fi + done + + td=$(mktemp -d) + + pushd $td + curl https://www.openssl.org/source/openssl-$version.tar.gz | + tar --strip-components=1 -xz + AR=${triple}ar CC=${triple}gcc ./Configure \ + --prefix=/openssl \ + no-dso \ + $os \ + -fPIC \ + ${@:3} + nice make -j$(nproc) + make install + + # clean up + apt-get purge --auto-remove -y ${purge_list[@]} + + popd + + rm -rf $td + rm $0 +} + +main "${@}" diff --git a/mergify.yml b/mergify.yml new file mode 100644 index 0000000..8ee7d46 --- /dev/null +++ b/mergify.yml @@ -0,0 +1,106 @@ +pull_request_rules: + # Check if PR title contain valid types + - name: Comment PR if title not semantic + conditions: + - author!=Mergify + - -draft + - '-title~=^(feat|fix|refactor|ci|build|docs|website|chore)(\(.*\))?:' + actions: + comment: + message: | + This pull request's title is not fulfill the requirements. @{{author}} please update it 🙏. + Valid format: + ``` + fix(query): fix group by string bug + ^ ^---------------------^ + | | + | +-> Summary in present tense. + | + +-------> Type: feat, fix, refactor, ci, build, docs, website, chore + ``` + Valid types: + - `feat`: this PR introduces a new feature to the codebase + - `fix`: this PR patches a bug in codebase + - `refactor`: this PR changes the code base without new features or bugfix + - `ci|build`: this PR changes build/testing/ci steps + - `docs|website`: this PR changes the documents or websites + - `chore`: this PR only has small changes that no need to record + + # Check if PR title contain valid types + - name: Semantic PR Check + conditions: + - or: + - author=Mergify + - 'title~=^(feat|fix|refactor|ci|build|docs|website|chore)(\(.*\))?:' + actions: + post_check: + title: | + {% if check_succeed %} + Title follows Semantic PR + {% else %} + Title does not follow Semantic PR + {% endif %} + summary: | + {% if not check_succeed %} + Pull request title must follow [Semantic PR](https://databend.rs/doc/contributing/good-pr) + Valid format: + ``` + fix(query): fix group by string bug + ^ ^---------------------^ + | | + | +-> Summary in present tense. + | + +-------> Type: feat, fix, refactor, ci, build, docs, website, chore + ``` + Valid types: + - `feat`: this PR introduces a new feature to the codebase + - `fix`: this PR patches a bug in codebase + - `refactor`: this PR changes the code base without new features or bugfix + - `ci|build`: this PR changes build/testing/ci steps + - `docs|website`: this PR changes the documents or websites + - `chore`: this PR only has small changes that no need to record + {% endif %} + + # Assign pr label based of tags + - name: label on New Feature + conditions: + - 'title~=^(feat)(\(.*\))?:' + actions: + label: + add: + - pr-feature + - name: label on Bug Fix + conditions: + - 'title~=^(fix)(\(.*\))?:' + actions: + label: + add: + - pr-bugfix + - name: label on Refactor + conditions: + - 'title~=^(refactor)(\(.*\))?:' + actions: + label: + add: + - pr-refactor + - name: label on Build/Testing/CI + conditions: + - 'title~=^(ci|build)(\(.*\))?:' + actions: + label: + add: + - pr-build + - name: label on Documentation + conditions: + - 'title~=^(docs|website)(\(.*\))?:' + actions: + label: + add: + - pr-doc + - name: label on Not for changelog + conditions: + - 'title~=^(chore)(\(.*\))?:' + actions: + label: + add: + - pr-chore