Skip to content

Merge pull request #35 from tugraskan/jeffs #66

Merge pull request #35 from tugraskan/jeffs

Merge pull request #35 from tugraskan/jeffs #66

Workflow file for this run

# SWAT+ CI for GitHub, O. David, 2024, LGPL 2.1
name: Build/Release SWAT+
on:
push:
tags:
- '*.*'
- '*.*.*'
workflow_dispatch:
inputs:
rev:
description: 'tag, branch, or SHA to check out'
required: true
default: 'develop'
permissions:
contents: write
packages: write
pull-requests: write
jobs:
# Get the version from tag
version:
name: Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: '${{ github.event.inputs.rev }}'
fetch-tags: true
fetch-depth: 0
- name: Get SWAT+ version
id: get_version
run: |
V=`git describe --tags`
echo $V
echo $V >v.txt
cat v.txt
echo ${{ github.event.release.tag_name }}
echo ${GITHUB_REF#refs/*/}
- name: upload
uses: actions/upload-artifact@v4
with:
name: release_tag
path: v.txt
##### Build swat with GNU
build-gnu:
runs-on: ${{ matrix.os }}
needs:
- version
#if: endsWith(github.event.base_ref, 'main') == true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
toolchain:
- {compiler: gcc, version: 13}
steps:
- name: Install Compiler
uses: fortran-lang/setup-fortran@v1
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Checkout
uses: actions/checkout@v4
- name: Build SWAT+
id: build_exe
run: |
echo ${{ env.FC }}
cmake --version
RELEASE_VERSION=${GITHUB_REF#refs/*/}
os="$RUNNER_OS"
e="build/swatplus-*"
gen="Unix"
if [ "$RUNNER_OS" == "Windows" ]; then
e="build/swatplus-*.exe"
gen="MinGW"
fi
# generate
cmake -B build -G "${gen} Makefiles" \
-D CMAKE_Fortran_COMPILER=${{ env.FC }} \
-D TAG=$RELEASE_VERSION \
-D CMAKE_BUILD_TYPE=Release
# build
cmake --build build --parallel 4
exebase=`basename -s .exe build/swatplus-*`
exez="${exebase}.zip"
exe=`ls $e`
echo $exe
echo $exez
echo $os
echo "exe=$exe" >> $GITHUB_OUTPUT
echo "exez=$exez" >> $GITHUB_OUTPUT
echo "os=$os" >> $GITHUB_OUTPUT
ls -hl build/swatplus-*
file build/swatplus-*
if [ "$RUNNER_OS" != "Windows" ]; then
(cd build && zip ../$exez swatplus-*)
fi
shell: bash
- name: zip
if: matrix.os == 'windows-latest'
uses: vimtor/[email protected]
with:
files: ${{ steps.build_exe.outputs.exe }}
dest: ${{ steps.build_exe.outputs.exez }}
- name: upload
uses: actions/upload-artifact@v4
with:
name: gnu-${{ steps.build_exe.outputs.os }}
path: ${{ steps.build_exe.outputs.exez }}
##### Build with Intel (ifx. ifort)
build-intel:
runs-on: ${{ matrix.os }}
needs:
- version
# if: endsWith(github.event.base_ref, 'main') == true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
toolchain:
- {compiler: intel, version: '2024.1'}
- {compiler: intel-classic, version: '2021.9'}
exclude:
- os: macos-latest
toolchain: {compiler: intel, version: '2024.1'}
- os: windows-latest
toolchain: {compiler: intel-classic, version: '2021.9'}
- os: ubuntu-latest
toolchain: {compiler: intel-classic, version: '2021.9'}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: '${{ github.event.inputs.rev }}'
# fetch-tags: true
# fetch-depth: 0
- name: Install Compiler
uses: fortran-lang/setup-fortran@v1
id: setup-fortran
with:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}
- name: Download version
uses: actions/download-artifact@v4
with:
name: release_tag
- name: Build SWAT+
id: build_exe
run: |
echo ${{ env.FC }}
cmake --version
# RELEASE_VERSION=${GITHUB_REF#refs/*/}
RELEASE_VERSION=`cat v.txt`
os="$RUNNER_OS"
if [ "$RUNNER_OS" == "Linux" ]; then
cmake -B build \
-D CMAKE_Fortran_COMPILER=${{ env.FC }} \
-D TAG=$RELEASE_VERSION \
-D CMAKE_BUILD_TYPE=Release
e="build/swatplus-*"
elif [ "$RUNNER_OS" == "Windows" ]; then
cmake -B build -G "MinGW Makefiles" \
-D CMAKE_Fortran_COMPILER="C:\Program Files (x86)\Intel\oneAPI\compiler\2024.1\bin\${{ env.FC }}.exe" \
-D TAG=$RELEASE_VERSION \
-D CMAKE_BUILD_TYPE=Release
e="build/swatplus-*.exe"
elif [ "$RUNNER_OS" == "macOS" ]; then
cmake -B build \
-D CMAKE_Fortran_COMPILER=${{ env.FC }} \
-D TAG=$RELEASE_VERSION \
-D CMAKE_APPLE_SILICON_PROCESSOR="x86_64" \
-D CMAKE_BUILD_TYPE=Release
e="build/swatplus-*"
else
echo "$RUNNER_OS not supported."
exit 1
fi
# compile
cmake --build build --parallel 4
exebase=`basename -s .exe build/swatplus-*`
exez="${exebase}.zip"
exe=`ls $e`
echo $exe
echo $exez
echo $os
echo "exe=$exe" >> $GITHUB_OUTPUT
echo "exez=$exez" >> $GITHUB_OUTPUT
echo "os=$os" >> $GITHUB_OUTPUT
ls -hl build/swatplus-*
file build/swatplus-*
if [ "$RUNNER_OS" != "Windows" ]; then
(cd build && zip ../$exez swatplus-*)
fi
shell: bash
- name: zip
if: matrix.os == 'windows-latest'
uses: vimtor/[email protected]
with:
files: ${{ steps.build_exe.outputs.exe }}
dest: ${{ steps.build_exe.outputs.exez }}
- name: upload
uses: actions/upload-artifact@v4
with:
name: intel-${{ steps.build_exe.outputs.os }}
path: ${{ steps.build_exe.outputs.exez }}
##### Create a new release with all zip files
release:
name: Release
runs-on: ubuntu-latest
needs: [ build-gnu, build-intel ]
steps:
- name: Download GNU Linux
uses: actions/download-artifact@v4
with:
name: gnu-Linux
- name: Download GNU Windows
uses: actions/download-artifact@v4
with:
name: gnu-Windows
- name: Download GNU macOS
uses: actions/download-artifact@v4
with:
name: gnu-macOS
- name: Download Intel Linux
uses: actions/download-artifact@v4
with:
name: intel-Linux
- name: Download Intel Windows
uses: actions/download-artifact@v4
with:
name: intel-Windows
- name: Download Intel macOS
uses: actions/download-artifact@v4
with:
name: intel-macOS
- name: Download version
uses: actions/download-artifact@v4
with:
name: release_tag
- name: Read version
id: read_ver
run: |
RELEASE_VERSION=`cat v.txt`
echo "rv=$RELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ github.token }}
# tag_name: ${{ github.event.release.tag_name }}
prerelease: true
draft: false
# name: ${{ github.event.release.tag_name }}
name: ${{ steps.read_ver.outputs.rv }}
files: swatplus-*
generate_release_notes: true