Skip to content

Commit

Permalink
ci: build and publish binary packages
Browse files Browse the repository at this point in the history
  • Loading branch information
id committed Feb 2, 2023
1 parent a9cb23d commit 8367a2f
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 26 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
112 changes: 112 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ _build
rebar3.crashdump
*~
docs/
TAGS
TAGS
/rebar.lock
/.emqttb.repeat
/*.tar.gz
/emqttb
/libquicer_nif.so
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

9 changes: 6 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
]}.

Expand All @@ -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* "
Expand Down
7 changes: 6 additions & 1 deletion rebar.config.script
Original file line number Diff line number Diff line change
Expand Up @@ -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")
),

Expand Down
41 changes: 41 additions & 0 deletions scripts/rename-package.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 8367a2f

Please sign in to comment.