Skip to content

Commit

Permalink
Merge pull request #35 from csdms/mcflugen/update-ci
Browse files Browse the repository at this point in the history
Update CI to test source distributions
  • Loading branch information
mcflugen authored Oct 15, 2024
2 parents 309905a + 954f2af commit 8ca9e53
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 12 deletions.
59 changes: 50 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,49 @@ name: Test
on: [push, pull_request]

jobs:
build-and-test:
# We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. Without this if check, checks are duplicated since
# internal PRs match both the push and pull_request events.
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository
check-tag:
# Run on external PRs, but not on internal PRs, to avoid duplicate runs
if: |
github.event_name == 'push' ||
github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
outputs:
publish_url: ${{ steps.check-publish.outputs.publish_url }}

steps:
- name: Check if this is a release/prerelease
id: check-publish
run: |
tag_name="${GITHUB_REF#refs/tags/}"
if [[ "$tag_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+[ab][0-9]+$ ]]; then
publish_url="https://test.pypi.org/legacy/"
elif [[ "$tag_name" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
publish_url="https://upload.pypi.org/legacy/"
else
publish_url="none"
fi
echo "publish_url=$publish_url" >> "$GITHUB_OUTPUT"
echo "tag_name=$tag_name"
echo "publish_url=$publish_url"
build-sdist:
name: Build source distribution
needs: check-tag
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
name: build-sdist
path: ${{ github.workspace }}/dist/*.tar.gz

test:
needs: build-sdist
runs-on: ${{ matrix.os }}

defaults:
Expand All @@ -30,10 +65,16 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- uses: actions/download-artifact@v4
with:
pattern: "build-*"
merge-multiple: true
path: ${{ github.workspace }}/dist

- name: Test
run: |
pip install nox
nox --non-interactive --error-on-missing-interpreter -s test test-cli
nox --non-interactive --error-on-missing-interpreter -s test test-cli -- dist/*.tar.gz
- name: Coveralls
if: matrix.os == 'ubuntu-latest'
Expand All @@ -45,7 +86,7 @@ jobs:
debug: true

coveralls_finish:
needs: build-and-test
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
Expand Down
21 changes: 18 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
@nox.session
def test(session: nox.Session) -> None:
"""Run the tests."""
session.install(".[testing]")
session.install("-r", "requirements-testing.txt")
install(session)

args = ["--cov", PROJECT, "-vvv"] + session.posargs
args = ["--cov", PROJECT, "-vvv"]

if "CI" in os.environ:
args.append(f"--cov-report=xml:{ROOT.absolute()!s}/coverage.xml")
Expand All @@ -28,14 +29,28 @@ def test(session: nox.Session) -> None:
@nox.session(name="test-cli")
def test_cli(session: nox.Session) -> None:
"""Test the command line interface."""
session.install(".")
install(session)

session.run("model-metadata", "--help")
session.run("model-metadata", "--version")
session.run("model-metadata", "find", "--help")
session.run("model-metadata", "query", "--help")
session.run("model-metadata", "stage", "--help")


@nox.session
def install(session: nox.Session) -> None:
first_arg = session.posargs[0] if session.posargs else None

if first_arg:
if os.path.isfile(first_arg):
session.install(first_arg)
else:
session.error("path must be a source distribution")
else:
session.install(".")


@nox.session
def lint(session: nox.Session) -> None:
"""Look for lint."""
Expand Down

0 comments on commit 8ca9e53

Please sign in to comment.