Skip to content

Merge pull request #73 from rok4/develop #81

Merge pull request #73 from rok4/develop

Merge pull request #73 from rok4/develop #81

name: Test, build and publish artefacts and documentation
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+b[0-9]+'
jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
job_status: ${{ job.status }}
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
generateReleaseNotes: true
draft: false
prerelease: ${{ contains(github.ref_name ,'b') }}
build_and_test:
name: Test and build artefacts
needs: create_release
outputs:
job_status: ${{ job.status }}
strategy:
max-parallel: 2
fail-fast: true
matrix:
include:
- os: ubuntu-20.04
python-version: "3.8"
- os: ubuntu-22.04
python-version: "3.10"
runs-on: ${{ matrix.os }}
steps:
- name: Checkout project
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/pyproject.toml'
- name: Install system dependencies
run: |
sudo apt update
sudo apt -y install python3-rados python3-gdal
- name: Install python dependencies
run: |
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade build bump2version
bump2version --current-version 0.0.0 --new-version ${{ github.ref_name }} patch
pip install -e .
echo "/usr/lib/python3/dist-packages/" >.venv/lib/python${{ matrix.python-version }}/site-packages/system.pth
- name: Run unit tests
run: |
source .venv/bin/activate
pip install -e .[test]
coverage run -m pytest
coverage report -m
- name: Build unit tests report
if: "! contains(github.ref_name,'b') && matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
coverage html -d dist/tests/
rm dist/tests/.gitignore
- name: Build package
if: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
python3 -m build
- name: Build documentation
if: "! contains(github.ref_name,'b') && matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
run: |
source .venv/bin/activate
pip install -e .[doc]
pdoc3 --html --output-dir dist/ rok4
cp README.md CHANGELOG.md dist/
- name: Upload packages, tests results and documentation
if: "matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.8'"
uses: actions/upload-artifact@v3
with:
name: dist-py3
path: dist/
if-no-files-found: error
retention-days: 1
publish_artefacts:
name: Add built artefacts to release and PyPI
needs: [create_release, build_and_test]
if: "always() && needs.create_release.outputs.job_status == 'success' && needs.build_and_test.outputs.job_status == 'success'"
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: dist-py3
path: dist/
- name: Add wheel package to release
id: upload-release-whl
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/rok4-${{ github.ref_name }}-py3-none-any.whl
asset_name: rok4-${{ github.ref_name }}-py3-none-any.whl
asset_content_type: application/zip
- name: Add tarball package to release
id: upload-release-targz
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/rok4-${{ github.ref_name }}.tar.gz
asset_name: rok4-${{ github.ref_name }}.tar.gz
asset_content_type: application/zip
- name: Isolate wheel and tarball
run: |
mkdir to_publish
cp ./dist/rok4-${{ github.ref_name }}* to_publish/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
packages_dir: to_publish/
commit_documentation:
name: Add documentation and unit tests results into gh-pages branch
needs: build_and_test
if: "always() && ! contains(github.ref_name,'b') && needs.create_release.outputs.job_status == 'success' && needs.build_and_test.outputs.job_status == 'success'"
runs-on: ubuntu-latest
steps:
- name: Checkout project on gh-pages
uses: actions/checkout@v4
with:
ref: 'gh-pages'
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/download-artifact@v3
with:
name: dist-py3
path: artifact/
- name: Copy version elements to final location
run: |
mkdir -p docs/versions/${{ github.ref_name }}
cp -r artifact/rok4 docs/versions/${{ github.ref_name }}/
cp -r artifact/tests docs/versions/${{ github.ref_name }}/
- name: Add pages from templates
run: |
sed "s#__version__#${{ github.ref_name }}#" templates/mkdocs.template.yml >mkdocs.yml
sed "s#__version__#${{ github.ref_name }}#" templates/unit-tests.template.md >docs/versions/${{ github.ref_name }}/unit-tests.md
sed "s#__version__#${{ github.ref_name }}#" templates/documentation.template.md >docs/versions/${{ github.ref_name }}/documentation.md
sed "s#__version__#${{ github.ref_name }}#" templates/index-version.template.md >docs/versions/${{ github.ref_name }}/index.md
cat artifact/README.md >>docs/versions/${{ github.ref_name }}/index.md
sed -i "s#x.y.z#${{ github.ref_name }}#g" docs/versions/${{ github.ref_name }}/index.md
cp templates/index-versions.template.md docs/versions/index.md
sed "s/^## \(.*\)$/## \1 \n\n[➔ Lien vers la documentation](\1\/index.md) /" artifact/CHANGELOG.md >>docs/versions/index.md
sed "s#__version__#${{ github.ref_name }}#" templates/latest.template.html >docs/versions/latest/index.html
rm -r artifact
- name: Publish on gh-pages branch
run: |
git config user.name github-actions
git config user.email [email protected]
git add -v docs/versions/${{ github.ref_name }}/ docs/versions/latest/ docs/versions/index.md mkdocs.yml
git commit -m "Add documentation for version ${{ github.ref_name }}"
git push
delete_version:
name: Remove release and tag if error occured
needs: build_and_test
if: "always() && needs.create_release.outputs.job_status == 'success' && needs.build_and_test.outputs.job_status != 'success'"
runs-on: ubuntu-latest
steps:
- name: Remove release and tag
uses: dev-drprasad/[email protected]
with:
tag_name: ${{ github.ref_name }}
delete_release: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}