🗑️ change runners to new standard (#40) #31
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
# Many thanks to | |
# https://www.meziantou.net/executing-github-actions-jobs-or-steps-only-when-specific-files-change.htm | |
# for providing the base that this uses | |
name: Release to PyPI | |
on: | |
push: | |
branches: | |
- 'main' | |
jobs: | |
conditional_job_check_files: | |
runs-on: 'ubuntu-latest' | |
# Declare outputs for next jobs | |
outputs: | |
version_changed: ${{ steps.check_file_changed.outputs.version_changed }} | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
# Checkout as many commits as needed for the diff | |
fetch-depth: 2 | |
- id: check_file_changed | |
run: | | |
# Diff HEAD with the previous commit | |
if git diff HEAD^ HEAD pyproject.toml | grep -q "+version ="; | |
then | |
GOTIME="True" | |
else | |
GOTIME="False" | |
fi | |
echo "::notice title=GOTIME::$GOTIME" | |
# Set the output named "version_changed" | |
echo "version_changed=$GOTIME" >> $GITHUB_OUTPUT | |
# Run the job only with "version_changed" equals "True" | |
conditional_job: | |
runs-on: 'ubuntu-latest' | |
needs: [ conditional_job_check_files ] | |
if: needs.conditional_job_check_files.outputs.version_changed == 'True' | |
steps: | |
- name: Checkout current branch | |
uses: actions/checkout@v3 | |
with: | |
ref: "main" | |
- uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
- name: Build dist | |
run: poetry build | |
- name: Get current version number | |
run: | | |
poetry_response=$(poetry version) | |
sliced_version=$(python -c "print('$poetry_response'.split()[1])") | |
echo "version_number=$sliced_version" >> $GITHUB_ENV | |
- name: Publish to GitHub | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "dist/*" | |
generateReleaseNotes: true | |
tag: ${{ env.version_number }} | |
commit: main | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to PyPI | |
run: poetry publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_TOKEN }} |