Skip to content

Commit

Permalink
WIP: Test pypi publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Batalex committed Jan 16, 2025
1 parent 928d62c commit a352fd3
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 121 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concurrency:
cancel-in-progress: true

on:
pull_request:
workflow_dispatch:

jobs:
tests:
Expand Down
266 changes: 146 additions & 120 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,58 @@ env:
BRANCH: ${{ github.ref_name }}

on:
pull_request:
push:
# Sequence of patterns matched against refs/tags
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
tests:
uses: ./.github/workflows/ci-tests.yaml
# tests:
# uses: ./.github/workflows/ci-tests.yaml

release_checks:
name: Checks before pkg build
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
fetch-depth: 0
- id: setup_python
name: Setup Python
uses: actions/[email protected]
with:
python-version: "3.10"
architecture: x64
- id: install_environment
name: Set up build environment
run: |
make setup
# release_checks:
# name: Checks before pkg build
# runs-on: ubuntu-latest
# timeout-minutes: 5
# strategy:
# fail-fast: true
# steps:
# - id: checkout
# name: Checkout repo
# uses: actions/checkout@v4
# with:
# ref: ${{ env.BRANCH }}
# fetch-depth: 0
# - id: setup_python
# name: Setup Python
# uses: actions/[email protected]
# with:
# python-version: "3.10"
# architecture: x64
# - id: install_environment
# name: Set up build environment
# run: |
# make setup

- id: package_metadata
name: Fetch package metadata
run: |
NAME=$(poetry version | awk '{print $1}')
VERSION=$(poetry version | awk '{print $2}')
echo "name=$NAME" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
# - id: package_metadata
# name: Fetch package metadata
# run: |
# NAME=$(poetry version | awk '{print $1}')
# VERSION=$(poetry version | awk '{print $2}')
# echo "name=$NAME" >> "$GITHUB_OUTPUT"
# echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- id: version_vs_tag_check
name: Check if tag version matches project version
run: |
VERSION=${{ steps.package_metadata.outputs.version }}
BRANCH=${{ env.BRANCH }}
if [[ "$BRANCH" != "v$VERSION" ]]; then exit 1; fi
# - id: version_vs_tag_check
# name: Check if tag version matches project version
# run: |
# VERSION=${{ steps.package_metadata.outputs.version }}
# BRANCH=${{ env.BRANCH }}
# if [[ "$BRANCH" != "v$VERSION" ]]; then exit 1; fi

outputs:
package_name: ${{ steps.package_metadata.outputs.name }}
package_version: ${{ steps.package_metadata.outputs.version }}
# outputs:
# package_name: ${{ steps.package_metadata.outputs.name }}
# package_version: ${{ steps.package_metadata.outputs.version }}

build:
name: Build package
Expand All @@ -80,87 +81,112 @@ jobs:
name: distfiles
path: dist/

autorelease:
name: Release the package on github
needs: [release_checks, tests, build]
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
steps:
- id: checkout
name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ env.BRANCH }}
fetch-depth: 0
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: distfiles
path: dist/
- id: artifact_names
name: Compute artifact names outputs
run: |
_NAME=${{ needs.release_checks.outputs.package_name }}
_VERSION=${{ needs.release_checks.outputs.package_version }}
echo "wheel=${_NAME}-${_VERSION}-py3-none-any.whl" >> "$GITHUB_OUTPUT"
echo "tarball=${_NAME}-${_VERSION}.tar.gz" >> "$GITHUB_OUTPUT"
- name: Create Github Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body_path: ".github/RELEASE-TEMPLATE.md"
files: |
dist/${{ steps.artifact_names.outputs.wheel }}
dist/${{ steps.artifact_names.outputs.tarball }}
outputs:
version: ${{ needs.release_checks.outputs.package_version }}
wheel: ${{ steps.artifact_names.outputs.wheel }}
tarball: ${{ steps.artifact_names.outputs.tarball }}

upload-pypi:
name: Publish to PyPI
needs: [release_checks, tests, build]
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: distfiles
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

environment:
name: testpypi
url: https://test.pypi.org/p/<package-name>

permissions:
id-token: write # Needed for trusted publishing (https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)
id-token: write # IMPORTANT: mandatory for trusted publishing

test:
name: Test Release
runs-on: ubuntu-latest
timeout-minutes: 5
env:
DOWNLOADS_PATH: "/releases/download"
needs: [autorelease]
steps:
- id: check-tar-gz
name: Check tar.gz package
run: |
# check if release is now published and available
TARBALL=${{ needs.autorelease.outputs.tarball }}
VERSION=${{ needs.autorelease.outputs.version }}
echo "Checking latest available Spark package release: ${TARBALL}"
STATUSCODE=$(curl --silent --head $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${TARBALL} | head -n 1 | cut -d' ' -f2)
if [[ ${STATUSCODE} -ne 200 ]] && [[ ${STATUSCODE} -ne 302 ]]; then exit 1; fi
- id: download-package
name: Download wheel package
run: |
# check if release is now published and available
WHEEL=${{ needs.autorelease.outputs.wheel }}
VERSION=${{ needs.autorelease.outputs.version }}
echo "Downloading latest available Spark wheel package release ${WHEEL}."
wget $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${WHEEL} --no-check-certificate
- id: install-package
name: Install wheel package file
run: |
pip install ./${{ needs.autorelease.outputs.wheel }}
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

# autorelease:
# name: Release the package on github
# needs: [release_checks, tests, build]
# runs-on: ubuntu-latest
# timeout-minutes: 5
# strategy:
# fail-fast: true
# steps:
# - id: checkout
# name: Checkout repo
# uses: actions/checkout@v4
# with:
# ref: ${{ env.BRANCH }}
# fetch-depth: 0
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: distfiles
# path: dist/
# - id: artifact_names
# name: Compute artifact names outputs
# run: |
# _NAME=${{ needs.release_checks.outputs.package_name }}
# _VERSION=${{ needs.release_checks.outputs.package_version }}
# echo "wheel=${_NAME}-${_VERSION}-py3-none-any.whl" >> "$GITHUB_OUTPUT"
# echo "tarball=${_NAME}-${_VERSION}.tar.gz" >> "$GITHUB_OUTPUT"
# - name: Create Github Release
# uses: softprops/action-gh-release@v2
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# body_path: ".github/RELEASE-TEMPLATE.md"
# files: |
# dist/${{ steps.artifact_names.outputs.wheel }}
# dist/${{ steps.artifact_names.outputs.tarball }}
# outputs:
# version: ${{ needs.release_checks.outputs.package_version }}
# wheel: ${{ steps.artifact_names.outputs.wheel }}
# tarball: ${{ steps.artifact_names.outputs.tarball }}

# upload-pypi:
# name: Publish to PyPI
# needs: [release_checks, tests, build]
# runs-on: ubuntu-latest
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v4
# with:
# name: distfiles
# path: dist/
# - name: Publish to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# permissions:
# id-token: write # Needed for trusted publishing (https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)

# test:
# name: Test Release
# runs-on: ubuntu-latest
# timeout-minutes: 5
# env:
# DOWNLOADS_PATH: "/releases/download"
# needs: [autorelease]
# steps:
# - id: check-tar-gz
# name: Check tar.gz package
# run: |
# # check if release is now published and available
# TARBALL=${{ needs.autorelease.outputs.tarball }}
# VERSION=${{ needs.autorelease.outputs.version }}
# echo "Checking latest available Spark package release: ${TARBALL}"
# STATUSCODE=$(curl --silent --head $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${TARBALL} | head -n 1 | cut -d' ' -f2)
# if [[ ${STATUSCODE} -ne 200 ]] && [[ ${STATUSCODE} -ne 302 ]]; then exit 1; fi
# - id: download-package
# name: Download wheel package
# run: |
# # check if release is now published and available
# WHEEL=${{ needs.autorelease.outputs.wheel }}
# VERSION=${{ needs.autorelease.outputs.version }}
# echo "Downloading latest available Spark wheel package release ${WHEEL}."
# wget $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/${{ env.DOWNLOADS_PATH }}/v${VERSION}/${WHEEL} --no-check-certificate
# - id: install-package
# name: Install wheel package file
# run: |
# pip install ./${{ needs.autorelease.outputs.wheel }}

0 comments on commit a352fd3

Please sign in to comment.