Publish NIMS #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update docs and Publish NIMS | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
concurrency: publish_to_pypi | |
env: | |
# Versions are also listed in PR.yml | |
POETRY_VERSION: 1.2.2 | |
PYTHON_VERSION: 3.9 | |
jobs: | |
check_nims: | |
name: Check NIMS | |
uses: ./.github/workflows/check_nims.yml | |
check_nimg: | |
name: Check NIMG | |
uses: ./.github/workflows/check_nimg.yml | |
# Don't run check_examples.yml because the examples may reference a | |
# package version that doesn't exist yet. | |
build: | |
name: Update API reference docs and Publish NIMS Package to PyPI | |
runs-on : ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- uses: Gr1N/setup-poetry@v8 | |
with: | |
poetry-version: ${{ env.POETRY_VERSION }} | |
- name: Check for lock changes | |
run: poetry lock --check | |
- uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pypoetry/virtualenvs | |
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }} | |
# If the tag is 0.1.0, this will set the version of NIMS package to 0.1.0 | |
- name: Store version from Tag | |
id: vars | |
run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT | |
- name: Update NIMS package version based on tag name. | |
run: | | |
poetry version ${{ steps.vars.outputs.tag }} | |
- name: Update NIMG package version based on tag name. | |
run: | | |
poetry version ${{ steps.vars.outputs.tag }} | |
working-directory: ./ni_measurementlink_generator | |
- name: Install ni-measurementlink-service (all extras, docs) | |
run: poetry install -v --all-extras --with docs | |
- name: Build docs | |
run: | | |
rm -rf docs | |
mkdir -p docs | |
poetry run sphinx-build _docs_source docs -b html | |
- name: Commit file changes | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
run: | | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Promote NIMS package version and update Sphinx generated files in _docs" -a | |
- name: Push changes to the appropriate branch | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
uses: CasperWA/push-protected@v2 | |
with: | |
token: ${{ secrets.ADMIN_PAT }} | |
branch: ${{ github.event.release.target_commitish }} | |
unprotect_reviews: true | |
# To Test the Publish use : poetry publish --build --username __token__ --password ${{ secrets.TEST_PYPI_TOKEN }} -r test-pypi | |
- name: Build NIMS Python package and publish to PyPI | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
run: | | |
poetry publish --build --username __token__ --password ${{ secrets.PYPI_TOKEN }} | |
- name: Build NIMG Python package and publish to PyPI | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
run: | | |
poetry publish --build --username __token__ --password ${{ secrets.PYPI_TOKEN }} | |
working-directory: ./ni_measurementlink_generator | |
- name: Create archives of the examples | |
env: | |
EXAMPLE_ARCHIVE: measurementlink-python-examples-${{ steps.vars.outputs.tag }} | |
run: | | |
# Use --prefix for the tarball but not the zip file. Windows zip tools often create a directory automatically. | |
git archive -o dist/${EXAMPLE_ARCHIVE}.zip ${GITHUB_REF}:examples/ | |
git archive -o dist/${EXAMPLE_ARCHIVE}.tar.gz --prefix ${EXAMPLE_ARCHIVE}/ ${GITHUB_REF}:examples/ | |
- name: Upload release assets | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "dist/measurementlink-python-examples-*" | |
allowUpdates: true | |
omitBodyDuringUpdate: true | |
omitDraftDuringUpdate: true | |
omitNameDuringUpdate: true | |
omitPrereleaseDuringUpdate: true | |
updateOnlyUnreleased: false | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: NIMS Artifacts | |
path: dist/ # path/to/artifact |