Skip to content

Commit

Permalink
github actions utest (#169)
Browse files Browse the repository at this point in the history
* add ci-related files. update utest
* modify to auto-run different cases based on ci.test
* Improve CI workflow
* Separate builds and tests into different jobs
* Separate input data from build image; instead, use it as a volume before running tests
* Make ci subdirectory to contain ci-related files
* add clean-up after utest run
* add workflow manage files
* move parsing in main.yml to a separate script file
  • Loading branch information
MinsukJi-NOAA authored Sep 9, 2020
1 parent 3fb6556 commit 407df4e
Show file tree
Hide file tree
Showing 21 changed files with 2,279 additions and 789 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
.git
.gitignore
tests/*.log
tests/log_ut_linux.gnu
121 changes: 121 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: Pull Request Tests

on:
push:
branches:
- develop
pull_request:
branches:
- develop

jobs:
setup:
name: Set up
runs-on: ubuntu-latest

outputs:
tn: ${{ steps.parse.outputs.tn }}
bld: ${{ steps.parse.outputs.bld }}
test: ${{ steps.parse.outputs.test }}
img: ${{ steps.parse.outputs.img }}

steps:
- name: Checkout codes
uses: actions/checkout@v2

- name: Parse cases
id: parse
run: |
cd ${GITHUB_WORKSPACE}/tests/ci
parsed_output=( $(./parse.sh) )
name_=${parsed_output[0]}
bld_=${parsed_output[1]}
test_=${parsed_output[2]}
img_=${parsed_output[3]}
echo "::set-output name=tn::$name_"
echo "::set-output name=bld::$bld_"
echo "::set-output name=test::$test_"
echo "::set-output name=img::$img_"
echo "test name : $name_"
echo "build set : $bld_"
echo "test set : $test_"
echo "image name: $img_"
build:
name: Build (${{ matrix.bld_set }})
needs: setup
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.bld) }}

steps:
- name: Checkout codes
uses: actions/checkout@v2
with:
submodules: recursive

- name: Build
run: |
printf '{\n "experimental": true\n}' | sudo tee /etc/docker/daemon.json >/dev/null
sudo systemctl restart docker
sleep 10
cd tests/ci && ./ci.sh -n ${{ needs.setup.outputs.tn }} -b ${{ matrix.bld_set }}
- name: Free up disk space
run: |
sudo docker rmi $(sudo docker image ls | grep -E -m1 '<none>' | awk '{ print $3 }')
sudo docker rmi $(sudo docker image ls | awk '/ci-test-base/ { print $3 }')
- name: Prepare artifacts
run: |
cd tests/ci
sudo docker save ${{ needs.setup.outputs.img }} | gzip >${{ needs.setup.outputs.img }}.tar.gz
tar cvjf artifact.tar.bz2 ${{ needs.setup.outputs.img }}.tar.gz ci.sh ci.test
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.bld_set }}.artifact.tar.bz2
path: tests/ci/artifact.tar.bz2

utest:
name: Unit test (${{ needs.setup.outputs.tn }}, ${{ matrix.test_set }})
needs: [setup,build]
runs-on: ubuntu-latest
#runs-on: self-hosted

strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup.outputs.test) }}

steps:
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ matrix.artifact }}.artifact.tar.bz2

- name: Prepare artifacts
run: |
tar xvjf artifact.tar.bz2 && rm -f artifact.tar.bz2
sudo docker load --input ${{ needs.setup.outputs.img }}.tar.gz && rm -f ${{ needs.setup.outputs.img }}.tar.gz
- name: Run utest
run: ./ci.sh -n ${{ needs.setup.outputs.tn }} -r ${{ matrix.test_set }}

- name: Upload memory usage file
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: memory_stat_${{ matrix.test_set }}
path: memory_stat

- name: Clean up
if: ${{ always() }}
run: |
rm -f ci.sh ci.test
sudo docker rm my-container && sudo docker rmi ${{ needs.setup.outputs.img }}:latest
sudo docker volume rm DataVolume
54 changes: 54 additions & 0 deletions .github/workflows/manage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Manage workflows

on:
workflow_run:
workflows: ["Pull Request Tests"]
types:
- requested

jobs:
job1:
name: Job 1
runs-on: ubuntu-latest

steps:
- name: Checkout codes
uses: actions/checkout@v2

- name: Check if skip-ci is requested
run: |
cd ${GITHUB_WORKSPACE}/tests/ci
repo="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs"
tr_id=$(cat ${GITHUB_EVENT_PATH} | ./json_helper.py get_trigger_id)
tr_br=$(cat ${GITHUB_EVENT_PATH} | ./json_helper.py get_trigger_br)
check=$(cat ${GITHUB_EVENT_PATH} | ./json_helper.py check_skip)
echo "::set-env name=TRIGGER_ID::${tr_id}"
echo "::set-env name=TRIGGER_BR::${tr_br}"
echo "skip-ci: ${check}"
if [[ $check == yes ]]; then
echo "skip-ci is requested"
echo '::set-env name=CURR_JOB::cancelled'
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" ${repo}/$tr_id/cancel
else
echo '::set-env name=CURR_JOB::running'
fi
- name: Cancel redundant jobs
run: |
echo "CURR_JOB is $CURR_JOB"
echo "TRIGGER_ID is $TRIGGER_ID"
echo "TRIGGER_BR is $TRIGGER_BR"
export GITHUB_ACTOR
export GITHUB_RUN_ID
export TRIGGER_ID
export TRIGGER_BR
cd ${GITHUB_WORKSPACE}/tests/ci
repo="${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs"
cancel_ids=$(curl -H "Accept: application/vnd.github.v3+json" ${repo} | ./json_helper.py cancel_workflow)
echo "cancel ids: $cancel_ids"
if [[ $cancel_ids != '' ]]; then
for i in $cancel_ids; do
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.v3+json" ${repo}/$i/cancel
done
fi
if: ${{ env.CURR_JOB == 'running' }}
29 changes: 29 additions & 0 deletions modulefiles/linux.gnu/fv3
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export F77=${F77:-mpif77}
export F90=${F90:-mpif90}
export FC=${FC:-mpif90}

##
## set up variables for ../cmake/configure_linux.gnu.cmake
##
export CMAKE_Platform=linux.gnu
export CMAKE_C_COMPILER=${CC}
export CMAKE_CXX_COMPILER=${CXX}
export CMAKE_Fortran_COMPILER=${FC}

##
## use own NetCDF library
##
export NETCDF=${NETCDF:-/usr/local}

##
## use SIONlib library if installed and environment variable is set
##
Expand All @@ -24,3 +37,19 @@ if [ ! "x$SIONLIB" == "x" ]; then
export SIONLIB_INC="-I${SIONLIB}/include -I${SIONLIB}/include/mod_64"
export SIONLIB_LIB="-L${SIONLIB}/lib -lsionmpi_f90_64 -lsionser_f90_64 -lsionmpi_64 -lsiongen_64 -lsionser_64 -lsioncom_64 -lsioncom_64_lock_none"
fi

##
## use pre-compiled EMSF library for above compiler / MPI combination
##
export ESMFMKFILE=${ESMFMKFILE:-/usr/local/lib/esmf.mk}

##
## NCEP libraries (need to download and build manually, see doc/README_{UBUNTU,CENTOS,...}.txt and https://github.com/NCAR/NCEPlibs)
##
export NCEPLIBS_DIR=${NCEPLIBS_DIR:-/usr/local/NCEPlibs}
export bacio_DIR=${NCEPLIBS_DIR}/bacio-2.4.0
export nemsio_DIR=${NCEPLIBS_DIR}/nemsio-2.5.1
export w3nco_DIR=${NCEPLIBS_DIR}/w3nco-2.4.0
export sp_DIR=${NCEPLIBS_DIR}/sp-2.3.0
export w3emc_DIR=${NCEPLIBS_DIR}/w3emc-2.7.0
export sigio_DIR=${NCEPLIBS_DIR}/sigio-2.3.0
Loading

0 comments on commit 407df4e

Please sign in to comment.