Skip to content

Merge pull request #294 from opensafely-core/dependabot/pip/virtualen… #113

Merge pull request #294 from opensafely-core/dependabot/pip/virtualen…

Merge pull request #294 from opensafely-core/dependabot/pip/virtualen… #113

name: Tag repo; build and publish assets
on:
push:
branches:
- main
permissions: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
tag-new-version:
name: Tag new version
permissions:
contents: write
# This if condition acts as a safeguard against confusing tagging behaviour,
# should the triggers for this workflow include pull requests in future.
# See https://github.com/mathieudutour/github-tag-action/issues/150 for why this if condition is prudent.
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.new_tag }}
version: ${{ steps.tag.outputs.new_version }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Bump version and push tag
id: tag
uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
release_branches: main
build-and-publish-package:
runs-on: ubuntu-latest
name: Build and publish PyPI package
permissions:
contents: write
needs: tag-new-version
if: needs.tag-new-version.outputs.tag
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Python 3.10
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.10"
- name: Install wheel package
run: |
pip install wheel
- name: Generate correct value for VERSION file
run: |
echo ${NEEDS_TAG_NEW_VERSION_OUTPUTS_TAG} > osgithub/VERSION
env:
NEEDS_TAG_NEW_VERSION_OUTPUTS_TAG: ${{ needs.tag-new-version.outputs.tag }}
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Publish package
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
if: needs.tag-new-version.outputs.tag
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
# As well as uploading to PyPI it's useful to publish them as Github
# Release Assets for use in contexts where we have access to Github but not
# to PyPI
- name: Create release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.tag-new-version.outputs.tag }}
run: |
gh release create "$TAG" dist/*.whl dist/*.tar.gz --title "$TAG" --notes "" --verify-tag