Release MODFLOW executables #31
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
name: Release MODFLOW executables | |
on: | |
schedule: | |
- cron: '0 3 * * 3' # run at 3 AM UTC every Wednesday | |
push: | |
branches: | |
- master | |
- develop | |
workflow_dispatch: | |
jobs: | |
executables-intel: | |
name: pymake CI intel on different OSs | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-20.04, macos-latest, windows-2019] | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Setup Intel OneAPI Compilers | |
uses: modflowpy/install-intelfortran-action@v1 | |
- uses: oprypin/find-latest-tag@v1 | |
with: | |
repository: MODFLOW-USGS/executables # The repository to scan. | |
releases-only: true # We know that all relevant tags have a GitHub release for them. | |
id: executables # The step ID to refer to later. | |
- name: Setup persistent environment variables | |
run: | | |
echo "MODFLOW-USGS/executables is at version ${{ steps.executables.outputs.tag }}" | |
echo "RELEASE_VERSION=${{ steps.executables.outputs.tag }}" >> $GITHUB_ENV | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install wheel | |
pip install https://github.com/modflowpy/pymake/zipball/master | |
pip list | |
- name: build executables on Linux and macOS | |
# if: runner.os != 'Windows' | |
run: python scripts/build_executables.py | |
# - name: build executables on Windows | |
# if: runner.os == 'Windows' | |
# shell: cmd | |
# run: python scripts/build_executables.py | |
- name: Upload a Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release_build | |
path: ./*.zip | |
- name: Upload additional Build Artifacts | |
if: runner.os == 'Linux' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: release_build | |
path: | | |
./code.json | |
./code.md | |
# make the release if previous job was successful | |
release: | |
name: Make a release | |
needs: executables-intel | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
- name: Install Python dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install https://github.com/modflowpy/pymake/zipball/master | |
- name: Get the latest release tag | |
uses: oprypin/find-latest-tag@v1 | |
with: | |
repository: MODFLOW-USGS/executables # The repository to scan. | |
releases-only: true # We know that all relevant tags have a GitHub release for them. | |
id: executables # The step ID to refer to later. | |
- name: Get latest release tag | |
run: | | |
current="${{ steps.executables.outputs.tag }}" | |
# next="${current%.*}.$((${current##*.}+1))" | |
next=$(echo "${{ steps.executables.outputs.tag }} + 1.0" | bc) | |
echo "RELEASE_VERSION=$current" >> $GITHUB_ENV | |
echo "NEXT_VERSION=$next" >> $GITHUB_ENV | |
repo="${{ github.repository }}" | |
echo "$repo current version is $current" | |
echo "$repo next version is $next" | |
- name: Download release artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: release_build | |
path: ./release_build/ | |
- name: List artifact files | |
run: ls -l ./release_build/ | |
- name: Create release body header | |
shell: python | |
run: | | |
import os | |
next_version = os.getenv('NEXT_VERSION') | |
line = "The programs, version numbers, and the date " | |
line += "stamp on the downloaded file used to create the " | |
line += f"executables for version {next_version} are\n\n" | |
with open('Header.md', "w") as file: | |
file.write(line) | |
- name: Build release body | |
run: | | |
cat Header.md ./release_build/code.md > BodyFile.md | |
cat BodyFile.md | |
# - name: Setup tmate session | |
# uses: mxschmitt/action-tmate@v3 | |
# with: | |
# limit-access-to-actor: true | |
- name: Update readme | |
id: update-readme | |
run: | | |
# update readme from metadata | |
cp release_build/code.md code.md | |
cp release_build/code.json code.json | |
python scripts/update_readme.py | |
# determine whether changes need to be committed | |
if [[ `git status --porcelain --untracked-files=no` ]]; then | |
echo "Changes to README.md:" | |
git diff README.md | |
changes="true" | |
else | |
echo "No changes to README.md" | |
changes="false" | |
fi | |
echo "changes=$changes" >> $GITHUB_OUTPUT | |
- name: Draft pull request | |
# only open PR on manual trigger | |
if: github.event_name == 'workflow_dispatch' && steps.update-readme.outputs.changes == 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
# commit and push | |
branch="update-readme-${{ env.NEXT_VERSION }}" | |
git config core.sharedRepository true | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add README.md | |
git status | |
git switch -c $branch | |
git commit -m "ci(release): update readme" | |
git push -u origin "$branch" | |
# create PR | |
body=' | |
# MODFLOW executables release '${{ env.NEXT_VERSION }}' | |
This PR updates `README.md` with the latest release information. | |
' | |
gh pr create -B "master" -H "$branch" --title "Release ${{ env.NEXT_VERSION }}" --draft --body "$body" | |
- name: Create release | |
# only create new release on manual trigger | |
if: github.event_name == 'workflow_dispatch' | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ env.NEXT_VERSION }} | |
name: "MODFLOW and related programs binary executables" | |
bodyFile: "./BodyFile.md" | |
artifacts: "./release_build/*" | |
draft: false | |
allowUpdates: true | |
token: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Delete Artifact | |
# uses: GeekyEggo/delete-artifact@v1.0.0 | |
# with: | |
# name: release_build |