diff --git a/.github/workflows/python-publish.yaml b/.github/workflows/python-publish.yaml new file mode 100644 index 0000000..94b458b --- /dev/null +++ b/.github/workflows/python-publish.yaml @@ -0,0 +1,68 @@ +name: Package and release + +on: + release: + types: [published] + +jobs: + release-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.9' + + - name: Install poetry + uses: abatilo/actions-poetry@v2 + + - name: Setup a local virtual environment (if no poetry.toml file) + run: | + poetry config virtualenvs.create true --local + poetry config virtualenvs.in-project true --local + + - name: Define a cache for the virtual environment based on the dependencies lock file + uses: actions/cache@v3 + with: + path: ./.venv + key: venv-${{ hashFiles('poetry.lock') }} + + - name: Install the project dependencies + run: poetry install + + - name: Build + run: poetry build + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: release-dists + path: dist/ + if-no-files-found: error + + release: + needs: + - release-build + if: github.event_name == 'release' + runs-on: ubuntu-latest + permissions: + id-token: write + environment: + name: pypi + url: https://pypi.org/p/quri-parts-riqu + + steps: + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: release-dists + path: dist/ + + - name: Publish release distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index a2169ad..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,86 +0,0 @@ -name: Package and release - -on: - release: - types: [published] - -jobs: - update_version: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Extract version from tag - id: extract_version - run: | - VERSION=$(echo "${GITHUB_REF#refs/tags/v}") - echo "VERSION: $VERSION" - echo "::set-output name=version::$VERSION" - - - name: Update version in pyproject.toml - run: | - sed -i "s/^version = \".*\"/version = \"${{ steps.extract_version.outputs.version }}\"/" pyproject.toml - git config user.name "GitHub Actions" - git config user.email "actions@github.com" - git add pyproject.toml - git commit -m "Update version to ${{ steps.extract_version.outputs.version }}" - git push origin HEAD:refs/heads/main - - package: - needs: [update_version] - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.9' - - name: Install poetry - uses: abatilo/actions-poetry@v2 - - name: Setup a local virtual environment (if no poetry.toml file) - run: | - poetry config virtualenvs.create true --local - poetry config virtualenvs.in-project true --local - - uses: actions/cache@v3 - name: Define a cache for the virtual environment based on the dependencies lock file - with: - path: ./.venv - key: venv-${{ hashFiles('poetry.lock') }} - - name: Install the project dependencies - run: poetry install - - - name: Build - run: | - poetry build - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: dist - path: dist/* - if-no-files-found: error - - release: - needs: [package] - if: github.event_name == 'release' - runs-on: ubuntu-latest - - steps: - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: dist - path: ./dist - - name: Install Twine - run: python -m pip install twine - - name: Release to PyPI - run: python -m twine upload dist/* - env: - TWINE_USERNAME: "__token__" - TWINE_PASSWORD: ${{ secrets.TWINE_API_TOKEN }}