Merge pull request #244 from opensafely-core/dependabot/pip/black-24.3.0 #175
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: Tag repo; build and publish assets | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
tag-new-version: | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.tag.outputs.new_tag }} | |
version: ${{ steps.tag.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Bump version and push tag | |
id: tag | |
uses: mathieudutour/[email protected] | |
# As this workflow is currently written, | |
# this is a redundant check: the workflow should only ever run on push to main. | |
# But it is an extra safeguard and reminder of the behaviour of github-tag-action. | |
# Pull requests can end up being tagged by github-tag-action, | |
# which is probably undesirable and very confusing to work out what's happening. | |
# See https://github.com/opensafely-core/ehrql/commit/3e55492e9c1b537fb5057f19f11f53a713fbae46 | |
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' | |
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 | |
needs: tag-new-version | |
if: needs.tag-new-version.outputs.tag | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.8 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.8 | |
- name: Install wheel package | |
run: | | |
pip install wheel | |
- name: Generate correct value for VERSION file | |
run: | | |
echo ${{ needs.tag-new-version.outputs.tag }} > opensafely/VERSION | |
- name: Build package | |
run: | | |
python setup.py sdist bdist_wheel | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@master | |
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 | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ needs.tag-new-version.outputs.tag }} | |
release_name: ${{ needs.tag-new-version.outputs.tag }} | |
draft: false | |
prerelease: false | |
- name: Get release filenames | |
id: get_release_filenames | |
run: | | |
cd dist | |
whl_filename=$(ls *.whl | head -n 1) | |
sdist_filename=$(ls *.tar.gz | head -n 1) | |
echo "::set-output name=whl_filename::$whl_filename" | |
echo "::set-output name=sdist_filename::$sdist_filename" | |
- name: "Upload release asset: wheel" | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: dist/${{ steps.get_release_filenames.outputs.whl_filename }} | |
asset_name: ${{ steps.get_release_filenames.outputs.whl_filename }} | |
asset_content_type: application/zip | |
- name: "Upload release asset: sdist" | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: dist/${{ steps.get_release_filenames.outputs.sdist_filename }} | |
asset_name: ${{ steps.get_release_filenames.outputs.sdist_filename }} | |
asset_content_type: application/gzip |