From 76e13ea00755d3284c6eec83869b2df324ce8f97 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Thu, 18 Sep 2025 18:22:28 -0500 Subject: [PATCH 1/4] github: Rewrite publish workflow --- .github/workflows/Publish_NIMS.yml | 120 ---------------------- .github/workflows/publish.yml | 154 +++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 120 deletions(-) delete mode 100644 .github/workflows/Publish_NIMS.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/Publish_NIMS.yml b/.github/workflows/Publish_NIMS.yml deleted file mode 100644 index cf3d8bdf5..000000000 --- a/.github/workflows/Publish_NIMS.yml +++ /dev/null @@ -1,120 +0,0 @@ -name: Publish NIMS - -on: - release: - types: [published] - workflow_dispatch: - -concurrency: publish_to_pypi - -jobs: - check_nims: - name: Check NIMS - uses: ./.github/workflows/check_nims.yml - # Don't run check_nimg.yml because the generator now depends - # on the service and may reference a package version that doesn't exist yet. - # 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 - permissions: - contents: write - steps: - - name: Check out repo - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0 - - name: Set up Python - uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 - - name: Set up Poetry - uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 - - - name: Check for lock changes - run: poetry check --lock - working-directory: ./packages/service - - # 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 }} - working-directory: ./packages/service - - - name: Update NIMG package version based on tag name. - run: | - poetry version ${{ steps.vars.outputs.tag }} - working-directory: ./packages/generator - - - name: Update SDK package version based on tag name. - run: | - poetry version ${{ steps.vars.outputs.tag }} - working-directory: ./packages/sdk - - - 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@74d25b8aa10e0c29024138735d32f3c0b75f9279 # v2.16.0 - 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 }} - working-directory: ./packages/service - - - 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: ./packages/generator - - - name: Build SDK 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: ./packages/sdk - - - 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. - rm -rf dist - mkdir -p dist - 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@bcfe5470707e8832e12347755757cec0eb3c22af # v1.18.0 - with: - artifacts: "dist/measurement-plugin-python-examples-*" - allowUpdates: true - omitBodyDuringUpdate: true - omitDraftDuringUpdate: true - omitNameDuringUpdate: true - omitPrereleaseDuringUpdate: true - updateOnlyUnreleased: false - - - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 - with: - name: NIMS Artifacts - path: ./packages/service/dist/ # path/to/artifact \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..b487721bb --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,154 @@ +name: Publish NIMS + +on: + release: + types: [published] + workflow_dispatch: + inputs: + environment: + description: The environment to publish to. + default: 'none' + required: true + type: choice + options: + - none + - pypi + - testpypi + +env: + environment: ${{ github.event_name == 'release' && 'pypi' || inputs.environment }} + environment-info: | + { + "pypi": { + "base-url": "https://pypi.org", + "upload-url": "https://upload.pypi.org/legacy/" + }, + "testpypi": { + "base-url": "https://test.pypi.org", + "upload-url": "https://test.pypi.org/legacy/" + } + } + package-name: | + { + "generator": "ni_measurement_plugin_sdk_generator", + "sdk": "ni_measurement_plugin_sdk", + "service": "ni_measurement_plugin_sdk_service" + } + +jobs: + # Do not call check_examples.yml because the examples may depend on the version we are releasing. + check_nimg: + name: Check generator + uses: ./.github/workflows/check_nimg.yml + check_nims: + name: Check service + uses: ./.github/workflows/check_nims.yml + build_package: + name: Build ${{ matrix.package }} + runs-on: ubuntu-latest + needs: [check_nimg, check_nims] + strategy: + matrix: + package: [generator, sdk, service] + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Set up Python + uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Set up Poetry + uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Check project version + if: github.event_name == 'release' + uses: ni/python-actions/check-project-version@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + with: + project-directory: ./packages/${{ matrix.package }} + - name: Build distribution packages + run: poetry build + working-directory: ./packages/${{ matrix.package }} + - name: Upload build artifacts + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 + with: + name: ${{ matrix.package }}-distribution-packages + path: dist/* + publish_package: + name: Publish ${{ matrix.package }} to PyPI + if: github.event_name == 'release' || inputs.environment != 'none' + runs-on: ubuntu-latest + needs: [build_package] + environment: + # This logic is duplicated because `name` doesn't support the `env` context. + name: ${{ github.event_name == 'release' && 'pypi' || inputs.environment }} + url: ${{ fromJson(env.environment-info)[env.environment].base-url }}/p/${{ fromJson(env.package-name)[matrix.package] }} + permissions: + id-token: write + strategy: + matrix: + package: [generator, sdk, service] + steps: + - name: Download build artifacts + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 + with: + name: ${{ matrix.package }}-distribution-packages + path: dist/ + - run: ls -lR + - name: Upload to ${{ env.environment }} + uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4 + with: + repository-url: ${{ fromJson(env.environment-info)[env.environment].upload-url }} + publish_examples: + name: Publish examples + runs-on: ubuntu-latest + needs: [check_nimg, check_nims] + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Create archives of the examples + env: + EXAMPLE_ARCHIVE: measurement-plugin-python-examples-${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name }} + run: | + # Use --prefix for the tarball but not the zip file. Windows zip tools often create a directory automatically. + rm -rf dist + mkdir -p dist + 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@bcfe5470707e8832e12347755757cec0eb3c22af # v1.18.0 + with: + artifacts: "dist/measurement-plugin-python-examples-*" + allowUpdates: true + omitBodyDuringUpdate: true + omitDraftDuringUpdate: true + omitNameDuringUpdate: true + omitPrereleaseDuringUpdate: true + updateOnlyUnreleased: false + update_versions: + name: Update package versions + runs-on: ubuntu-latest + needs: [build_package] + permissions: + contents: write + pull-requests: write + steps: + - name: Check out repo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Set up Python + uses: ni/python-actions/setup-python@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + - name: Set up Poetry + uses: ni/python-actions/setup-poetry@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + # Create one pull request that updates all three packages. + - name: Update generator project version + uses: ni/python-actions/update-project-version@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + with: + project-directory: ./packages/generator + create-pull-request: false + - name: Update sdk project version + uses: ni/python-actions/update-project-version@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + with: + project-directory: ./packages/sdk + create-pull-request: false + - name: Update service project version + uses: ni/python-actions/update-project-version@f0276f7f58868ec0d0d1a86377287c9e6fe0c6e7 # v0.5.0 + with: + project-directory: ./packages/service + create-pull-request: true From 6cd97c3dcc0dbd38174410a189e9a8b5caa34a39 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Thu, 18 Sep 2025 18:31:50 -0500 Subject: [PATCH 2/4] github: Fix dist path --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b487721bb..4630a480d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -69,7 +69,7 @@ jobs: uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: ${{ matrix.package }}-distribution-packages - path: dist/* + path: ./packages/${{ matrix.package }}/dist/* publish_package: name: Publish ${{ matrix.package }} to PyPI if: github.event_name == 'release' || inputs.environment != 'none' From 5f43b74daf2eddb508809194e74fe478bd1ee920 Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Thu, 18 Sep 2025 18:40:11 -0500 Subject: [PATCH 3/4] github: Make publish_examples work with workflow_call --- .github/workflows/publish.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4630a480d..8e0da81c6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -102,9 +102,13 @@ jobs: steps: - name: Check out repo uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + - name: Get version + id: get-version + run: echo "version="$(poetry version --short)" >> "$GITHUB_OUTPUT" + working-directory: ./packages/service - name: Create archives of the examples env: - EXAMPLE_ARCHIVE: measurement-plugin-python-examples-${{ github.event_name == 'release' && github.event.release.tag_name || github.ref_name }} + EXAMPLE_ARCHIVE: measurement-plugin-python-examples-${{ steps.get-version.outputs.version }} run: | # Use --prefix for the tarball but not the zip file. Windows zip tools often create a directory automatically. rm -rf dist From d6bd17de7f86ce203c22597b088b5b957eeddfbd Mon Sep 17 00:00:00 2001 From: Brad Keryan Date: Thu, 18 Sep 2025 18:42:32 -0500 Subject: [PATCH 4/4] github: Fix quoting --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8e0da81c6..bf4076065 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -104,7 +104,7 @@ jobs: uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Get version id: get-version - run: echo "version="$(poetry version --short)" >> "$GITHUB_OUTPUT" + run: echo "version=$(poetry version --short)" >> "$GITHUB_OUTPUT" working-directory: ./packages/service - name: Create archives of the examples env: