Skip to content

Try

Try #66

Workflow file for this run

name: CI/CD
on:
workflow_dispatch:
push:
branches:
- '**' # run on all branches (including master)
tags:
- 'v*.*.*' # release tags like v1.2.3
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# - name: Run tests with coverage in FMS17
# run: |
# ENV_FILE=.env_fms17 coverage run --data-file=.coverage.env_fms17 -m unittest discover -s tests -t tests
# coverage xml -o coverage.xml
- name: Upload coverage to Codecov (only on master)
#if: ${{ github.ref == 'refs/heads/master' }}
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
release:
name: Release on tag
runs-on: ubuntu-latest
needs: tests
if: startsWith(github.ref, 'refs/tags/v')
environment:
name: pypi
url: https://pypi.org/p/fmdata
permissions:
id-token: write
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Ensure tag commit is on master
run: |
git fetch origin master:origin-master
if git merge-base --is-ancestor origin-master "${GITHUB_SHA}"; then
echo "Tag commit is contained in master."
else
echo "Error: Release tags must point to a commit on master."
exit 1
fi
- name: Extract version from tag and export PACKAGE_VERSION
run: |
TAG_NAME="${GITHUB_REF_NAME}"
# Expect tags like v1.2.3 -> PACKAGE_VERSION=1.2.3
VERSION="${TAG_NAME#v}"
echo "PACKAGE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install build
- name: Build package
run: |
python -m build
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false
tag_name: "${{ github.ref_name }}"
generate_release_notes: true
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1