Skip to content

Merge pull request #31 from EOEPCA/develop #120

Merge pull request #31 from EOEPCA/develop

Merge pull request #31 from EOEPCA/develop #120

Workflow file for this run

name: build-and-publish
on:
push:
branches:
- develop
- main
tags:
- 'v*.*.*'
permissions:
id-token: write
contents: read
packages: write
env:
IMAGE_ID: ghcr.io/eoepca/eoap-cwlwrap/eoap-cwlwrap
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: Install dependencies
run: pip install hatch nose2
# -----------------------------
# Strict SemVer + Hatch version gate
# -----------------------------
- name: Validate tag and hatch version
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG="${GITHUB_REF#refs/tags/}"
# Ensure tag starts with v
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: Tag must follow strict SemVer format vX.Y.Z"
exit 1
fi
TAG_VERSION="${TAG#v}"
HATCH_VERSION=$(hatch version)
echo "Tag version: $TAG_VERSION"
echo "Hatch version: $HATCH_VERSION"
if [ "$TAG_VERSION" != "$HATCH_VERSION" ]; then
echo "ERROR: Git tag version does not match hatch version"
exit 1
fi
- name: Build package
run: hatch build
- name: Test package
run: hatch test --verbose
# -----------------------------
# Determine container tag
# -----------------------------
- name: Determine image tag
run: |
if [[ "${GITHUB_REF}" == refs/heads/develop ]]; then
echo "IMAGE_TAG=latest-dev" >> $GITHUB_ENV
elif [[ "${GITHUB_REF}" == refs/heads/main ]]; then
echo "IMAGE_TAG=latest" >> $GITHUB_ENV
elif [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
echo "IMAGE_TAG=$VERSION" >> $GITHUB_ENV
fi
- name: Login to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build container
run: |
docker build . -f Dockerfile -t eoap-cwlwrap
docker tag eoap-cwlwrap $IMAGE_ID:${IMAGE_TAG}
- name: Push container
run: docker push $IMAGE_ID:${IMAGE_TAG}
publish-to-pypi:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install hatch
run: pip install hatch
- name: Build package
run: hatch build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1