Skip to content

Merge pull request #22 from lsst-dm/u/timj/fix-license #212

Merge pull request #22 from lsst-dm/u/timj/fix-license

Merge pull request #22 from lsst-dm/u/timj/fix-license #212

Workflow file for this run

name: build_and_test
on:
push:
branches:
- main
tags:
- "*"
pull_request:
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
with:
# Need to clone everything for the git tags.
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "setup.cfg"
- name: Update pip/wheel infrastructure
run: |
python -m pip install --upgrade pip
pip install uv
uv pip install --system wheel
- name: Install dependencies
run: |
uv pip install --system -r requirements.txt
# We have two cores so we can speed up the testing with xdist
- name: Install pytest packages
run: |
uv pip install --system pytest pytest-xdist pytest-cov
- name: List installed packages
run: |
uv pip list -v
- name: Build and install
run: |
uv pip install -v --system --no-deps -e .
- name: Run tests
run: |
pytest -r a -v -n 3 --cov=lsst.dax.obscore --cov=tests --cov-report=xml --cov-report=term --cov-branch
butler obscore -h
- name: Upload coverage to codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
check-changes:
outputs:
skip: ${{ steps.check.outputs.skip }}
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if weekly changed
id: check
run: |
# Get SHA hashes for all weekly tags
weekly_sha=$(git tag -l 'w.*' | while read tag; do
git rev-list -n 1 "${tag}"
done)
# Extract the current tag and its SHA
current_tag=${GITHUB_REF#refs/tags/}
current_sha=$(git rev-list -1 "${current_tag}")
# Count occurrences of the current SHA in the weekly SHA list
n=$(echo "${weekly_sha}" | grep -c "${current_sha}")
echo "Current tag ${current_tag} (${current_sha}) SHA found ${n} time(s)"
# Determine whether to skip the upload based on the count
if [ "${n}" -gt 1 ]; then
echo "Skip upload"
echo "skip=true" >> "${GITHUB_OUTPUT}"
else
echo "Enable upload"
echo "skip=false" >> "${GITHUB_OUTPUT}"
fi
pypi:
name: Upload release to PyPI
runs-on: ubuntu-latest
needs: [build_and_test, check-changes]
permissions:
id-token: write
if: "${{ ! startsWith(github.ref, 'refs/tags/w.') || needs.check-changes.outputs.skip == 'false' }}"
steps:
- uses: actions/checkout@v4
with:
# Need to clone everything to embed the version.
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools wheel build
- name: Build and create distribution
run: |
python -m build --skip-dependency-check
- name: Upload
uses: pypa/gh-action-pypi-publish@release/v1