Skip to content

Add argument: -opts #119

Add argument: -opts

Add argument: -opts #119

# Build CCGL library on native C++11 with GDAL and mongo-c-driver, generate Doxygen documents, generate code coverage, run test with CMake, and deploy docker image
name: Build and deploy with GDAL and MongoDB
on:
push:
branches:
- 'master'
- 'dev'
pull_request:
workflow_dispatch:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
# Container registry domain, and a name for the Docker image that this workflow builds.
# IMAGE_NAME: ${{ github.repository }} ==> crazyzlj/ccgl
IMAGE_NAME: ccgl
# github container registry
REGISTRY: ghcr.io
NAMESPACE: ${{ github.repository_owner }}
# aliyun ACR
REGION_ID_ACR: cn-hangzhou
REGISTRY_ACR: registry.cn-hangzhou.aliyuncs.com
LOGIN_SERVER: https://registry.cn-hangzhou.aliyuncs.com
NAMESPACE_ACR: ljzhu-geomodels
DOCKERFILE_NAME: Dockerfile.alpine-with-gdal-mongodb
# IMAGE_TAG: ${{ github.sha }}
IMAGE_TAG: ${{ github.ref == 'refs/heads/master' && 'alpine-with-gdal-mongodb' || 'dev-alpine-with-gdal-mongodb' }}
jobs:
build-linux:
# Check GitHub Actions runner images versions: https://github.com/actions/runner-images
runs-on: ubuntu-22.04
services:
mongodb:
image: mongo
ports:
- 27017:27017
steps:
- name: Checkout CCGL
uses: actions/checkout@v4
- name: Install GDAL and mongo-c-driver
run: sudo apt-get update && sudo apt-get install -qq gdal-bin libgdal-dev libmongoc-1.0-0 libmongoc-dev lcov
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUNITTEST=1 -DCODE_COVERAGE=1
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 4
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} --rerun-failed --output-on-failure
- name: Code coverage
working-directory: ${{github.workspace}}/build
run: make ccov-unittest
- name: Upload to CodeCov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ${{github.workspace}}/build/ccov/unittest.info
flags: unittest # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
- name: Build Doc
uses: mattnotmitt/[email protected]
with:
working-directory: '.'
doxyfile-path: 'doc/Doxyfile.in'
- name: Build Doc in Chinese
uses: mattnotmitt/[email protected]
with:
working-directory: '.'
doxyfile-path: 'doc/Doxyfile.zh-cn.in'
- name: Deploy Doc
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
commit_message: ${{ github.event.head_commit.message }}
publish_branch: gh-pages
force_orphan: true
publish_dir: html
deploy-linux:
needs: build-linux
runs-on: ubuntu-22.04
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
# permissions: write-all
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- uses: actions/checkout@v4
# login alibaba Container Registry
- name: Login to ACR
uses: aliyun/acr-login@v1
with:
login-server: ${{ env.LOGIN_SERVER }}
region-id: ${{ env.REGION_ID_ACR }}
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
# login ghcr.io
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }}
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
file: ./docker/${{ env.DOCKERFILE_NAME }}
push: true
platforms: linux/amd64,linux/arm64
provenance: false
tags: |
${{ env.REGISTRY_ACR }}/${{ env.NAMESPACE_ACR }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
${{ env.REGISTRY }}/${{ env.NAMESPACE }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-windows:
runs-on: windows-2019
steps:
- name: Checkout CCGL
uses: actions/checkout@v4
- name: Find mongod.exe
run: where.exe mongod.exe
# C:\Program Files\MongoDB\Server\5.0\bin\mongod.exe
- name: Start MongoDB Service
# How to start MongoDB as a service on Windows runners
# https://github.com/orgs/community/discussions/30083#discussioncomment-3448499
shell: pwsh
run: |
Set-Service mongodb -StartupType Automatic
Start-Service -Name mongodb
- name: Download mongo-c-driver
# Build mongo-c-driver is time-consuming, I moved it to another repo. https://github.com/crazyzlj/Github_Actions_Precompiled_Packages
# run: ${{github.workspace}}\.github\workflows\build_mongo-c-driver.ps1
# Instead, download the prebuilt library directly.
id: pwshdownmongo
shell: pwsh
run: |
cd ${{github.workspace}}\.github\workflows
./download_mongo-c-driver.ps1 -mongoCPath ${{github.workspace}}/mongolib
Get-ChildItem Env: | Where-Object {$_.Name -Match "^MONGO"} | %{ echo "$($_.Name)=$($_.Value)" >> $env:GITHUB_ENV }
- name: Download GDAL
id: pwshdowngdal
shell: pwsh
run: |
cd ${{github.workspace}}\.github\workflows
./download_gdal.ps1 -gdalPath ${{github.workspace}}\gdallib
Get-ChildItem Env: | Where-Object {$_.Name -Match "^GDAL"} | %{ echo "$($_.Name)=$($_.Value)" >> $env:GITHUB_ENV }
- name: Configure CMake
shell: cmd
run: |
cmake -G "Visual Studio 16 2019" -A x64 -B ${{github.workspace}}/build ^
-DGDAL_ROOT=${{ env.GDAL_ROOT }} ^
-DMONGOC_ROOT=${{ env.MONGOC_ROOT }} ^
-DUNITTEST=1
- name: Build
shell: cmd
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- /m:4
- name: Test
shell: cmd
working-directory: ${{github.workspace}}/build
# Set Env in pwsh, refers to https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#environment-files
run: |
set PATH=${{ env.GDAL_BIN }};${{ env.MONGOC_BIN }};%PATH%
ctest -C ${{env.BUILD_TYPE}} --rerun-failed --output-on-failure
build-mac:
runs-on: macos-latest
steps:
- name: Setup xcode
uses: maxim-lobanov/setup-xcode@v1
# https://github.com/ankane/setup-mongodb
- name: Setup MongoDB
uses: ankane/setup-mongodb@v1
- name: Run MongoDB
run: mongosh --eval "db.version()"
- name: Install mongo-c-driver
run: brew install mongo-c-driver
- name: Install GDAL
run: brew list gdal &>/dev/null || brew install gdal
- name: Checkout CCGL
uses: actions/checkout@v4
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DUNITTEST=1
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 4
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}} --rerun-failed --output-on-failure