Skip to content

Table of Contents

Table of Contents #103

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:
integration-fms17:
name: Integration tests (FMS17 on fms_17)
runs-on: [fms_17]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Cache pip
uses: actions/cache@v4
with:
path: ~\AppData\Local\pip\Cache
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: Create tests/.env for FMS17
shell: powershell
run: |
$envContent = @"
FMS_ADDRESS="https://localhost"
FMS_DB_NAME="fmdata_testing"
FMS_DB_USER="${{ secrets.FMDATA_TESTING_USER }}"
FMS_DB_PASSWORD="${{ secrets.FMDATA_TESTING_PASSWORD }}"
FMS_VERSION="17"
"@
New-Item -ItemType Directory -Force -Path tests | Out-Null
Set-Content -Path tests/.env -Value $envContent -NoNewline
- name: Run integration tests with coverage (FMS17)
shell: powershell
run: |
$env:ENV_FILE = ".env"
coverage run -m unittest discover -s tests -t tests
coverage xml -o coverage_fms17.xml
- name: Upload coverage artifact (FMS17)
uses: actions/upload-artifact@v4
with:
name: coverage-fms17
path: |
coverage_fms17.xml
.coverage.fms17
integration-fms22:
name: Integration tests (FMS22 on fms_22)
runs-on: [fms_22]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.9'
- 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: Create tests/.env for FMS22
shell: bash
run: |
mkdir -p tests
cat > tests/.env << 'EOF'
FMS_ADDRESS="https://localhost"
FMS_DB_NAME="fmdata_testing"
FMS_DB_USER="${{ secrets.FMDATA_TESTING_USER }}"
FMS_DB_PASSWORD="${{ secrets.FMDATA_TESTING_PASSWORD }}"
FMS_VERSION="22"
EOF
- name: Run integration tests with coverage (FMS22)
shell: bash
run: |
export ENV_FILE=".env"
coverage run -m unittest discover -s tests -t tests
coverage xml -o coverage_fms22.xml
mv .coverage .coverage.fms22 || true
- name: Upload coverage artifact (FMS22)
uses: actions/upload-artifact@v4
with:
name: coverage-fms22
path: |
coverage_fms22.xml
.coverage.fms22
sonarcloud:
name: SonarCloud analysis
runs-on: ubuntu-latest
needs:
- integration-fms17
- integration-fms22
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Download coverage artifact (FMS17)
uses: actions/download-artifact@v4
with:
name: coverage-fms17
path: coverage_artifacts
- name: Download coverage artifact (FMS22)
uses: actions/download-artifact@v4
with:
name: coverage-fms22
path: coverage_artifacts
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v6.0.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
release:
name: Release on tag
runs-on: ubuntu-latest
needs: sonarcloud
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