Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] Build with GitHub actions #748

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
on:
workflow_call:
inputs:
arch:
type: string
default: "64"
compiler:
type: string
default: "gcc"
coverage:
type: string
default: "OFF"
lib_msg_delivery:
type: string
default: "OFF"
lib_write_deadline:
type: string
default: "OFF"
repeat:
type: string
default: "1"
sanitize:
type: string
description: "sanitize option to use, 'address' or 'thread'"
server_version:
type: string
description: "nats-server version to test with"
default: "latest"
streaming:
type: string
default: "ON"
tls:
type: string
default: "ON"
type:
type: string
description: "Debug or Release."
default: "Release"
ubuntu_version:
type: string
description: "Ubuntu version to use, e.g. '20.04'"
default: "latest"
secrets:
CODECOV_TOKEN:
description: "Codecov repo token"

permissions:
contents: write # to comment on coverage.

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
do:
runs-on: ubuntu-${{ inputs.ubuntu_version }}
name: "ubuntu:${{ inputs.ubuntu_version }} ${{ inputs.compiler }} nats:${{ inputs.server_version }}"
steps:
- name: Checkout nats.c
uses: actions/checkout@v4

- name: "Checkout dependencies (nats.c.deps)"
uses: actions/checkout@v4
with:
repository: nats-io/nats.c.deps
path: deps

# configure the cmake flags and NATS_... environment variables
- id: cmake-flags
name: Configure cmake flags
env:
flags: -DNATS_BUILD_ARCH=${{ inputs.arch }}
-DCMAKE_BUILD_TYPE=${{ inputs.type }}
-DNATS_BUILD_STREAMING=${{ inputs.streaming }}
-DNATS_BUILD_WITH_TLS=${{ inputs.tls }}
-DNATS_PROTOBUF_DIR=${{ github.workspace}}/deps/pbuf
-DNATS_BUILD_USE_SODIUM=ON
-DNATS_SODIUM_DIR=${{ github.workspace}}/deps/sodium
run: |
if [[ -n "${{ inputs.sanitize }}" ]]; then
flags="$flags -DNATS_SANITIZE=ON -DCMAKE_C_FLAGS=-fsanitize=${{ inputs.sanitize }}"
fi
if [[ "${{ inputs.coverage }}" == "ON" ]]; then
flags="$flags -DNATS_COVERAGE=ON"
fi
echo "flags=$flags" >> $GITHUB_OUTPUT

- id: nats-vars
name: Configure NATS_ environment variables
run: |
if [[ -n "${{ inputs.sanitize }}" ]]; then
echo "NATS_TEST_VALGRIND=yes" >> $GITHUB_ENV
fi
if [[ "${{ inputs.lib_msg_delivery }}" == "ON" ]]; then
echo "NATS_DEFAULT_TO_LIB_MSG_DELIVERY=yes" >> $GITHUB_ENV
fi
if [[ "${{ inputs.lib_write_deadline }}" == "ON" ]]; then
echo "NATS_DEFAULT_LIB_WRITE_DEADLINE=2000" >> $GITHUB_ENV
fi
echo "CC=${{ inputs.compiler }}" >> $GITHUB_ENV

# install build dependencies
- name: Install ${{ inputs.compiler }} if needed
if: startsWith(inputs.compiler, 'clang-') || startsWith(inputs.compiler, 'gcc-')
run: |
sudo apt-get -q update
sudo apt-get -y install ${{ inputs.compiler }}

# otherwise, configure cmake, build, archive and upload
- name: CMake
run: |
mkdir -p build
cd build
cmake .. ${{ steps.cmake-flags.outputs.flags }}
make rebuild_cache && make

- name: "Rebuild the list of tests to match the compile flags"
working-directory: ./build
run: |
./test/testsuite
if [[ $(diff list.txt ../test/list.txt; echo $?) != 0 ]]; then
mv list.txt ../test/list.txt
make rebuild_cache
fi

# testing

- name: "Download nats-server version ${{ inputs.server_version }}"
if: inputs.server_version
working-directory: ./build
run: |
rel=${{ inputs.server_version }}
if [ "$rel" = "latest" ]; then
rel=$(curl -s https://api.github.com/repos/nats-io/nats-server/releases/latest | jq -r '.tag_name')
fi
if [ "$rel" != "${rel#v}" ] && wget https://github.com/nats-io/nats-server/releases/download/$rel/nats-server-$rel-linux-amd64.tar.gz; then
tar -xzf nats-server-$rel-linux-amd64.tar.gz
cp nats-server-$rel-linux-amd64/nats-server ../deps/nats-server/nats-server
else
for c in 1 2 3 4 5
do
echo "Attempt $c to download binary for main"
rm -f ./nats-server
curl -sf "https://binaries.nats.dev/nats-io/nats-server/v2@$rel" | PREFIX=. sh
# We are sometimes getting nats-server of size 0. Make sure we have a
# working nats-server by making sure we get a version number.
v="$(./nats-server -v)"
if [ "$v" != "" ]; then
break
fi
done
mv ./nats-server ../deps/nats-server/nats-server
fi

- name: "Test"
working-directory: ./build
run: |
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest --timeout 60 --output-on-failure --repeat-until-fail ${{ inputs.repeat }} 2>&1 | tee /tmp/out.txt
if [[ $(grep -q 'ThreadSanitizer: ' /tmp/out.txt; echo $?) == 0 ]]; then
echo "!!! ThreadSanitizer detected WARNING(s) !!!"
exit 1
fi

- name: Upload coverage reports to Codecov
if: inputs.coverage == 'ON'
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
# verbose: true
66 changes: 66 additions & 0 deletions .github/workflows/on-pr-debug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Debug"
on:
pull_request:

permissions:
contents: write # so it can comment

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
default:
name: "DefaultD"
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
uses: ./.github/workflows/build-test.yml
with:
compiler: ${{ matrix.compiler }}
server_version: main
type: Debug
repeat: 3

coverage:
name: "Coverage"
uses: ./.github/workflows/build-test.yml
with:
coverage: ON
server_version: main
type: Debug
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

sanitize-addr:
name: "Sanitize address"
uses: ./.github/workflows/build-test.yml
with:
sanitize: address
server_version: main
type: Debug

sanitize-addr-lib-msg-delivery:
name: "Sanitize address (lib_msg_delivery)"
uses: ./.github/workflows/build-test.yml
with:
sanitize: address
server_version: main
lib_msg_delivery: ON

san-addr:
name: "Sanitize address (lib_write_deadline)"
uses: ./.github/workflows/build-test.yml
with:
sanitize: address
server_version: main
lib_write_deadline: ON

san-thread:
name: "Sanitize thread"
uses: ./.github/workflows/build-test.yml
with:
sanitize: thread
server_version: main
repeat: 3
62 changes: 62 additions & 0 deletions .github/workflows/on-push-release-extra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: "Release"
on:
push:
branches:
- main
- release_*


permissions:
contents: write # required by build-test to comment on coverage but not used here.

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
server-versions:
strategy:
fail-fast: false
matrix:
server_version: [latest, v2.9.11]
uses: ./.github/workflows/build-test.yml
name: "Other servers"
with:
server_version: ${{ matrix.server_version }}

TLS-OFF:
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
uses: ./.github/workflows/build-test.yml
name: "No TLS"
with:
tls: OFF

older-cc:
strategy:
fail-fast: false
matrix:
compiler: [gcc-7, gcc-8, clang-8]
uses: ./.github/workflows/build-test.yml
name: "Older compilers"
with:
ubuntu_version: 20.04
compiler: ${{ matrix.compiler }}

no-streaming:
uses: ./.github/workflows/build-test.yml
name: "No Streaming"
with:
streaming: OFF

coverage:
name: "Coverage"
uses: ./.github/workflows/build-test.yml
with:
coverage: ON
server_version: main
type: Debug
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/on-push-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: "Release"
on:
push:

permissions:
contents: write # required by build-test to comment on coverage but not used here.

defaults:
run:
shell: bash --noprofile --norc -x -eo pipefail {0}

jobs:
quick:
name: "DefaultR"
strategy:
fail-fast: false
matrix:
compiler: [gcc, clang]
ubuntu_version: [latest, 20.04]
uses: ./.github/workflows/build-test.yml
with:
server_version: main
ubuntu_version: ${{ matrix.ubuntu_version }}
compiler: ${{ matrix.compiler }}
repeat: 3
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Compiled Object files, Static and Dynamic libs (Shared Objects)
*.a
*.so
*.dylib
*.gcov

# Folders
build*/
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(CTest)
include(FindPackageHandleStandardArgs)

# Uncomment to have the build process verbose
#set(CMAKE_VERBOSE_MAKEFILE TRUE)
# set(CMAKE_VERBOSE_MAKEFILE TRUE)

# Uncomment to have the executable moved to 'build' instead of their respective 'build/xxx' directories
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
Expand Down
19 changes: 19 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ignore:
- "test/**"
- "examples/**"
- "src/win/**"
- "src/unix/**"
- "src/stan/protocol.pb-c.c"
coverage:
precision: 2
round: down
range: "60...75"
status:
project:
default:
target: 65%
threshold: 1%
github_checks:
annotations: true
comment:
require_changes: false
Loading