Skip to content

improved pipeline

improved pipeline #1

Workflow file for this run

name: Publish
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.13
- name: Install dependencies
uses: py-actions/py-dependency-install@v4
- name: Test with pytest and coverage
run: |
coverage run --source=snapshooter -m pytest
coverage xml
coverage html
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: jeromerg/snapshooter
publish:
name: Publish
runs-on: ubuntu-latest
# only run on push event (not on pull_request event)
if: github.event_name == 'push'
permissions:
id-token: write
contents: write
steps:
- name: Configure Git
run: |
git config --global user.name 'github-actions'
git config --global user.email 'github-actions@github.com'
- name: Checkout files
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.10.13
- name: Set Version
run: |
# read snapshooter/__init__.py
# ... and extract __version__ = '0.1.0'
VERSION=$(grep -oP '__version__ = "\K[^"]+' snapshooter/__init__.py)
# extract major, minor, build
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
BUILD=$(echo $VERSION | cut -d. -f3)
# replace build with github run number
VERSION=$MAJOR.$MINOR.$GITHUB_RUN_NUMBER
# path the version in __init__.py
sed -i "s/__version__ = .*/__version__ = '$VERSION'/" snapshooter/__init__.py
# export the version to subsequent steps
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Prepare distribution
run: |
python setup.py sdist bdist_wheel
- name: Publish Release to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create and Push Tag
run: |
TAG="v$VERSION"
git tag $TAG
git push origin $TAG
- name: Publish Release to GitHub
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
draft: false
prerelease: false