From fa2fe63a65fb3e4024d5db6fc1936ff6c0a181ae Mon Sep 17 00:00:00 2001 From: Marlon Saglia Date: Thu, 29 Aug 2024 13:18:16 +0200 Subject: [PATCH 1/3] feat: update PyPI release workflow to use OIDC --- .../{pyvespa.yml => release-pyvespa.yml} | 21 ++- .../{vespacli.yml => release-vespacli.yml} | 128 +++++++++--------- vespacli/pyproject.toml | 2 +- vespacli/utils/check_latest_version.py | 27 +++- vespacli/vespacli/_version_generated.py | 1 - 5 files changed, 100 insertions(+), 79 deletions(-) rename .github/workflows/{pyvespa.yml => release-pyvespa.yml} (73%) rename .github/workflows/{vespacli.yml => release-vespacli.yml} (54%) delete mode 100644 vespacli/vespacli/_version_generated.py diff --git a/.github/workflows/pyvespa.yml b/.github/workflows/release-pyvespa.yml similarity index 73% rename from .github/workflows/pyvespa.yml rename to .github/workflows/release-pyvespa.yml index bd3c0a09..804b7350 100644 --- a/.github/workflows/pyvespa.yml +++ b/.github/workflows/release-pyvespa.yml @@ -7,9 +7,21 @@ on: jobs: update_version: runs-on: ubuntu-latest + + # The environment is reuiqred for OIDC to work. + # Ref: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ + environment: + name: "PyPI - Pyvespa" + url: https://pypi.org/p/pyvespa + + permissions: + contents: read + id-token: write + env: # Workaround to ensure that the version is available RELEASE_REF: ${{ github.ref || format('{0}{1}', 'refs/tags/', github.event.release.tag_name) }} + steps: - uses: actions/checkout@v4 @@ -40,9 +52,6 @@ jobs: python -m build - name: Upload to PyPI - if: github.event_name == 'release' - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_PYVESPA }} - run: | - python -m twine upload dist/* + uses: pypa/gh-action-pypi-publish@release/v1 + with: + print-hash: true diff --git a/.github/workflows/vespacli.yml b/.github/workflows/release-vespacli.yml similarity index 54% rename from .github/workflows/vespacli.yml rename to .github/workflows/release-vespacli.yml index 38eafbdb..96467ba3 100644 --- a/.github/workflows/vespacli.yml +++ b/.github/workflows/release-vespacli.yml @@ -11,10 +11,10 @@ on: - cron: "0 0 * * 1-4" jobs: - check-and-update: + prepare: runs-on: ubuntu-latest outputs: - version: ${{ steps.set_output.outputs.version }} + version: ${{ steps.check_latest_version.outputs.version }} steps: - uses: actions/checkout@v4 @@ -28,6 +28,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -e .[build] + - name: Check latest version and set version variable id: check_latest_version run: | @@ -36,18 +37,36 @@ jobs: # Set the output variable echo "version=$version" >> $GITHUB_OUTPUT - - name: Update the version (if not NA) - if: ${{ (steps.check_latest_version.outputs.version != 'NA') }} + + check-and-update: + runs-on: ubuntu-latest + # Only run if we have a new version + if: ${{ needs.prepare.outputs.version != 'NA' }} + needs: + - prepare + env: + VERSION: ${{ needs.prepare.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Install dependencies and this repo + run: | + python -m pip install --upgrade pip + pip install -e .[build] + + - name: Update the version run: | - # Print evaluation of the condition - echo "Version is not NA, updating version to ${{ steps.check_latest_version.outputs.version }}" - echo "Updating Vespa CLI version to ${{ steps.check_latest_version.outputs.version }}" - python utils/update_version.py --version ${{ steps.check_latest_version.outputs.version }} + echo "Updating Vespa CLI version to ${VERSION}" + python utils/update_version.py --version "${VERSION}" - name: Download latest binaries - if: ${{ steps.check_latest_version.outputs.version != 'NA' }} run: | - python utils/download_binaries.py --version ${{ steps.check_latest_version.outputs.version }} + python utils/download_binaries.py --version "${VERSION}" - name: Upload binaries as artifact uses: actions/upload-artifact@v4 @@ -55,19 +74,20 @@ jobs: name: binaries path: vespacli/vespacli/go-binaries - - name: Set the output variable - id: set_output - if: ${{ steps.check_latest_version.outputs.version != 'NA' }} - run: | - echo "version=${{ steps.check_latest_version.outputs.version }}" >> $GITHUB_OUTPUT + test: - needs: check-and-update - if: ${{ needs.check-and-update.outputs.version != 'NA' }} runs-on: ${{ matrix.os }} + # Only run if we have a new version + if: ${{ needs.prepare.outputs.version != 'NA' }} + needs: + - prepare + - check-and-update + env: + VERSION: ${{ needs.prepare.outputs.version }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-12, macos-14] - python-version: ["3.10", "3.11"] # Update or modify Python versions as needed + os: [ubuntu-24.04, ubuntu-latest, windows-latest, macos-13, macos-latest] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -85,16 +105,16 @@ jobs: - name: Set permissions on all files in go-binaries run: | chmod -R +x vespacli/go-binaries/* - + - name: Install dependencies run: | python -m pip install --upgrade pip pip install -e .[build] - + - name: Update latest version run: | - python utils/update_version.py --version ${{ needs.check-and-update.outputs.version }} - + python utils/update_version.py --version "${VERSION}" + - name: Install dependencies run: | python -m pip install --upgrade pip @@ -104,45 +124,25 @@ jobs: run: | vespa version - create-pr: - needs: [check-and-update, test] - outputs: - version: ${{ needs.check-and-update.outputs.version }} + release: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.10" - - - name: Install dependencies and this repo - run: | - python -m pip install --upgrade pip - pip install -e .[build] + # The environment is reuiqred for OIDC to work. + # Ref: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ + environment: + name: "PyPI - VespaCLI" + url: https://pypi.org/p/vespacli - - name: Update latest version - run: | - python utils/update_version.py --version ${{ needs.check-and-update.outputs.version }} + permissions: + contents: read + id-token: write + + needs: + - prepare + - test + env: + VERSION: ${{ needs.prepare.outputs.version }} - - name: Commit and PR - if: github.event_name == 'release' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NEW_BRANCH: "update-vespa-cli-version-${{ needs.check-and-update.outputs.version }}" - run: | - git checkout -b "${NEW_BRANCH}" - git commit -a -m "Update Vespa CLI version to ${{ needs.check-and-update.outputs.version }}" - git push --set-upstream origin "${NEW_BRANCH}" - gh pr create -B master -H "${NEW_BRANCH}" \ - -t "Update Vespa CLI version to ${{ needs.check-and-update.outputs.version }}" \ - -b ":robot: This PR updates the Vespa CLI version to ${{ needs.check-and-update.outputs.version }}" \ - -l "vespacli" - - release: - needs: create-pr - runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -165,18 +165,16 @@ jobs: - name: Set permissions on all files in go-binaries run: | chmod -R +x vespacli/go-binaries/* - + - name: Update latest version run: | - python utils/update_version.py --version ${{ needs.create-pr.outputs.version }} + python utils/update_version.py --version "${VERSION}" - name: Build run: | python -m build - name: Upload to PyPI - env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN_VESPACLI }} - run: | - python -m twine upload dist/* + uses: pypa/gh-action-pypi-publish@release/v1 + with: + print-hash: true diff --git a/vespacli/pyproject.toml b/vespacli/pyproject.toml index a08a476d..21dedd74 100644 --- a/vespacli/pyproject.toml +++ b/vespacli/pyproject.toml @@ -8,7 +8,7 @@ description = "A Python wrapper for Vespa CLI tools, supporting multiple platfor keywords = [ "vespa", "cli", "wrapper",] name = "vespacli" readme = "README.md" -version = "8.391.23" +version = "8.dev" [[project.authors]] name = "Thomas Thoresen" email = "thomas@vespa.ai" diff --git a/vespacli/utils/check_latest_version.py b/vespacli/utils/check_latest_version.py index d4243067..348017ce 100644 --- a/vespacli/utils/check_latest_version.py +++ b/vespacli/utils/check_latest_version.py @@ -1,13 +1,28 @@ from download_binaries import VespaBinaryDownloader -from vespacli._version_generated import vespa_version import sys +import requests +from packaging import version -if __name__ == "__main__": + +def get_latest_pypi_version() -> version.Version: + response = requests.get( + "https://pypi.org/simple/vespacli/", + headers={"Accept": "application/vnd.pypi.simple.v1+json"} + ) + latest_version = response.json()["releases"][-1]["version"] + return version.parse(latest_version) + + +def get_latest_github_version() -> version.Version: downloader = VespaBinaryDownloader() - new_version = downloader.get_latest_version() - found_newer = new_version != vespa_version - if found_newer: - print(f"{new_version}") + return version.parse(downloader.get_latest_version()) + + +if __name__ == "__main__": + gh_release = get_latest_github_version() + pypi_release = get_latest_pypi_version() + if gh_release > pypi_release: + print(f"{0}" % gh_release) else: print("NA") sys.exit(0) diff --git a/vespacli/vespacli/_version_generated.py b/vespacli/vespacli/_version_generated.py deleted file mode 100644 index 0995ce62..00000000 --- a/vespacli/vespacli/_version_generated.py +++ /dev/null @@ -1 +0,0 @@ -vespa_version = "8.391.23" # Automatically updated by github actions bot vespacli/_version_generated.py From e16f314196c915492c10a79e70a07ccc2eff6240 Mon Sep 17 00:00:00 2001 From: "Marlon (Esolitos) Saglia" Date: Mon, 2 Sep 2024 11:07:07 +0200 Subject: [PATCH 2/3] fix typo Co-authored-by: Thomas Hjelde Thoresen --- .github/workflows/release-vespacli.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-vespacli.yml b/.github/workflows/release-vespacli.yml index 96467ba3..59bc7f35 100644 --- a/.github/workflows/release-vespacli.yml +++ b/.github/workflows/release-vespacli.yml @@ -127,7 +127,7 @@ jobs: release: runs-on: ubuntu-latest - # The environment is reuiqred for OIDC to work. + # The environment is required for OIDC to work. # Ref: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ environment: name: "PyPI - VespaCLI" From 85ce6f4bebeb2e23b3836fc2bfeeb7c981239d71 Mon Sep 17 00:00:00 2001 From: "Marlon (Esolitos) Saglia" Date: Mon, 2 Sep 2024 11:07:20 +0200 Subject: [PATCH 3/3] fix typo Co-authored-by: Thomas Hjelde Thoresen --- .github/workflows/release-pyvespa.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-pyvespa.yml b/.github/workflows/release-pyvespa.yml index 804b7350..a050aba8 100644 --- a/.github/workflows/release-pyvespa.yml +++ b/.github/workflows/release-pyvespa.yml @@ -8,7 +8,7 @@ jobs: update_version: runs-on: ubuntu-latest - # The environment is reuiqred for OIDC to work. + # The environment is required for OIDC to work. # Ref: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ environment: name: "PyPI - Pyvespa"