Build and publish #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and publish | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*.*.*' # Example: v1.2.3 | |
env: | |
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | |
PRE_RELEASE_VERSION: true | |
DRAFT_VERSION: true | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/fmdata | |
permissions: | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Sets env vars for main | |
if: ${{ env.BRANCH_NAME == 'main' }} | |
run: | | |
echo "PRE_RELEASE_VERSION=false" >> $GITHUB_ENV | |
echo "DRAFT_VERSION=false" >> $GITHUB_ENV | |
- name: Get next version | |
uses: reecetech/[email protected] | |
id: version | |
with: | |
scheme: semver | |
release_branch: main | |
- name: Set PACKAGE_VERSION Environment Variable | |
run: echo "PACKAGE_VERSION=${{ steps.version.outputs.version }}" >> $GITHUB_ENV | |
- name: Release version | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: ${{ env.DRAFT_VERSION }} | |
prerelease: ${{ env.PRE_RELEASE_VERSION }} | |
tag_name: "${{ steps.version.outputs.version }}" | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
# Cache pip dependencies for faster builds | |
- name: Cache pip | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
# (Optional) Run tests | |
# - name: Run tests | |
# run: | | |
# pytest | |
# Build the package | |
- name: Build package | |
run: | | |
python setup.py sdist bdist_wheel | |
- name: Publish package distributions to PyPI | |
if: ${{ env.PRE_RELEASE_VERSION == false }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |