Merge pull request #139 from opensafely-core/dependabot/pip/ruff-0.2.2 #49
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: | |
# 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@v4 | |
with: | |
fetch-depth: 0 | |
- name: Bump version and push tag | |
id: tag | |
uses: mathieudutour/github-tag-action@fcfbdceb3093f6d85a3b194740f8c6cec632f4e2 | |
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.9 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9 | |
- 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 | |
- 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 |