Skip to content

Create Release

Create Release #537

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
workflow_run:
workflows: [ "Vendor Update" ]
types:
- completed
#release:
# types: ['published']
name: Create Release
jobs:
unit-tests:
name: Unit Tests
if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }}
permissions:
contents: read
uses: ./.github/workflows/unit-tests.yml
version_check:
name: Check Version
runs-on: ubuntu-latest
needs: [ unit-tests ]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: '3.14'
- name: Install and Setup
run: |
python -m pip install -U pip setuptools wheel packaging
- name: Get Version
id: get_version
run: |
set -ex
python -m pip install -e .
echo "PCAPKIT_VERSION=$(python -c 'import pcapkit; print(pcapkit.__version__)')" >> $GITHUB_OUTPUT
echo "PCAPKIT_PRERELEASE=$(python -c 'from packaging.version import Version; import pcapkit; print(str(Version(pcapkit.__version__).is_prerelease).lower())')" >> $GITHUB_OUTPUT
echo "PCAPKIT_CONDA_LABEL=$(python -c 'from packaging.version import Version; import pcapkit; print("dev" if Version(pcapkit.__version__).is_prerelease else "main")')" >> $GITHUB_OUTPUT
- uses: mukunku/tag-exists-action@v1.7.0
id: check_tag
with:
tag: "v${{ steps.get_version.outputs.PCAPKIT_VERSION }}"
outputs:
PCAPKIT_VERSION: ${{ steps.get_version.outputs.PCAPKIT_VERSION }}
PCAPKIT_PRERELEASE: ${{ steps.get_version.outputs.PCAPKIT_PRERELEASE }}
PCAPKIT_TAG_EXISTS: ${{ steps.check_tag.outputs.exists }}
PCAPKIT_CONDA_LABEL: ${{ steps.get_version.outputs.PCAPKIT_CONDA_LABEL }}
github:
name: GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
needs: [ version_check ]
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
# ref: v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
fetch-depth: 0
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v3.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
# allowUpdates: true
# artifacts: |
# dist/*
generate_release_notes: true
# makeLatest: true
name: PyPCAPKit v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
prerelease: ${{ needs.version_check.outputs.PCAPKIT_PRERELEASE }}
tag_name: "v${{ needs.version_check.outputs.PCAPKIT_VERSION }}"
token: "${{ secrets.GITHUB_TOKEN }}"
tag:
name: Conda Tag
runs-on: ubuntu-latest
permissions:
contents: write
needs: [ version_check ]
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
token: ${{ secrets.PYPCAPKIT }}
# ref: v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
fetch-depth: 0
- name: Reset Build Number
run: |
set -x
printf 0 > conda/build
- name: Commit Changes
run: |
set -x
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add conda/build
git commit -m"Reset conda build number" || true
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PYPCAPKIT }}
- name: Create Tag
run: |
set -x
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git tag -d v${{ needs.version_check.outputs.PCAPKIT_VERSION }} || true
git tag "conda-${{ needs.version_check.outputs.PCAPKIT_VERSION }}+0" -m"Conda Build"
- name: Push Tag
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PYPCAPKIT }}
atomic: false
tags: true
pypi:
name: PyPI distribution for Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
## Specifying a GitHub environment is optional, but strongly encouraged
#environment: release
#permissions:
# # IMPORTANT: this permission is mandatory for trusted publishing
# id-token: write
permissions:
contents: write
id-token: write
needs: [ github, version_check ]
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
- "pypy3.10"
- "pypy3.11"
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
ref: v${{ needs.version_check.outputs.PCAPKIT_VERSION }}
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install and Setup
run: |
set -x
python -m pip install -U pip setuptools wheel
python -m pip install -U build
- name: Build Package
env:
PCAPKIT_VERSION: ${{ needs.version_check.outputs.PCAPKIT_VERSION }}
run: |
python -m build
# rename wheel's python tag
python util/wheel_rename.py dist/*.whl
- name: No Source Distribution for Python ${{ matrix.python-version }}
if: ${{ matrix.python-version != '3.14' }}
run: |
rm dist/*.tar.gz
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
attestations: false
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
skip-existing: true
attestations: false
- name: Upload package to GitHub Release
uses: softprops/action-gh-release@v3.0.2
with:
# allowUpdates: true
files: |
dist/*
tag_name: "v${{ needs.version_check.outputs.PCAPKIT_VERSION }}"
token: "${{ secrets.GITHUB_TOKEN }}"
conda:
name: Conda deployment of package for platform ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
needs: [ tag, github, version_check ]
if: ${{ startsWith(github.ref_name, 'v') || needs.version_check.outputs.PCAPKIT_TAG_EXISTS == 'false' }}
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
# - windows-latest # skip for now
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
- "3.14"
steps:
- uses: actions/checkout@v7
with:
ref: conda-${{ needs.version_check.outputs.PCAPKIT_VERSION }}+0
fetch-depth: 0
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
- name: Install and Setup
if: ${{ matrix.os != 'windows-latest' }}
run: |
set -x
python -m pip install -U pip setuptools wheel
python -m pip install -e .[all]
python -m pip install pathlib2 typing_extensions
- name: Install and Setup (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -e .[all]
python -m pip install pathlib2 typing_extensions
- name: Setup Conda Distribution
if: ${{ matrix.os != 'windows-latest' }}
run: |
set -x
mkdir -p conda/wheels
python -m pip download -r conda/requirements.txt -d conda/wheels
- name: Setup Conda Distribution (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
mkdir -p conda/wheels
python -m pip download -r conda/requirements.txt -d conda/wheels
- name: Conda environment creation and activation
uses: conda-incubator/setup-miniconda@v4.0.1
env:
PCAPKIT_VERSION: ${{ needs.version_check.outputs.PCAPKIT_VERSION }}
PCAPKIT_BUILD: "0"
with:
python-version: ${{ matrix.python-version }}
activate-environment: base
auto-update-conda: false
auto-activate: true
channels: conda-forge,defaults
conda-remove-defaults: false
show-channel-urls: true
- name: Install conda build tools
run: |
conda install -n base --override-channels -c conda-forge -y conda-build
conda build --version
- name: Build conda packages
id: conda_build
shell: bash -el {0}
env:
PCAPKIT_VERSION: ${{ needs.version_check.outputs.PCAPKIT_VERSION }}
PCAPKIT_BUILD: "0"
working-directory: conda/pypcapkit
run: |
set -euo pipefail
out_dir="$(mktemp -d -t compilation-XXXXXXXXXX)"
echo "out_dir=$out_dir" >> "$GITHUB_OUTPUT"
conda build . --package-format .tar.bz2 --no-anaconda-upload --output-folder "$out_dir" --python "${{ matrix.python-version }}"
host_package="$(find "$out_dir" -type f \( -name '*.tar.bz2' -o -name '*.conda' \) -print | sort | sed -n '1p')"
if [ -z "$host_package" ]; then
echo "::error::No conda package was built"
exit 1
fi
case "${{ matrix.os }}" in
macos-latest)
target_platform="osx-64"
;;
ubuntu-latest)
target_platform="linux-64"
;;
windows-latest)
target_platform="win-64"
;;
*)
target_platform=""
;;
esac
host_platform="$(basename "$(dirname "$host_package")")"
if [ -n "$target_platform" ] && [ "$target_platform" != "$host_platform" ]; then
conda convert "$host_package" -o "$out_dir" -p "$target_platform"
fi
package_paths="$(find "$out_dir" -type f \( -name '*.tar.bz2' -o -name '*.conda' \) -print | sort)"
if [ -z "$package_paths" ]; then
echo "::error::No conda packages were found"
exit 1
fi
printf '%s\n' "$package_paths"
package_paths_csv="$(printf '%s\n' "$package_paths" | paste -sd ',' -)"
echo "packages_csv=$package_paths_csv" >> "$GITHUB_OUTPUT"
{
echo 'packages<<EOF'
printf '%s\n' "$package_paths"
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Upload conda packages to Anaconda
uses: anaconda/actions/upload-package@v0.3.1
with:
token: ${{ secrets.ANACONDA_TOKEN }}
channel: jarryshaw
packages: ${{ steps.conda_build.outputs.packages }}
labels: ${{ needs.version_check.outputs.PCAPKIT_CONDA_LABEL }}
- name: Upload package to GitHub Release
if: ${{ matrix.os == 'ubuntu-latest' }}
uses: softprops/action-gh-release@v3.0.2
with:
# allowUpdates: true
files: ${{ steps.conda_build.outputs.packages }}
tag_name: "v${{ needs.version_check.outputs.PCAPKIT_VERSION }}"
token: "${{ secrets.GITHUB_TOKEN }}"