Add argument: -opts #130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build CCGL library on native C++11 with mongo-c-driver, run test with CMake, and deploy docker image | |
name: Build and deploy with MongoDB | |
on: | |
push: | |
branches: | |
- 'master' | |
- 'dev' | |
paths-ignore: | |
- 'doc/**' | |
pull_request: | |
paths-ignore: | |
- 'doc/**' | |
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-mongodb | |
# IMAGE_TAG: ${{ github.sha }} | |
IMAGE_TAG: ${{ github.ref == 'refs/heads/master' && 'alpine-with-mongodb' || 'dev-alpine-with-mongodb' }} | |
jobs: | |
# Check GitHub Actions runner images versions: https://github.com/actions/runner-images | |
build-linux: | |
runs-on: ubuntu-22.04 | |
services: | |
mongodb: | |
image: mongo | |
ports: | |
- 27017:27017 | |
steps: | |
- name: Checkout CCGL | |
uses: actions/checkout@v4 | |
- name: Install mongo-c-driver | |
run: sudo apt-get update && sudo apt-get install -qq libmongoc-1.0-0 libmongoc-dev | |
- 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 | |
- name: Build | |
# Build your program with the given configuration | |
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} | |
- 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 | |
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. | |
# | |
# Set Env, refers to https://github.com/mstum/Simplexcel/blob/master/.github/workflows/cibuild.yml | |
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: Configure CMake | |
shell: cmd | |
run: | | |
cmake -G "Visual Studio 16 2019" -A x64 -B ${{github.workspace}}/build ^ | |
-DMONGOC_ROOT=${{ env.MONGOC_ROOT }} ^ | |
-DUNITTEST=1 | |
- name: Build | |
shell: cmd | |
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- /m:2 | |
- name: Test | |
shell: cmd | |
working-directory: ${{github.workspace}}/build | |
run: | | |
set PATH=${{ 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: 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}} | |
- name: Test | |
working-directory: ${{github.workspace}}/build | |
run: ctest -C ${{env.BUILD_TYPE}} --rerun-failed --output-on-failure |