Skip to content

Commit

Permalink
Updated GitHub actions workflows.
Browse files Browse the repository at this point in the history
  • Loading branch information
tttc3 committed Jan 24, 2024
1 parent 25262fa commit cdd0b47
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 75 deletions.
77 changes: 16 additions & 61 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,27 @@
# Based on https://github.com/patrick-kidger/action_update_python_project/blob/d7ed86de913dd5bbe1c46a9b46d7bd05bc43b122/action.yml
name: AutoRelease
name: Release

on:
workflow_dispatch:
push:
branches:
- main

jobs:
pypi-publish:
name: upload release to PyPI
build:
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Python 3.12
uses: actions/setup-python@v4
- name: Release
uses: patrick-kidger/action_update_python_project@v2
with:
python-version: "3.12"
- name: Install build tools
shell: bash
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build
- name: Check version in pyproject.toml
id: check_version
shell: bash
run: |
python -c "
import subprocess
import tomllib
vparse = lambda x: tuple(map(int, x.split('.')))
with open('pyproject.toml', 'rb') as fd:
pyproject = tomllib.load(fd)['project']
project_name = pyproject['name']
project_version = pyproject['version']
pypi_version = subprocess.run(
f'python -m pip index versions {project_name}', shell=True, capture_output=True
).stdout
try:
pypi_version = pypi_version.split(b'\n', 1)[0].split(b' ')[1][1:-1].decode('utf-8')
except IndexError:
# If there exists no current pypi version
pypi_version = '0.0.0'
new_version = str(vparse(project_version) > vparse(pypi_version)).lower()
subprocess.run(f'echo name={project_name} >> $GITHUB_OUTPUT', shell=True)
subprocess.run(f'echo tag=v{project_version} >> $GITHUB_OUTPUT', shell=True)
subprocess.run(f'echo new-version={new_version} >> $GITHUB_OUTPUT', shell=True)
print(f'Got checkout_version={vparse(project_version)}')
print(f'Got pypi_version={vparse(pypi_version)}')
print(f'Setting name={project_name}')
print(f'Setting tag=v{project_version}')
print(f'Setting new-version={new_version}')
"
- name: Publish package distributions to PyPI
if: (steps.check_version.outputs.new-version == 'true')
uses: pypa/gh-action-pypi-publish@release/v1

test-script: |
cp -r ${{ github.workspace }}/tests ./tests
cp ${{ github.workspace }}/pyproject.toml ./pyproject.toml
python -m pip install ".[test]"
pytest
pypi-token: ${{ secrets.pypi_token }}
github-user: tttc3
github-token: ${{ github.token }}
email-user: ${{ secrets.email_user }}
email-token: ${{ secrets.email_token }}
email-server: ${{ secrets.email_server }}
email-target: ${{ secrets.email_target }}
20 changes: 6 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# Based on https://github.com/patrick-kidger/equinox/blob/41fd6a7fa958453faea3bb66e20e3f5d7f57473b/.github/workflows/run_tests.yml
name: Tests
name: Run tests

on:
push:
branches:
main
pull_request:
branches:
main
workflow_dispatch:

jobs:
run-test:
run-tests:
strategy:
matrix:
python-version: [ 3.12 ]
Expand All @@ -26,14 +21,11 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ".[dev]"
- name: Checks with pre-commit
uses: pre-commit/action@v2.0.3

- name: Test with pytest
run: |
python -m pytest
python -m pip install --upgrade pip
python -m pip install ".[test]"
python -m test

0 comments on commit cdd0b47

Please sign in to comment.