From 8367a2fd75d4cfb2d89ebcae3d3e46f4bbfa2d3a Mon Sep 17 00:00:00 2001 From: Ivan Dyachkov Date: Thu, 2 Feb 2023 17:06:38 +0100 Subject: [PATCH] ci: build and publish binary packages --- .github/workflows/ci.yml | 22 +++---- .github/workflows/release.yml | 112 ++++++++++++++++++++++++++++++++++ .gitignore | 7 ++- Makefile | 33 +++++++--- rebar.config | 9 ++- rebar.config.script | 7 ++- scripts/rename-package.sh | 41 +++++++++++++ 7 files changed, 205 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100755 scripts/rename-package.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3874027..d2be4cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,29 +1,23 @@ name: CI on: - push: - branches: [ master ] pull_request: - branches: [ master ] + branches: + - master jobs: - build: - runs-on: ubuntu-latest strategy: matrix: - otp: [24] + otp: + - 24 container: image: erlang:${{ matrix.otp }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Compile and run tests - run: BUILD_WITHOUT_QUIC=true make - - # services: - # emqx: - # image: emqx:4.4 - # ports: - # - 1883:1883 + env: + BUILD_WITHOUT_QUIC: "true" + run: make diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ec64082 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,112 @@ +name: Release + +on: + push: + tags: + - "*" + workflow_dispatch: + inputs: + tag: + type: string + required: true + dryrun: + type: boolean + required: true + default: false + +jobs: + package: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + otp: + - "24" + quic_support: + - true + - false + os: + - ubuntu22.04 + - ubuntu20.04 + - ubuntu18.04 + - ubuntu16.04 + - debian10 + - debian9 + - rockylinux8 + - rockylinux9 + - centos7 + - amzn2 + container: + image: erlang:${{ matrix.otp }} + + steps: + - uses: actions/checkout@v3 + - shell: bash + run: | + [ "false" == ${{ matrix.quic_support }} ] && export BUILD_WITHOUT_QUIC=1 + make release + - if: failure() + run: cat rebar3.crashdump + - run: ./_build/default/bin/emqttb + - uses: actions/upload-artifact@v3 + if: startsWith(github.ref, 'refs/tags/') + with: + name: packages + path: ./*.tar.gz + + mac: + strategy: + fail-fast: false + matrix: + macos: + - macos-12 + otp: + - "24" + + runs-on: ${{ matrix.macos }} + + steps: + - uses: actions/checkout@v3 + - id: prepare + env: + HOMEBREW_NO_AUTO_UPDATE: 1 + HOMEBREW_NO_INSTALL_UPGRADE: 1 + HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1 + run: brew install coreutils erlang@${{ matrix.otp }} + - name: build + shell: bash + run: make release + - if: failure() + run: cat rebar3.crashdump + - run: ./_build/default/bin/emqttb + - uses: actions/upload-artifact@v3 + if: startsWith(github.ref, 'refs/tags/') + with: + name: packages + path: ./*.tar.gz + + release: + runs-on: ubuntu-latest + needs: package + if: startsWith(github.ref, 'refs/tags/') && !inputs.dryrun + + steps: + - uses: actions/download-artifact@v3 + with: + name: packages + path: packages + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: EMQTT bench daemon ${{ github.ref }} Released + body: EMQTT bench daemon ${{ github.ref }} Released + draft: false + prerelease: false + - uses: Rory-Z/upload-release-asset@v1 + with: + repo: emqttb + path: "packages/emqttb-*" + token: ${{ github.token }} diff --git a/.gitignore b/.gitignore index 4039311..0145a15 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,9 @@ _build rebar3.crashdump *~ docs/ -TAGS \ No newline at end of file +TAGS +/rebar.lock +/.emqttb.repeat +/*.tar.gz +/emqttb +/libquicer_nif.so diff --git a/Makefile b/Makefile index 0591340..cafd1f6 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,34 @@ -.PHONY: all dialyzer compile +REBAR ?= rebar3 + +.PHONY: all all: - rebar3 do compile, dialyzer, escriptize, eunit, ct + $(REBAR) do compile, dialyzer, eunit, ct + +.PHONY: compile +compile: + $(REBAR) compile +.PHONY: dialyzer dialyzer: - rebar3 do dialyzer + $(REBAR) do compile, dialyzer -compile: - rebar3 do compile +.PHONY: test +test: + $(REBAR) do eunit, ct + +.PHONY: release +release: + $(REBAR) do compile, tar .PHONY: README.md -README.md: - rebar3 escriptize +README.md: compile ./emqttb @make-docs --src "$$(pwd)/doc/src/conf.xml" pandoc -o "$@" --to gfm-gfm_auto_identifiers --from docbook 'docs/EMQTT bench daemon.xml' + +.PHONY: clean +clean: distclean + +.PHONY: distclean +distclean: + @rm -rf _build erl_crash.dump rebar3.crashdump rebar.lock emqttb + diff --git a/rebar.config b/rebar.config index 83190b2..b919b6d 100644 --- a/rebar.config +++ b/rebar.config @@ -14,7 +14,6 @@ {relx, [ {release, {emqttb, "0.1.0"}, [emqttb, kernel]} , {mode, dev} - , {sys_config_src, "./config/sys.config.src"} , {vm_args_src, "./config/vm.args.src"} ]}. @@ -38,11 +37,15 @@ " ${REBAR_CHECKOUTS_OUT_DIR}/quicer/priv/libquicer_nif.so; " " do [ -f $nifso ] && cp $nifso ${REBAR_BUILD_DIR}/bin/; " " done; " - " rm ./emqttb ./libquicer_nif.so; " - " ln -s \"${REBAR_BUILD_DIR}/bin/emqttb\" ./emqttb; " + " rm ./emqttb ./libquicer_nif.so; " + " ln -s \"${REBAR_BUILD_DIR}/bin/emqttb\" ./emqttb; " " ln -s \"${REBAR_BUILD_DIR}/bin/libquicer_nif.so\" ./libquicer_nif.so; " " ' " }, + {"(linux|darwin|solaris|freebsd|netbsd|openbsd)", + tar, + "scripts/rename-package.sh" + }, {"win32", escriptize, "robocopy \"%REBAR_BUILD_DIR%/bin/\" ./ emqttb* " diff --git a/rebar.config.script b/rebar.config.script index bb20f8f..1506f46 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -14,9 +14,14 @@ fun() -> win32 =:= element(1, os:type()) end, +IsDarwin = +fun() -> + {unix, darwin} =:= os:type() +end, + Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.9"}}}, -IsQuicSupp = not (IsCentos6() orelse IsWin32() orelse +IsQuicSupp = not (IsCentos6() orelse IsWin32() orelse IsDarwin() orelse false =/= os:getenv("BUILD_WITHOUT_QUIC") ), diff --git a/scripts/rename-package.sh b/scripts/rename-package.sh new file mode 100755 index 0000000..585dd2a --- /dev/null +++ b/scripts/rename-package.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash + +set -euo pipefail + +cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")/.." + +UNAME="$(uname -s)" + +case "$UNAME" in + Darwin) + DIST='macos' + VERSION_ID=$(sw_vers -productVersion | cut -d '.' -f 1) + SYSTEM="${DIST}${VERSION_ID}" + ;; + Linux) + DIST="$(sed -n '/^ID=/p' /etc/os-release | sed -r 's/ID=(.*)/\1/g' | sed 's/"//g')" + VERSION_ID="$(sed -n '/^VERSION_ID=/p' /etc/os-release | sed -r 's/VERSION_ID=(.*)/\1/g' | sed 's/"//g')" + SYSTEM="$(echo "${DIST}${VERSION_ID}" | sed -r 's/([a-zA-Z]*)-.*/\1/g')" + ;; + CYGWIN*|MSYS*|MINGW*) + SYSTEM="windows" + ;; +esac + +ARCH="$(uname -m)" +case "$ARCH" in + x86_64) + ARCH='amd64' + ;; + aarch64) + ARCH='arm64' + ;; + arm*) + ARCH=arm + ;; +esac + +VSN="$(grep -E ".+vsn.+" _build/default/lib/emqttb/ebin/emqttb.app | cut -d '"' -f2)" +BASE=$(find ./_build/default/rel/emqttb -name "*.tar.gz" | tail -1) +QUIC=$(find ./_build/default/rel/emqttb -name "quicer-*" | grep -q quicer && echo '-quic' || echo '') +cp "$BASE" "./emqttb-${VSN}-${SYSTEM}-${ARCH}${QUIC}.tar.gz"