Publish NIMS #47
Workflow file for this run
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: Publish NIMS | |
on: | |
release: | |
types: [published] | |
workflow_dispatch: | |
concurrency: publish_to_pypi | |
env: | |
# Versions are also listed in PR.yml | |
POETRY_VERSION: 1.8.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: Build | |
runs-on : ubuntu-latest | |
steps: | |
- name: Check out repo | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- name: Set up Poetry | |
uses: Gr1N/setup-poetry@v9 | |
with: | |
poetry-version: ${{ env.POETRY_VERSION }} | |
- name: Check for lock changes | |
run: poetry lock --check | |
# 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_measurement_plugin_generator | |
- name: Commit file changes | |
id: commit | |
if: ${{ startsWith(github.event.release.target_commitish, 'main') || startsWith(github.event.release.target_commitish, 'releases/') }} | |
run: | | |
echo "version_changed=false" >> $GITHUB_OUTPUT | |
if [ -n "$(git status --porcelain)" ]; then | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git add . | |
git commit -m "Promote NIMS and NIMG package version" -a | |
echo "version_changed=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Push changes to the appropriate branch | |
if: ${{ steps.commit.outputs.version_changed && (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_measurement_plugin_generator | |
- name: Create archives of the examples | |
env: | |
EXAMPLE_ARCHIVE: measurement-plugin-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/measurement-plugin-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 |