get version #744
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: Main | |
on: | |
push: | |
branches: ["*"] # Run only when push to branches (not tags). | |
paths-ignore: | |
- "codeforlife/version.py" | |
- "**/*.md" | |
- ".vscode/**" | |
- ".*" | |
workflow_dispatch: | |
jobs: | |
# test: | |
# uses: ocadotechnology/codeforlife-workspace/.github/workflows/test-python-code.yaml@main | |
# secrets: inherit | |
# with: | |
# python-version: 3.12 | |
# TODO: https://python-semantic-release.readthedocs.io/en/latest/automatic-releases/github-actions.html#common-workflow-example | |
release: | |
concurrency: release | |
runs-on: ubuntu-latest | |
# needs: [test] | |
permissions: | |
id-token: write | |
# Release if: | |
# - the repo's owner is Ocado Tech. | |
# - a change is made to the default branch. | |
if: | | |
github.repository_owner_id == 2088731 && | |
github.ref_name == github.event.repository.default_branch | |
env: | |
PYTHON_SCRIPT: "from codeforlife.version import __version__; print(__version__)" | |
steps: | |
- name: 🛫 Checkout | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.CFL_BOT_GITHUB_TOKEN }} | |
fetch-depth: 0 | |
ref: ${{ github.sha }} | |
- name: 🛫 Checkout Branch on Workflow SHA | |
run: git checkout -B ${{ github.ref_name }} ${{ github.sha }} | |
- name: 🐍 Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.12 | |
- name: 🔍 Get Old Version | |
run: | | |
OLD_VERSION=$(python -c "$PYTHON_SCRIPT") | |
echo $OLD_VERSION | |
echo OLD_VERSION=$OLD_VERSION >> $GITHUB_ENV | |
- name: 🛠 Install Dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install python-semantic-release~=7.33 setuptools==75.1.0 | |
- name: 🤖 Set up cfl-bot as Git User | |
uses: ocadotechnology/codeforlife-workspace/.github/actions/git/setup-bot@main | |
- name: 🚀 Publish Semantic Release | |
env: | |
GH_TOKEN: ${{ secrets.CFL_BOT_GITHUB_TOKEN }} | |
run: semantic-release publish --verbosity=INFO | |
- name: 🔍 Get New Version | |
run: | | |
NEW_VERSION=$(python -c "$PYTHON_SCRIPT") | |
echo $NEW_VERSION | |
echo NEW_VERSION=$NEW_VERSION >> $GITHUB_ENV | |
- name: 🚀 Publish to PyPI | |
if: env.OLD_VERSION != env.NEW_VERSION | |
uses: pypa/gh-action-pypi-publish@release/v1 |