Skip to content

ci: scope down GitHub Token permissions #932

ci: scope down GitHub Token permissions

ci: scope down GitHub Token permissions #932

Workflow file for this run

name: ODBC Driver for Linux
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
env:
CI_OUTPUT_PATH: "ci-output"
ODBC_LIB_PATH: "${{github.workspace}}/build/odbc/lib"
ODBC_BIN_PATH: "${{github.workspace}}/build/odbc/bin"
ODBC_BUILD_PATH: "${{github.workspace}}/build/odbc/build"
DOCUMENTDB_HOME: "${{github.workspace}}/build/odbc/bin"
DOC_DB_KEYPAIR: ${{secrets.DOC_DB_KEYPAIR}}
DOC_DB_USER_NAME: ${{secrets.DOC_DB_USER_NAME}}
DOC_DB_PASSWORD: ${{secrets.DOC_DB_PASSWORD}}
DOC_DB_USER: ${{secrets.DOC_DB_USER}}
DOC_DB_HOST: ${{secrets.DOC_DB_HOST}}
DOC_DB_LOCAL_PORT: 27019
DOC_DB_REMOTE_PORT: 27017
DOC_DB_PRIV_KEY_FILE: ~/certs/docdb-sshtunnel.pem
DOC_DB_ODBC_INTEGRATION_TEST: 1
DOC_DB_LOG_PATH: "${{github.workspace}}/build/odbc/logs"
DOC_DB_LOG_LEVEL: "debug"
JAVA_HOME: "/usr/lib/jvm/java-17-amazon-corretto/"
permissions:
contents: write
checks: write
pull-requests: write
jobs:
build-linux64:
runs-on: ubuntu-20.04
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }}
steps:
- uses: actions/checkout@v2
- name: Get Java distribution
run: |
sudo apt-get -y install software-properties-common
wget -O- https://apt.corretto.aws/corretto.key | sudo apt-key add -
sudo apt-add-repository 'deb https://apt.corretto.aws stable main'
sudo apt-get update
sudo apt-get install -y java-17-amazon-corretto-jdk
- name: Get latest version of CMake
uses: lukka/get-cmake@latest
- name: run-cppcheck
run: |
sudo apt install cppcheck
sh run_cppcheck.sh
- name: upload-cppcheck-results
if: failure()
uses: actions/upload-artifact@v2
with:
name: cppcheck-results
path: cppcheck-results.log
- name: Extract key-pair into file
run: |
mkdir ~/certs
echo "${{env.DOC_DB_KEYPAIR}}" > ${{env.DOC_DB_PRIV_KEY_FILE}}
chmod 400 ${{env.DOC_DB_PRIV_KEY_FILE}}
- name: get-dependencies
if: success()
run: |
sudo apt update
sudo apt install libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libpulse-dev linux-headers-$(uname -r) gcc gcc-multilib g++ g++-multilib linux-headers-$(uname -r) build-essential valgrind libboost-all-dev libbson-dev libsasl2-dev lcov
- name: Update environment with JDBC_DRIVER_VERSION
run: |
read -r JDBC_DRIVER_VERSION < ./src/JDBC_DRIVER_VERSION.txt
echo "JDBC_DRIVER_VERSION=$JDBC_DRIVER_VERSION" >> $GITHUB_ENV
- name: Cache DocumentDB JDBC JAR
id: cache-documentdb-jdbc-jar
uses: actions/cache@v3
with:
path: |
cache/jar
key: cache-documentdb-jdbc-jar-${{env.JDBC_DRIVER_VERSION}}
- name: Download DocumentDB JDBC JAR
if: steps.cache-documentdb-jdbc-jar.outputs.cache-hit != 'true'
run: |
mkdir -p cache/jar
cd cache/jar
wget https://github.com/aws/amazon-documentdb-jdbc-driver/releases/download/v${{env.JDBC_DRIVER_VERSION}}/documentdb-jdbc-${{env.JDBC_DRIVER_VERSION}}-all.jar
- name: Install DocumentDB JDBC JAR
run: |
mkdir -p ${{env.ODBC_BIN_PATH}}/libs
cp cache/jar/documentdb-jdbc-${{env.JDBC_DRIVER_VERSION}}-all.jar ${{env.ODBC_BIN_PATH}}/libs
- name: build-and-install-mongocxx
run: |
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.21.1/mongo-c-driver-1.21.1.tar.gz
tar xzf mongo-c-driver-1.21.1.tar.gz
cd mongo-c-driver-1.21.1
mkdir -p cmake-build
cd cmake-build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
sudo make install
cd ../..
git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_MNMLSTC=1 -DCMAKE_INSTALL_PREFIX=/usr/local
sudo make install
- name: install-mongocxx
run: |
cd mongo-c-driver-1.21.1/cmake-build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
sudo make
sudo make install
cd ../../
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_MNMLSTC=1 -DCMAKE_INSTALL_PREFIX=/usr/local
sudo make
sudo make install
# TODO enable clang-tidy-check
# https://github.com/aws/amazon-documentdb-odbc-driver/issues/169
# generate compile_commands.json file for clang-tidy-check, requires mongocxx and boost dependencies
# - name: generate-compile-commands-file
# run: |
# cmake "${{github.workspace}}/src" -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE="OFF" -DBUILD_SHARED_LIBS="OFF" -DWITH_TESTS="ON" -DWITH_ODBC="ON"
# - name: clang-tidy-check
# uses: ZedThree/[email protected]
# id: review
# with:
# If there are any comments, fail the check
# - if: steps.review.outputs.total_comments > 0
# run: exit 1
- name: configure-and-build-driver
run: |
chmod +x build_linux_release64_deb.sh
./build_linux_release64_deb.sh
- name: register-odbc-driver
run: |
chmod +r -R ${{env.ODBC_LIB_PATH}}
chmod +x scripts/register_driver_unix.sh
sudo bash scripts/register_driver_unix.sh
- name: set-up-local-mongodb
run: |
docker run --name mongo -e MONGO_INITDB_ROOT_USERNAME=${{env.DOC_DB_USER_NAME}} -e MONGO_INITDB_ROOT_PASSWORD=${{env.DOC_DB_PASSWORD}} -d -p 27017:27017 mongo:latest
chmod +x ./src/odbc-test/scripts/import_test_data.sh
./src/odbc-test/scripts/import_test_data.sh
- name: run-tests
id: runtests
run: |
mkdir -p "${{env.DOC_DB_LOG_PATH}}"
ssh -f -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${{env.DOC_DB_PRIV_KEY_FILE}} -L${{env.DOC_DB_LOCAL_PORT}}:${{secrets.DOC_DB_HOST}}:${{env.DOC_DB_REMOTE_PORT}} ${{secrets.DOC_DB_USER}}
./build/odbc/bin/documentdb-odbc-tests --catch_system_errors=false
- name: upload-test-report
if: always()
uses: EnricoMi/publish-unit-test-result-action/[email protected]
with:
check_name: "Ubuntu 20.04 Build Unit Test Results Check"
comment_title: "Ubuntu 20.04 Build Unit Test Results"
files: ./odbc_test_result.xml
- name: upload-test-file
if: always() && (steps.runtests.outcome == 'failure')
uses: actions/upload-artifact@v2
with:
name: odbc-test-results
path: |
./odbc_test_result.xml
./build/odbc/logs/docdb_odbc_*.log
build-linux64-debug:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Get Java distribution
run: |
sudo apt-get -y install software-properties-common
wget -O- https://apt.corretto.aws/corretto.key | sudo apt-key add -
sudo apt-add-repository 'deb https://apt.corretto.aws stable main'
sudo apt-get update
sudo apt-get install -y java-17-amazon-corretto-jdk
pip install gcovr
- name: Get latest version of CMake
uses: lukka/get-cmake@latest
- name: run-cppcheck
run: |
sudo apt install cppcheck
sh run_cppcheck.sh
- name: upload-cppcheck-results
if: failure()
uses: actions/upload-artifact@v2
with:
name: cppcheck-results
path: cppcheck-results.log
- name: Extract key-pair into file
run: |
mkdir ~/certs
echo "${{env.DOC_DB_KEYPAIR}}" > ${{env.DOC_DB_PRIV_KEY_FILE}}
chmod 400 ${{env.DOC_DB_PRIV_KEY_FILE}}
- name: get-dependencies
if: success()
run: |
sudo apt update
sudo apt install libcurl4-openssl-dev libssl-dev uuid-dev zlib1g-dev libpulse-dev linux-headers-$(uname -r) gcc gcc-multilib g++ g++-multilib linux-headers-$(uname -r) build-essential valgrind libboost-all-dev libbson-dev libsasl2-dev lcov
- name: Update environment with JDBC_DRIVER_VERSION
run: |
read -r JDBC_DRIVER_VERSION < ./src/JDBC_DRIVER_VERSION.txt
echo "JDBC_DRIVER_VERSION=$JDBC_DRIVER_VERSION" >> $GITHUB_ENV
- name: Cache DocumentDB JDBC JAR
id: cache-documentdb-jdbc-jar
uses: actions/cache@v3
with:
path: |
cache/jar
key: cache-documentdb-jdbc-jar-${{env.JDBC_DRIVER_VERSION}}
- name: Download DocumentDB JDBC JAR
if: steps.cache-documentdb-jdbc-jar.outputs.cache-hit != 'true'
run: |
mkdir -p cache/jar
cd cache/jar
wget https://github.com/aws/amazon-documentdb-jdbc-driver/releases/download/v${{env.JDBC_DRIVER_VERSION}}/documentdb-jdbc-${{env.JDBC_DRIVER_VERSION}}-all.jar
- name: Install DocumentDB JDBC JAR
run: |
mkdir -p ${{env.ODBC_BIN_PATH}}/libs
cp cache/jar/documentdb-jdbc-${{env.JDBC_DRIVER_VERSION}}-all.jar ${{env.ODBC_BIN_PATH}}/libs
- name: build-and-install-mongocxx
run: |
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.21.1/mongo-c-driver-1.21.1.tar.gz
tar xzf mongo-c-driver-1.21.1.tar.gz
cd mongo-c-driver-1.21.1
mkdir -p cmake-build
cd cmake-build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
sudo make install
cd ../..
git clone https://github.com/mongodb/mongo-cxx-driver.git --branch releases/stable --depth 1
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_MNMLSTC=1 -DCMAKE_INSTALL_PREFIX=/usr/local
sudo make install
- name: install-mongocxx
run: |
cd mongo-c-driver-1.21.1/cmake-build
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF ..
sudo make
sudo make install
cd ../../
cd mongo-cxx-driver/build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_MNMLSTC=1 -DCMAKE_INSTALL_PREFIX=/usr/local
sudo make
sudo make install
# TODO enable clang-tidy-check
# https://github.com/aws/amazon-documentdb-odbc-driver/issues/169
# generate compile_commands.json file for clang-tidy-check, requires mongocxx and boost dependencies
# - name: generate-compile-commands-file
# run: |
# cmake "${{github.workspace}}/src" -DCMAKE_EXPORT_COMPILE_COMMANDS=on -DCMAKE_BUILD_TYPE=Release -DCODE_COVERAGE="OFF" -DBUILD_SHARED_LIBS="OFF" -DWITH_TESTS="ON" -DWITH_CORE="OFF" -DWITH_ODBC="ON"
# - name: clang-tidy-check
# uses: ZedThree/[email protected]
# id: review
# with:
# If there are any comments, fail the check
# - if: steps.review.outputs.total_comments > 0
# run: exit 1
- name: configure-and-build-driver
run: |
chmod +x build_linux_debug64.sh
./build_linux_debug64.sh
- name: register-odbc-driver
run: |
chmod +r -R ${{env.ODBC_LIB_PATH}}
chmod +x scripts/register_driver_unix.sh
sudo bash scripts/register_driver_unix.sh
- name: set-up-local-mongodb
run: |
docker run --name mongo -e MONGO_INITDB_ROOT_USERNAME=${{env.DOC_DB_USER_NAME}} -e MONGO_INITDB_ROOT_PASSWORD=${{env.DOC_DB_PASSWORD}} -d -p 27017:27017 mongo:latest
chmod +x ./src/odbc-test/scripts/import_test_data.sh
./src/odbc-test/scripts/import_test_data.sh
- name: run-tests
id: runtests
run: |
mkdir -p "${{env.DOC_DB_LOG_PATH}}"
ssh -f -N -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${{env.DOC_DB_PRIV_KEY_FILE}} -L${{env.DOC_DB_LOCAL_PORT}}:${{secrets.DOC_DB_HOST}}:${{env.DOC_DB_REMOTE_PORT}} ${{secrets.DOC_DB_USER}}
./build/odbc/bin/documentdb-odbc-tests --catch_system_errors=false
gcovr --exclude-directories cmake-build64/odbc-test/CMakeFiles/documentdb-odbc-tests.dir$ --cobertura --output coverage.cobertura.xml
- name: Update Repository Before Commit Badge
run: |
git pull
- name: Code Coverage Badge
uses: irongut/[email protected]
with:
filename: coverage.cobertura.xml
badge: true
format: text
indicators: true
output: both
- name: Extract Code Coverage Badge
run: |
COVERAGE_BADGE=$(head -1 code-coverage-results.txt )
COVERAGE_BADGE="${COVERAGE_BADGE/'Code%20Coverage'/'Linux%20Code%20Coverage'}"
curl $COVERAGE_BADGE > .github/badges/coverage_badge_linux.svg
- name: Commit Coverage Badge
if: github.event_name == 'pull_request'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_options: '--allow-empty --no-verify'
commit_message: Commit Code Coverage Badge
file_pattern: '*.svg'
skip_fetch: true
skip_dirty_check: true
- name: Code Coverage Summary Report
uses: irongut/[email protected]
with:
filename: coverage.cobertura.xml
badge: true
format: markdown
indicators: true
output: both
- name: Add Header for Code Coverage Summary Report
run: |
echo "## Ubuntu 20.04 Debug Build Unit Test Results Check" > coverage-cobertura.md
cat code-coverage-results.md >> coverage-cobertura.md
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
header: linux
recreate: true
path: coverage-cobertura.md
- name: upload-test-report
if: always()
uses: EnricoMi/publish-unit-test-result-action/[email protected]
with:
check_name: "Ubuntu 20.04 Debug Build Unit Test Results Check"
comment_title: "Ubuntu 20.04 Debug Build Unit Test Results"
files: ./odbc_test_result.xml
- name: upload-test-file
if: always() && (steps.runtests.outcome == 'failure')
uses: actions/upload-artifact@v3
with:
name: odbc-test-results-linux-debug
path: |
./odbc_test_result.xml
./build/odbc/logs/docdb_odbc_*.log
- name: upload-coverage
if: always()
uses: actions/upload-artifact@v3
with:
name: code-coverage-Linux
path: cmake-build64/ccov/all-merged
build-linux-docker-image:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: build-image
run: |
cd docker/linux-environment
docker build -t documentdb-dev-linux .
# TODO Linux build enhacements
# https://github.com/aws/amazon-documentdb-odbc-driver/issues/170