Skip to content

Commit c842dfa

Browse files
authored
Merge pull request #205 from nasa/build/switch-poetry-to-uv
Build/switch poetry to uv
2 parents 66eddef + 7dfeb04 commit c842dfa

12 files changed

Lines changed: 762 additions & 1148 deletions
Lines changed: 37 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -1,192 +1,84 @@
1-
# When code is pushed to a branch, run linting and tests, and
2-
# then automatically increment the version number as appropriate for the branch source.
3-
name: Lint and Test
1+
# Builds the batchee Docker image on PRs and pushes.
2+
# Publishes to GHCR only on version tag pushes.
3+
name: Build batchee image
44

5-
# Controls when the workflow will run
65
on:
7-
# Triggers the workflow on push events
6+
pull_request:
7+
branches: [develop, main, 'release/**']
88
push:
9-
branches: [ develop, release/**, main, feature/**, issue/**, issues/** ]
9+
tags:
10+
- '[0-9]+.[0-9]+.[0-9]+'
11+
- '[0-9]+.[0-9]+.[0-9]+rc[0-9]+'
1012

11-
# Allows you to run this workflow manually from the Actions tab
12-
workflow_dispatch:
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
1316

1417
env:
15-
POETRY_VERSION: "2.1.3"
1618
PYTHON_VERSION: "3.12"
1719
REGISTRY: ghcr.io
1820
IMAGE_NAME: ${{ github.repository }}
1921

2022
jobs:
21-
run_tests:
23+
tests:
2224
uses: ./.github/workflows/run_tests.yml
2325
secrets:
2426
codecov_token: ${{ secrets.CODECOV_TOKEN }}
2527

2628
build:
27-
needs: run_tests
29+
needs: tests
2830
runs-on: ubuntu-latest
29-
31+
permissions:
32+
contents: read
33+
packages: write
3034
steps:
31-
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
3235
- name: Retrieve repository
3336
uses: actions/checkout@v6
34-
- name: Set up Python
35-
uses: actions/setup-python@v6
36-
with:
37-
python-version: ${{ env.PYTHON_VERSION }}
38-
- name: Install Poetry
39-
uses: abatilo/actions-poetry@v4.0.0
4037
with:
41-
poetry-version: ${{ env.POETRY_VERSION }}
42-
- name: Get version
43-
id: get-version
44-
run: |
45-
echo "current_version=$(poetry version | awk '{print $2}')" >> $GITHUB_OUTPUT
46-
echo "pyproject_name=$(poetry version | awk '{print $1}')" >> $GITHUB_ENV
38+
fetch-depth: 0
4739

48-
# Bumps the version, based on which branch is the target.
49-
- name: Bump pre-alpha version
50-
# If triggered by push to a feature branch
51-
if: |
52-
${{ startsWith(github.ref, 'refs/heads/issue') }} ||
53-
${{ startsWith(github.ref, 'refs/heads/dependabot/') }} ||
54-
${{ startsWith(github.ref, 'refs/heads/feature/') }}
55-
run: |
56-
new_ver="${{ steps.get-version.outputs.current_version }}+$(git rev-parse --short ${GITHUB_SHA})"
57-
poetry version $new_ver
58-
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
59-
- name: Bump alpha version
60-
# If triggered by push to the develop branch
61-
if: ${{ github.ref == 'refs/heads/develop' }}
62-
run: |
63-
poetry version prerelease
64-
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
65-
echo "venue=sit" >> $GITHUB_ENV
66-
- name: Bump rc version
67-
# If triggered by push to a release branch
68-
if: ${{ startsWith(github.ref, 'refs/heads/release/') }}
69-
env:
70-
# True if the version already has a 'rc' pre-release identifier
71-
BUMP_RC: ${{ contains(steps.get-version.outputs.current_version, 'rc') }}
72-
run: |
73-
if [ "$BUMP_RC" = true ]; then
74-
poetry version prerelease
75-
else
76-
poetry version ${GITHUB_REF#refs/heads/release/}rc1
77-
fi
78-
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
79-
echo "venue=uat" >> $GITHUB_ENV
80-
- name: Release version
81-
# If triggered by push to the main branch
82-
if: ${{ startsWith(github.ref, 'refs/heads/main') }}
83-
env:
84-
CURRENT_VERSION: ${{ steps.get-version.outputs.current_version }}
85-
# Remove rc* from the end of version string
86-
# The ${string%%substring} syntax below deletes the longest match of $substring from back of $string.
87-
run: |
88-
poetry version ${CURRENT_VERSION%%rc*}
89-
echo "software_version=$(poetry version | awk '{print $2}')" >> $GITHUB_ENV
90-
echo "venue=ops" >> $GITHUB_ENV
91-
92-
- name: Run Snyk as a blocking step
93-
uses: snyk/actions/python-3.11@master
94-
env:
95-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
40+
- name: Set up uv
41+
uses: astral-sh/setup-uv@v7
9642
with:
97-
command: test
98-
args: >
99-
--org=${{ secrets.SNYK_ORG_ID }}
100-
--project-name=${{ github.repository }}
101-
--severity-threshold=high
102-
--fail-on=all
103-
- name: Run Snyk on Python
104-
uses: snyk/actions/python-3.11@master
105-
env:
106-
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
107-
with:
108-
command: monitor
109-
args: >
110-
--org=${{ secrets.SNYK_ORG_ID }}
111-
--project-name=${{ github.repository }}
112-
113-
- name: Commit Version Bump
114-
# If building the `develop`, a `release` branch, or `main`,
115-
# then we commit the version bump back to the repo.
116-
if: |
117-
github.ref == 'refs/heads/develop' ||
118-
github.ref == 'refs/heads/main' ||
119-
startsWith(github.ref, 'refs/heads/release')
120-
run: |
121-
git config --global user.name 'batchee bot'
122-
git config --global user.email 'batchee@noreply.github.com'
123-
git commit -am "/version ${{ env.software_version }}" --no-verify
124-
git push --no-verify
43+
python-version: ${{ env.PYTHON_VERSION }}
12544

126-
# Builds and pushes the package to the Python Package Index (PyPI)
127-
- name: Build Python Artifact
128-
run: |
129-
poetry build
130-
- uses: actions/upload-artifact@v6
131-
with:
132-
name: python-artifact
133-
path: dist/*
134-
- name: Publish to test.pypi.org
135-
id: pypi-test-publish
136-
if: |
137-
github.ref == 'refs/heads/develop' ||
138-
startsWith(github.ref, 'refs/heads/release')
139-
env:
140-
POETRY_PYPI_TOKEN_TESTPYPI: ${{secrets.PYPI_TOKEN_TESTPYPI}}
141-
run: |
142-
poetry config repositories.testpypi https://test.pypi.org/legacy/
143-
poetry publish -r testpypi
144-
- name: Publish to pypi.org
145-
if: ${{ github.ref == 'refs/heads/main' }}
146-
id: pypi-publish
147-
env:
148-
POETRY_PYPI_TOKEN_PYPI: ${{secrets.PYPI_TOKEN_PYPI}}
45+
- name: Determine version
46+
id: version
14947
run: |
150-
poetry publish
48+
SERVICE_VERSION="$(uv tool run hatch version)"
49+
echo "service_version=$SERVICE_VERSION" >> "$GITHUB_OUTPUT"
15150
152-
# Builds and pushes a Docker image
15351
- name: Log in to the Container registry
154-
if: ${{ !startsWith(github.ref, 'refs/heads/main/') }}
15552
uses: docker/login-action@v3
15653
with:
15754
registry: ${{ env.REGISTRY }}
15855
username: ${{ github.actor }}
15956
password: ${{ secrets.GITHUB_TOKEN }}
57+
16058
- name: Extract metadata (tags, labels) for Docker
161-
if: ${{ !startsWith(github.ref, 'refs/heads/main/') }}
16259
id: meta
16360
uses: docker/metadata-action@v5
16461
with:
16562
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
16663
tags: |
167-
type=raw,pattern={{version}},value=${{ env.software_version }}
168-
type=raw,value=${{ env.venue }}
64+
type=raw,value=${{ steps.version.outputs.service_version }}
65+
type=raw,value=uat,enable=${{ startsWith(github.ref, 'refs/tags/') && contains(github.ref_name, 'rc') }}
66+
type=raw,value=ops,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref_name, 'rc') }}
67+
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/') && !contains(github.ref_name, 'rc') }}
68+
69+
- name: Set up Docker Buildx
70+
uses: docker/setup-buildx-action@v4
71+
16972
- name: Build and push Docker image
170-
if: ${{ !startsWith(github.ref, 'refs/heads/main/') }}
171-
id: docker-push
17273
uses: docker/build-push-action@v6
17374
with:
17475
context: .
17576
file: Dockerfile
17677
build-args: |
177-
SOURCE=${{env.pyproject_name}}[harmony]==${{ env.software_version }}
178-
push: true
78+
SERVICE_VERSION=${{ steps.version.outputs.service_version }}
79+
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
17980
pull: true
18081
tags: ${{ steps.meta.outputs.tags }}
18182
labels: ${{ steps.meta.outputs.labels }}
182-
183-
- name: Push Tag
184-
if: |
185-
github.ref == 'refs/heads/develop' ||
186-
github.ref == 'refs/heads/main' ||
187-
startsWith(github.ref, 'refs/heads/release')
188-
run: |
189-
git config user.name "${GITHUB_ACTOR}"
190-
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
191-
git tag -a "${{ env.software_version }}" -m "Version ${{ env.software_version }}"
192-
git push origin "${{ env.software_version }}"
83+
cache-from: type=gha
84+
cache-to: type=gha,mode=max

.github/workflows/pull_request.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/release-created.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/run_tests.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,47 @@
33
# be called by the workflow that runs tests against new PRs and as
44
# a first step in the workflow that publishes new Docker images.
55

6-
name: A reusable workflow to build and run the unit test suite
6+
# Runs linting and unit tests on push, and reports
7+
# code coverage to Codecov.
8+
name: Run tests and linting
79

810
on:
11+
push:
912
workflow_call:
1013
secrets:
1114
codecov_token:
1215
required: true
1316
workflow_dispatch:
1417

1518
env:
16-
POETRY_VERSION: "2.1.3"
1719
PYTHON_VERSION: "3.12"
1820

1921
jobs:
2022
run_tests:
2123
runs-on: ubuntu-latest
2224

25+
permissions:
26+
contents: read
27+
2328
steps:
2429
- name: Retrieve repository
2530
uses: actions/checkout@v6
2631

27-
- name: Set up Python
28-
uses: actions/setup-python@v6
32+
- name: Set up uv
33+
uses: astral-sh/setup-uv@v7
2934
with:
3035
python-version: ${{ env.PYTHON_VERSION }}
3136

32-
- name: Set up Poetry
33-
uses: abatilo/actions-poetry@v4.0.0
34-
with:
35-
poetry-version: ${{ env.POETRY_VERSION }}
36-
37-
- name: Install package
38-
run: poetry install --extras dev
37+
- name: Install dependencies
38+
run: uv sync --extra dev --frozen
3939

40-
- name: Lint
40+
- name: Run Linting
4141
run: |
42-
poetry run ruff check batchee
42+
uv run ruff check batchee
4343
4444
- name: Run tests with coverage
4545
run: |
46-
poetry run pytest --cov=batchee --cov-report=xml:build/reports/coverage.xml --cov-report=html:build/reports/coverage.html tests/
46+
uv run pytest --cov=batchee --cov-report=xml:build/reports/coverage.xml tests/
4747
4848
- name: Upload coverage reports to Codecov
4949
uses: codecov/codecov-action@v5

0 commit comments

Comments
 (0)