Skip to content

Commit 328e80a

Browse files
authored
test(github-actions): migrate tests to GitHub Actions (#145)
test(github-actions): migrate tests to GitHub Actions Migrate PubNub SDK test suite from Travis to GitHub Actions. fix(build): fix 'clean' targets Fix issue because of which `clean` target always exited with error.
1 parent 572b063 commit 328e80a

File tree

20 files changed

+380
-283
lines changed

20 files changed

+380
-283
lines changed

.github/workflows/commands-handler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout repository
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v3
1515
with:
1616
token: ${{ secrets.GH_TOKEN }}
1717
- name: Checkout release actions
18-
uses: actions/checkout@v2
18+
uses: actions/checkout@v3
1919
with:
2020
repository: pubnub/client-engineering-deployment-tools
2121
ref: v1
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
name: Tests runner
3+
description: Unit and integration tests runner for multiple compiler types.
4+
author: PubNub
5+
inputs:
6+
os:
7+
description: Environment in which framework should be built.
8+
required: true
9+
version:
10+
description: "Which version of 'cgreen' should be built."
11+
required: true
12+
pubNubPubKey:
13+
description: "PubNub publish keys which should be used with integration tests"
14+
required: true
15+
pubNubSubKey:
16+
description: "PubNub subscribe keys which should be used with integration tests"
17+
required: true
18+
19+
runs:
20+
using: "composite"
21+
steps:
22+
- name: Prepare environments
23+
shell: bash
24+
run: |
25+
echo "PUBNUB_PUBKEY=${{ inputs.pubNubPubKey }}" >> $GITHUB_ENV
26+
echo "PUBNUB_KEYSUB=${{ inputs.pubNubSubKey }}" >> $GITHUB_ENV
27+
- name: Pull Unit Test framework ('${{ inputs.os }}' gcc, clang)
28+
uses: ./.github/workflows/composite/unit-test-framework
29+
with:
30+
os: ${{ inputs.os }}
31+
version: ${{ inputs.version }}
32+
compilers: gcc,clang
33+
- name: Prepare Unit Test framework ('${{ inputs.os }}' gcc)
34+
shell: bash
35+
run: |
36+
mv "$GITHUB_WORKSPACE/cgreen" "$GITHUB_WORKSPACE/cgreen-universal"
37+
cp -r "$GITHUB_WORKSPACE/cgreen-universal/gcc" "$GITHUB_WORKSPACE/cgreen"
38+
- name: Run unit tests ('${{ inputs.os }}' gcc)
39+
shell: bash
40+
env:
41+
CC: gcc
42+
CXX: "g++"
43+
run: .github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh ${{ inputs.os }}
44+
- name: Run integration tests ('${{ inputs.os }}' gcc)
45+
shell: bash
46+
env:
47+
CC: gcc
48+
CXX: "g++"
49+
run: .github/workflows/composite/unit-integration-test-runner/run-integration-tests.sh ${{ inputs.os }}
50+
- name: Prepare Unit Test framework ('${{ inputs.os }}' clang)
51+
shell: bash
52+
run: |
53+
rm -rf "$GITHUB_WORKSPACE/cgreen"
54+
cp -r "$GITHUB_WORKSPACE/cgreen-universal/clang" "$GITHUB_WORKSPACE/cgreen"
55+
- name: Run unit tests ('${{ inputs.os }}' clang)
56+
shell: bash
57+
env:
58+
CC: clang
59+
CXX: "clang++"
60+
run: .github/workflows/composite/unit-integration-test-runner/run-unit-tests.sh ${{ inputs.os }}
61+
- name: Run integration tests ('${{ inputs.os }}' clang)
62+
shell: bash
63+
env:
64+
CC: clang
65+
CXX: "clang++"
66+
run: .github/workflows/composite/unit-integration-test-runner/run-integration-tests.sh ${{ inputs.os }}
67+
- name: Restore Unit Test framework ('${{ inputs.os }}' gcc,clang)
68+
shell: bash
69+
run: |
70+
rm -rf "$GITHUB_WORKSPACE/cgreen"
71+
cp -r "$GITHUB_WORKSPACE/cgreen-universal" "$GITHUB_WORKSPACE/cgreen"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
INFO_BG="\033[0m\033[48;2;5;49;70m"
4+
INFO_FG="\033[38;2;19;181;255m"
5+
BOLD_INFO_FG="${INFO_FG}\033[1m"
6+
SUCCESS_BG="\033[0m\033[48;2;30;69;1m"
7+
SUCCESS_FG="\033[38;2;95;215;0m"
8+
BOLD_SUCCESS_FG="${SUCCESS_FG}\033[1m"
9+
CLEAR="\033[0m"
10+
11+
echo "::group::Run integration tests ('$1' $CC / $CXX)"
12+
cd "$GITHUB_WORKSPACE"
13+
14+
if ! build="$(make -f posix.mk clean all 2>&1)"; then
15+
echo "::error file=posix.mk::Unable to build test suite: $build"
16+
exit 1
17+
else
18+
echo -e "${SUCCESS_BG}Test suit is built 🎉${CLEAR}"
19+
fi
20+
21+
[[ "$build" =~ "deprecated" ]] && echo "::warning title=deprecated::There is deprecated functions used in code."
22+
[[ "$build" =~ "not used" ]] && echo "::warning title=unused::There is unused variables and / or functions in code."
23+
24+
echo -e "${INFO_BG}${INFO_FG}Running ${BOLD_INFO_FG}POSIX ${INFO_BG}${INFO_FG}integration tests...${CLEAR}"
25+
posix/pubnub_fntest
26+
echo -e "${SUCCESS_BG}${BOLD_SUCCESS_FG}POSIX ${SUCCESS_BG}${SUCCESS_FG}integration tests completed 🎉${CLEAR}"
27+
echo -e "${INFO_BG}${INFO_FG}Running ${BOLD_INFO_FG}OpenSSL ${INFO_BG}${INFO_FG}integration tests${CLEAR}"
28+
openssl/pubnub_fntest
29+
echo -e "${SUCCESS_BG}${BOLD_SUCCESS_FG}POSIX ${SUCCESS_BG}${SUCCESS_FG}integration tests completed 🎉${CLEAR}"
30+
echo -e "${INFO_BG}${INFO_FG}Running ${BOLD_INFO_FG}C++ ${INFO_BG}${INFO_FG}integration tests${CLEAR}"
31+
cpp/fntest_runner
32+
echo -e "${SUCCESS_BG}${BOLD_SUCCESS_FG}POSIX ${SUCCESS_BG}${SUCCESS_FG}integration tests completed 🎉${CLEAR}"
33+
echo -e "${INFO_BG}${INFO_FG}Running ${BOLD_INFO_FG}C++ OpenSSL ${INFO_BG}${INFO_FG}integration tests${CLEAR}"
34+
cpp/openssl/fntest_runner
35+
echo -e "${SUCCESS_BG}${BOLD_SUCCESS_FG}POSIX ${SUCCESS_BG}${SUCCESS_FG}integration tests completed 🎉${CLEAR}"
36+
echo "::endgroup::"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
echo "::group::Run unit tests ('$1' $CC / $CXX)"
4+
cd "$GITHUB_WORKSPACE/core"
5+
make clean generate_report
6+
cd "$GITHUB_WORKSPACE/lib"
7+
make clean generate_report
8+
echo "::endgroup::"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: Unit Test and Mocking framework
3+
description: Manage unit test framework build and cache so it can be used with jobs.
4+
author: PubNub
5+
inputs:
6+
os:
7+
description: Environment in which framework should be built.
8+
required: true
9+
version:
10+
description: "Which version of 'cgreen' should be built."
11+
required: true
12+
compilers:
13+
description: "Coma-separated list of currently supported C compilers to be used during build (gcc, clang)."
14+
required: true
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- name: Build and Cache Unit Test framework ('${{ inputs.os }}' ${{ inputs.compilers }})
20+
id: unit-test-framework
21+
uses: actions/cache@v3
22+
with:
23+
path: |
24+
cgreen
25+
key: ${{ inputs.os }}-cgreen-${{ inputs.version }}-1
26+
restore-keys: |
27+
${{ inputs.os }}-cgreen-${{ inputs.version }}-
28+
- name: Checkout Unit Test framework
29+
if: steps.unit-test-framework.outputs.cache-hit != 'true'
30+
uses: actions/checkout@v3
31+
with:
32+
repository: cgreen-devs/cgreen
33+
ref: ${{ matrix.cgreen }}
34+
path: cgreen
35+
- name: Build Unit Test frameworks
36+
if: steps.unit-test-framework.outputs.cache-hit != 'true'
37+
shell: bash
38+
run: .github/workflows/composite/unit-test-framework/build-framework.sh ${{ inputs.os }} ${{ inputs.compilers }}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Identify make tool which depends from environment.
4+
[[ $1 =~ (ubuntu|macos) ]] && MAKE_TOOL=make || MAKE_TOOL=$(MAKE)
5+
6+
# Iterating over list of passed compilers.
7+
for compiler in ${2//,/ }
8+
do
9+
# Navigate to unit test framework source folder.
10+
cd "$GITHUB_WORKSPACE/cgreen"
11+
12+
# Clean up previous build results.
13+
[[ -d build ]] && $MAKE_TOOL clean && rm -rf build
14+
15+
echo "::group::Build unit test framework ('$1' $compiler)"
16+
if [[ $1 =~ (ubuntu|macos) ]]; then
17+
export CC="$compiler"
18+
[[ $compiler == "gcc" ]] && export CXX="g++" || export CXX="$compiler++"
19+
else
20+
echo "::warning title=compiler flags::Here should be some setup for Windows compiler"
21+
fi
22+
23+
echo "::notice title=cgreen::Prepare folders structure"
24+
! [[ -d "$GITHUB_WORKSPACE/cgreen-tmp/$compiler" ]] &&
25+
mkdir -p "$GITHUB_WORKSPACE/cgreen-tmp/$compiler"
26+
mkdir -p build && cd build
27+
28+
# Enable 'gcov' only for build on Ubuntu.
29+
[[ "$1" == "ubuntu" ]] && WITH_GCOV=ON || WITH_GCOV=OFF
30+
if [[ "$WITH_GCOV" == ON ]]; then
31+
echo "::notice title=gcov::Installing 'gcov' for code coverage."
32+
if ! install="$(pip install --user gcovr)"; then
33+
echo "::error title=gcov::Unable to install 'gcov':$install"
34+
else
35+
echo "::notice title=gcov::Installing 'gcov' for code coverage."
36+
fi
37+
else
38+
echo "::warning title=gcov::'gcov' doesn't work as expected on $1."
39+
echo "::warning title=gcov::Configure 'cgreen' without 'gcov' support"
40+
fi
41+
42+
echo "::notice title=cgreen::Configure 'cgreen' build"
43+
cmake -E env LDFLAGS="-lm" cmake -DCGREEN_INTERNAL_WITH_GCOV:BOOL=$WITH_GCOV ..
44+
45+
echo "::notice title=cgreen::Build 'cgreen' framework"
46+
make -j2
47+
48+
echo "::notice::Move built results to compiler specific colder"
49+
mv "$GITHUB_WORKSPACE/cgreen/build" "$GITHUB_WORKSPACE/cgreen-tmp/$compiler/build"
50+
cp -r "$GITHUB_WORKSPACE/cgreen/include" "$GITHUB_WORKSPACE/cgreen-tmp/$compiler/include"
51+
52+
# Clean up configured environments.
53+
unset CC && unset CXX
54+
echo "::endgroup::"
55+
done
56+
57+
echo "::notice title=cgreen::Prepare files for caching"
58+
rm -rf "$GITHUB_WORKSPACE/cgreen"
59+
mv "$GITHUB_WORKSPACE/cgreen-tmp" "$GITHUB_WORKSPACE/cgreen"

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ jobs:
1515
release: ${{ steps.check.outputs.ready }}
1616
steps:
1717
- name: Checkout actions
18-
uses: actions/checkout@v2
18+
uses: actions/checkout@v3
1919
with:
2020
repository: pubnub/client-engineering-deployment-tools
2121
ref: v1
2222
token: ${{ secrets.GH_TOKEN }}
2323
path: .github/.release/actions
24-
- id: check
25-
name: Check pre-release completed
24+
- name: Check pre-release completed
25+
id: check
2626
uses: ./.github/.release/actions/actions/checks/release
2727
with:
2828
token: ${{ secrets.GH_TOKEN }}
2929
publish:
3030
name: Publish package
31-
runs-on: macos-11
31+
runs-on: ubuntu-latest
3232
needs: check-release
3333
if: ${{ needs.check-release.outputs.release == 'true' }}
3434
steps:
3535
- name: Checkout repository
36-
uses: actions/checkout@v2
36+
uses: actions/checkout@v3
3737
with:
3838
# This should be the same as the one specified for on.pull_request.branches
3939
ref: master

.github/workflows/run-tests.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Tests
2+
3+
concurrency:
4+
group: ${{ github.ref }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
workflow_dispatch:
10+
11+
12+
jobs:
13+
tests-ubuntu:
14+
name: Integration and Unit tests (Ubuntu)
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout project
18+
uses: actions/checkout@v3
19+
with:
20+
token: ${{ secrets.GH_TOKEN }}
21+
- name: Build and run tests
22+
uses: ./.github/workflows/composite/unit-integration-test-runner
23+
with:
24+
os: ubuntu
25+
version: 1.6.0
26+
pubNubPubKey: ${{ secrets.PUBNUB_PUBKEY }}
27+
pubNubSubKey: ${{ secrets.PUBNUB_KEYSUB }}
28+
tests-macos:
29+
name: Integration and Unit tests (macOS)
30+
runs-on: macos-latest
31+
steps:
32+
- name: Checkout project
33+
uses: actions/checkout@v3
34+
with:
35+
token: ${{ secrets.GH_TOKEN }}
36+
- name: Build and run tests
37+
uses: ./.github/workflows/composite/unit-integration-test-runner
38+
with:
39+
os: macos
40+
version: 1.6.0
41+
pubNubPubKey: ${{ secrets.PUBNUB_PUBKEY }}
42+
pubNubSubKey: ${{ secrets.PUBNUB_KEYSUB }}
43+
acceptance:
44+
name: Acceptance tests
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Setup environment
48+
shell: bash
49+
run: |
50+
sudo apt-get install -y ninja-build libboost-all-dev libssl-dev
51+
sudo gem install cucumber
52+
- name: Checkout project
53+
uses: actions/checkout@v3
54+
with:
55+
token: ${{ secrets.GH_TOKEN }}
56+
- name: Checkout mock-server action
57+
uses: actions/checkout@v3
58+
with:
59+
repository: pubnub/client-engineering-deployment-tools
60+
ref: v1
61+
token: ${{ secrets.GH_TOKEN }}
62+
path: .github/.release/actions
63+
- name: Run mock server action
64+
uses: ./.github/.release/actions/actions/mock-server
65+
with:
66+
token: ${{ secrets.GH_TOKEN }}
67+
- name: Pull Cucumber cache
68+
id: cucumber-cpp
69+
uses: actions/cache@v3
70+
with:
71+
path: |
72+
cucumber-cpp
73+
key: ${{ runner.os }}-cucumber-cpp-c79100eb70fbb34f6ea10030cec051c2cc9f7961
74+
restore-keys: |
75+
${{ runner.os }}-cucumber-cpp-
76+
- name: Checkout Cucumber
77+
if: steps.cucumber-cpp.outputs.cache-hit != 'true'
78+
uses: actions/checkout@v3
79+
with:
80+
repository: cucumber/cucumber-cpp
81+
ref: c79100eb70fbb34f6ea10030cec051c2cc9f7961
82+
path: cucumber-cpp-src
83+
- name: Build Cucumber
84+
if: steps.cucumber-cpp.outputs.cache-hit != 'true'
85+
shell: bash
86+
run: |
87+
cd ./cucumber-cpp-src
88+
cmake -B build -DCMAKE_BUILD_TYPE=Debug
89+
cmake --build build --config Debug
90+
cd "$GITHUB_WORKSPACE"
91+
mkdir -p cucumber-cpp
92+
mv cucumber-cpp-src/build cucumber-cpp/build
93+
mv cucumber-cpp-src/include cucumber-cpp/include
94+
rm -rf cucumber-cpp-src
95+
- name: Build acceptance tests
96+
shell: bash
97+
run: |
98+
cd cpp
99+
make -f posix_openssl.mk openssl/pubnub_sync
100+
cd "$GITHUB_WORKSPACE"
101+
g++ -std=c++11 -g -o BoostSteps.o -c features/step_definitions/BoostSteps.cpp -Icucumber-cpp/include -Icucumber-cpp/build/src/ -Iposix -Icore -I. -Icpp -D PUBNUB_CRYPTO_API=1 -D PUBNUB_USE_SSL=0
102+
g++ -o steps BoostSteps.o cpp/pubnub_sync.a cucumber-cpp/build/src/libcucumber-cpp.a -Lboost -lboost_unit_test_framework -lpthread -lboost_regex -lboost_thread -lboost_program_options -lboost_filesystem -lssl -lcrypto -D PUBNUB_USE_SSL=0
103+
- name: Run acceptance tests
104+
shell: bash
105+
env:
106+
PAM_PUB_KEY: "pub_key"
107+
PAM_SUB_KEY: "sub_key"
108+
PAM_SEC_KEY: "sec_key"
109+
run: |
110+
mv sdk-specifications/features/access features
111+
sudo python3 run_contract_tests.py features/access/grant-token.feature
112+
sudo python3 run_contract_tests.py features/access/revoke-token.feature
113+
ls -la results
114+
- name: Expose acceptance tests reports
115+
if: always()
116+
uses: actions/upload-artifact@v3
117+
with:
118+
name: acceptance-test-reports
119+
path: ./results/**
120+
retention-days: 7

0 commit comments

Comments
 (0)