From 2aa87b1abbd6b66f77de6730f49dfddaa32bc739 Mon Sep 17 00:00:00 2001 From: Adrian Moennich Date: Sat, 30 Mar 2024 15:25:59 +0100 Subject: [PATCH] ci: Add PyPI publish workflow --- .github/utils/check_version.py | 19 +++++ .github/workflows/pypi.yml | 148 +++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 .github/utils/check_version.py create mode 100644 .github/workflows/pypi.yml diff --git a/.github/utils/check_version.py b/.github/utils/check_version.py new file mode 100644 index 00000000..4a3cd5c1 --- /dev/null +++ b/.github/utils/check_version.py @@ -0,0 +1,19 @@ +# This file is part of the Indico plugins. +# Copyright (C) 2002 - 2024 CERN +# +# The Indico plugins are free software; you can redistribute +# them and/or modify them under the terms of the MIT License; +# see the LICENSE file for more details. + +import sys +from configparser import ConfigParser + + +cp = ConfigParser() +cp.read('_meta/setup.cfg') +version = cp['metadata']['version'] +tag_version = sys.argv[1] + +if tag_version != version: + print(f'::error::Tag version {tag_version} does not match package version {version}') + sys.exit(1) diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 00000000..c69569d5 --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,148 @@ +name: PyPI release ๐Ÿ ๐Ÿ“ฆ + +env: + PYTHON_VERSION: '3.12' + TZ: Europe/Zurich + +on: + push: + tags: + - 'v*' + - '!v0.*' + - '!v1.*' + - '!v2.*' + - '!v3.0' + - '!v3.0.*' + - '!v3.1' + - '!v3.1.*' + - '!v3.2' + - '!v3.2.*' + - '!*\+docs' + +permissions: + contents: read + +jobs: + check-version: + name: Check version + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + name: Set up Python ๐Ÿ + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Check version ๐Ÿ” + run: python .github/utils/check_version.py "${GITHUB_REF#refs/tags/v}" + + build: + name: Build plugins ๐Ÿ— + needs: check-version + uses: indico/indico-gh-actions/.github/workflows/build-plugins.yml@master + with: + directory: public + add-version-suffix: false + + test-install: + name: Test installing plugins + needs: build + runs-on: ubuntu-22.04 + steps: + - name: Checkout core + uses: actions/checkout@v4 + with: + path: indico + repository: indico/indico + + - name: Download build artifacts ๐Ÿ“ฆ + uses: actions/download-artifact@v4 + with: + merge-multiple: true + pattern: plugin-wheel-* + path: wheels + + + - name: Set up Python ๐Ÿ + uses: actions/setup-python@v5 + with: + python-version: ${{ env.PYTHON_VERSION }} + cache: pip + cache-dependency-path: indico/requirements*.txt + + - name: Install Indico ๐Ÿ”ง + working-directory: indico + run: | + sudo apt-get install libpq-dev + pip install --user -U pip setuptools wheel + pip install --user -e '.[dev]' + + - name: Install plugins ๐Ÿงฉ + run: | + pip install wheels/*.whl + + - name: List plugins ๐Ÿงฉ + run: | + indico setup list-plugins + + create-github-release: + name: Create GitHub release ๐Ÿ™ + # Upload wheel to a GitHub release. It remains available as a build artifact for a while as well. + needs: + - build + - test-install + runs-on: ubuntu-22.04 + permissions: + contents: write + steps: + - name: Download build artifacts ๐Ÿ“ฆ + uses: actions/download-artifact@v4 + with: + merge-multiple: true + pattern: plugin-wheel-* + path: dist + - name: Create draft release ๐Ÿ™ + run: >- + gh release create + --draft + --repo ${{ github.repository }} + --title ${{ github.ref_name }} + ${{ github.ref_name }} + dist/* + env: + GH_TOKEN: ${{ github.token }} + + publish-pypi: + name: Publish ๐Ÿš€ + needs: build + # Wait for approval before attempting to upload to PyPI. This allows reviewing the + # files in the draft release. + environment: publish + runs-on: ubuntu-22.04 + permissions: + contents: write + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + merge-multiple: true + pattern: plugin-wheel-* + path: dist + # Try uploading to Test PyPI first, in case something fails. + - name: Publish to Test PyPI ๐Ÿงช + uses: pypa/gh-action-pypi-publish@v1.8.14 + with: + repository-url: https://test.pypi.org/legacy/ + packages-dir: dist/ + skip-existing: true + # - name: Publish to PyPI ๐Ÿš€ + # uses: pypa/gh-action-pypi-publish@v1.8.14 + # with: + # packages-dir: dist/ + - name: Publish GitHub release ๐Ÿ™ + run: >- + gh release edit + --draft=false + --repo ${{ github.repository }} + ${{ github.ref_name }} + env: + GH_TOKEN: ${{ github.token }}