Skip to content

Modernize build syntax #85

Modernize build syntax

Modernize build syntax #85

Workflow file for this run

name: Tests, Docs, Deploy
on:
- push
- pull_request
permissions:
contents: read
jobs:
# Test Code for recent Python releases
test-code:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install tox
python -m pip install tox-gh-actions
- name: Test Code
run: tox
# Test Code for older Python3 releases
test-code-older-py3:
runs-on: ubuntu-20.04
container:
image: python:${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
python-version: ['3.4.10', '3.5.10']
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install dependencies
shell: bash
run: |
if [[ ${{ matrix.python-version }} == 3.3* ]]; then
python -m pip install virtualenv==15.2.0
python -m pip install pluggy==0.5.2
python -m pip install tox==2.9.1
fi
python -m pip install tox
- name: Test Code
shell: bash
run: |
version_abbr=$( echo ${{ matrix.python-version }} | sed -r 's/^([0-9])\.([0-9]).*/\1\2/' )
envs=$( tox -listenvs | grep "py$version_abbr-" | tr '\n' ',' )
tox -e $envs
# Test Code for Python27
test-code-older-py27:
runs-on: ubuntu-20.04
container:
image: python:${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
python-version: ['2.7.18']
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install tox
python -m pip install tox-gh-actions==2.8.1
- name: Test Code
run: tox
# Test Docs
test-docs:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install numpy
python -m pip install sphinx
python -m pip install numpydoc
- name: Test Docs
run: sphinx-build -W --keep-going doc _build/html
# Save Artifacts
create-save-artifacts:
runs-on: ubuntu-20.04
needs: [test-code, test-code-older-py3, test-code-older-py27, test-docs]
permissions:
contents: write
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install build
python -m pip install numpy
python -m pip install sphinx
python -m pip install numpydoc
- name: Create artifacts
run: |
python -m build
VERSION=$(python setup.py --version)
sphinx-build -W --keep-going doc _build/html
tar -C _build/html -zcf dist/docs-${VERSION}.tar.gz .
- name: Save artifacts to Github Actions
uses: actions/upload-artifact@v4
with:
name: docs, source tar, wheel
path: dist/*
if-no-files-found: error
- name: Deploy artifacts to GitHub Pages
shell: bash
run: |
SHORT_COMMIT=$(git rev-parse --short HEAD)
shopt -s extglob dotglob
rm -rf !(dist|.git|.|..)
cp dist/* .
git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
git checkout -b gh-pages
git update-ref -d HEAD
git add --all
git commit -m "Artifacts for $SHORT_COMMIT"
git config push.default simple
git push origin gh-pages --force
if: github.event_name == 'push' &&
(github.ref == 'refs/heads/master'|| startsWith(github.ref, 'refs/tags') )
# Deploy to GitHub Releases
deploy-github-releases:
runs-on: ubuntu-20.04
needs: [create-save-artifacts]
if: success() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Deploy to GitHub Releases
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASES_TOKEN }}
run: |
VERSION=$(python setup.py --version)
cat > release-notes.md <<EOL
Version $VERSION of PDS4 Python Tools and PDS4 Viewer.
EOL
extra_flags=''
if [[ "$VERSION" == *"dev"* ]]; then
extra_flags='--draft'
fi
gh release create v$VERSION --notes-file release-notes.md $extra_flags
# Deploy to PyPi
deploy-pypi:
runs-on: ubuntu-20.04
needs: [create-save-artifacts]
if: success() && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install build
- name: Create artifacts
run: |
python -m build
- name: Publish to Test PyPI
uses: pypa/[email protected]
with:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish to PyPI
uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
if: contains(github.ref, 'dev') == false