Skip to content

Commit

Permalink
Add Unit Tests; Simplify the Installation; Create the CI (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
btschwertfeger authored Apr 16, 2023
1 parent 48dfcb3 commit 510d51f
Show file tree
Hide file tree
Showing 40 changed files with 1,577 additions and 380 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# Github: https://github.com/btschwertfeger
#
# Template workflow to build and install BiasAdjustCXX
#

name: Build and install BiasAdjustCXX

on:
workflow_call:

jobs:
Build:
runs-on: ubuntu-latest
container:
image: alpine:3.17
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: |
apk add --update linux-headers libc-dev g++ build-base git cmake libaec-dev netcdf-dev hdf5-dev curl-dev
git clone https://github.com/Unidata/netcdf-cxx4.git
cd netcdf-cxx4
cmake -S . -B build
cmake --build build
cd build
ctest
make install
cd ../..
rm -rf netcdf-cxx4
- name: Build and install BiasAdjustCXX
run: |
make build
make install
make uninstall
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
name: Docker build
## Checks the code logic, style and more
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# Github: https://github.com/btschwertfeger
#
# Workflow to build the docker image.

name: Build Docker Image

on:
push:
branches:
- 'master'
workflow_call:
inputs:
TAG:
type: string
required: true
secrets:
DOCKERHUB_USERNAME:
required: true
DOCKERHUB_TOKEN:
required: true

jobs:
build:
Deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/biasadjustcxx:latest
tags: ${{ secrets.DOCKERHUB_USERNAME }}/biasadjustcxx:${{ inputs.TAG }}
19 changes: 19 additions & 0 deletions .github/workflows/_pre_commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# Github: https://github.com/btschwertfeger
#
# Template workflow to run pre-commit.
#

name: Pre-Commit

on:
workflow_call:

jobs:
Pre-Commit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: pre-commit/[email protected]
38 changes: 38 additions & 0 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Checks the code logic, style and more
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# Github: https://github.com/btschwertfeger
#
# Workflow to build the test suite and run the unit tests.

name: Unit Tests

on:
workflow_call:

jobs:
Test:
runs-on: ubuntu-latest
container:
image: alpine:3.17
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install dependencies
run: |
apk add --update linux-headers libc-dev g++ build-base git cmake libaec-dev netcdf-dev hdf5-dev curl-dev
git clone https://github.com/Unidata/netcdf-cxx4.git
cd netcdf-cxx4
cmake -S . -B build
cmake --build build
cd build
ctest
make install
cd ../..
rm -rf netcdf-cxx4
- name: Test BiasAdjustCXX
run: |
make dev
make test
59 changes: 59 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Checks the code logic, style and more
# -*- coding: utf-8 -*-
# Copyright (C) 2023 Benjamin Thomas Schwertfeger
# Github: https://github.com/btschwertfeger
#
# Workflow to apply pre-commit, build, test and upload the docker
# image(s).

name: CI/CD

on:
push:
branches:
- "**"

concurrency:
group: CICD-${{ github.ref }}
cancel-in-progress: true

jobs:
## Run the pre-commit content
Pre-Commit:
uses: ./.github/workflows/_pre_commit.yml

## Build the BiasAdjustCXX command-line tool
##
Build:
needs: [Pre-Commit]
uses: ./.github/workflows/_build.yml

## Build the test suite and run the unit tests
##
Test:
needs: [Pre-Commit]
uses: ./.github/workflows/_test.yml

## Create and upload a docker image
##
Docker:
if: success() && github.ref != 'refs/heads/master'
needs: [Build, Test]
uses: ./.github/workflows/_build_docker.yml
with:
TAG: ${{ github.ref_name }}
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

## Create and upload the latest docker image
##
Docker-latest:
needs: [Build, Test]
if: success() && github.ref == 'refs/heads/master'
uses: ./.github/workflows/_build_docker.yml
with:
TAG: latest
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ output/
qdm_result.nc
del/
del.cxx
del.nc
del.nc
19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- id: check-merge-conflict
- id: check-added-large-files
args: ["--maxkb=500"]
- id: check-executables-have-shebangs
- id: trailing-whitespace
- id: fix-byte-order-marker
- id: fix-encoding-pragma
- id: requirements-txt-fixer
- id: mixed-line-ending
- id: end-of-file-fixer
- id: detect-private-key
3 changes: 0 additions & 3 deletions .vscode/extensions.json

This file was deleted.

115 changes: 0 additions & 115 deletions .vscode/settings.json

This file was deleted.

Loading

0 comments on commit 510d51f

Please sign in to comment.