-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge github actions code from dev branch
- Loading branch information
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Build SWAT using GCC on Linux and macOS | ||
|
||
name: Build by GCC on Linux/macOS | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'cmake/**' | ||
- 'src/**' | ||
- 'CMakeLists.txt' | ||
pull_request: | ||
paths: | ||
- 'cmake/**' | ||
- 'src/**' | ||
- 'CMakeLists.txt' | ||
workflow_dispatch: | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Debug | ||
|
||
jobs: | ||
build-ubuntu-gfortran: | ||
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. | ||
# You can convert this to a matrix build if you need cross-platform coverage. | ||
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout SWAT | ||
uses: actions/checkout@v3 | ||
|
||
- 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}} | ||
|
||
- name: Build | ||
# Build your program with the given configuration | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 4 | ||
|
||
build-mac-gfortran: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout SWAT | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure CMake | ||
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#language-and-runtime | ||
# Specify gfortran alias explicitly! | ||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_Fortran_COMPILER=gfortran-11 | ||
|
||
- name: Build | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Build SWAT using ifort on Linux | ||
# Refers to https://gist.github.com/scivision/d94bb10a01fa3b8ed0c9a93ee16318ba | ||
|
||
name: Build by IntelFortran on Linux | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'cmake/**' | ||
- 'src/**' | ||
- 'CMakeLists.txt' | ||
pull_request: | ||
paths: | ||
- 'cmake/**' | ||
- 'src/**' | ||
- 'CMakeLists.txt' | ||
workflow_dispatch: | ||
|
||
env: | ||
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) | ||
BUILD_TYPE: Debug | ||
|
||
jobs: | ||
|
||
linux-ubuntu-ifort: | ||
runs-on: ubuntu-latest | ||
env: | ||
FC: ifort | ||
|
||
steps: | ||
- name: Intel Apt repository | ||
timeout-minutes: 1 | ||
run: | | ||
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | ||
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | ||
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS-2023.PUB | ||
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list | ||
sudo apt-get update | ||
- name: Install Intel oneAPI | ||
timeout-minutes: 5 | ||
run: sudo apt-get install intel-oneapi-compiler-fortran | ||
|
||
- name: Checkout SWAT | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Intel oneAPI environment | ||
run: | | ||
source /opt/intel/oneapi/setvars.sh | ||
printenv >> $GITHUB_ENV | ||
- 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}} | ||
|
||
- name: Build | ||
# Build your program with the given configuration | ||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -- -j 4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Create and publish SWAT Docker images | ||
|
||
# Configures this workflow to run every time a change is pushed to the branches. | ||
on: | ||
push: | ||
branches: | ||
- '**' # matches every branch | ||
|
||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. | ||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
# | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 | ||
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@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
# 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. | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
## | ||
# crazyzlj/swat:alpine | ||
# | ||
# Usage: | ||
# > cd SWAT | ||
# > docker build -t <tag> -f docker/Dockerfile . | ||
# or build and push for amd64 and arm64 platforms simultanously | ||
# > docker buildx build --platform linux/amd64,linux/arm64 --push -t crazyzlj/swat:alpine -f docker/Dockerfile . | ||
# | ||
# Copyright 2022 Liang-Jun Zhu <[email protected]> | ||
|
||
# Use alpine as the build container | ||
ARG ALPINE_VERSION=3.15 | ||
FROM alpine:${ALPINE_VERSION} as builder | ||
|
||
LABEL maintainer="Liang-Jun Zhu <[email protected]>" | ||
|
||
# Replace alpine repository source cdn to accelarate access speed; Setup build environment | ||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ | ||
&& apk update && apk upgrade \ | ||
&& apk add --no-cache cmake gfortran make musl-dev | ||
|
||
# Copy source directory | ||
WORKDIR /SWAT | ||
COPY . . | ||
|
||
# # Build for release | ||
ARG INSTALL_DIR=/SWAT/dist | ||
RUN cd /SWAT \ | ||
&& mkdir build \ | ||
&& cd build \ | ||
&& cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \ | ||
&& make -j 2 \ | ||
&& make install \ | ||
&& cd .. | ||
|
||
# # Build final image | ||
FROM alpine:${ALPINE_VERSION} as runner | ||
|
||
# Replace alpine repository source cdn; Add GNU gfortran library | ||
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories | ||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \ | ||
&& apk update && apk upgrade \ | ||
&& apk add --no-cache libgfortran | ||
|
||
# Order layers starting with less frequently varying ones | ||
ARG INSTALL_DIR=/SWAT/dist | ||
COPY --from=builder ${INSTALL_DIR}/bin/ /usr/bin/ |