Skip to content

Update version

Update version #37

name: Update version
on:
workflow_dispatch:
inputs:
version:
description: 'Version number - M.N.P'
required: true
type: string
jobs:
update-version-number:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: peterjgrainger/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: 'new_version'
sha: '${{ github.event.pull_request.head.sha }}'
- uses: actions/checkout@v3
with:
ref: 'new_version'
- name: Change version in conf.py, pyproject.toml and __init__.py
run: |
awk -F= -F\" '$1=="version = "{$2=version}1' version=\"${NEW_VERSION}\" OFS="" pyproject.toml > tmp.toml
mv tmp.toml pyproject.toml
awk -F= -F\" '$1=="__version__="{$2=version}1' version=\"${NEW_VERSION}\" OFS="" src/ncas_amof_netcdf_template/__init__.py > tmp.py
mv tmp.py src/ncas_amof_netcdf_template/__init__.py
awk -F= -F\' '$1=="release = "{$2=version}1' version=\'${NEW_VERSION}\' OFS="" docs/source/conf.py > tmp.py
mv tmp.py docs/source/conf.py
env:
NEW_VERSION: ${{ inputs.version }}
- name: Change production status in pyproject.toml
run: |
if [[ "${new_version}" == *"a"* ]]
then
if $(grep -Fq "Development Status :: 3 - Alpha" pyproject.toml)
then
echo "Already correct dev status"
elif $(grep -Fq "Development Status :: 4 - Beta" pyproject.toml)
then
sed -i 's/4 - Beta/3 - Alpha/' pyproject.toml
elif $(grep -Fq "Development Status :: 5 - Production/Stable" pyproject.toml)
then
sed -i 's|5 - Production/Stable|3 - Alpha|' pyproject.toml
else
echo "Currently in unknown dev status, failing..."
exit 1
fi
elif [[ "${new_version}" == *"b"* || "${new_version}" == *"rc"* ]]
then
if $(grep -Fq "Development Status :: 4 - Beta" pyproject.toml)
then
echo "Already correct dev status"
elif $(grep -Fq "Development Status :: 3 - Alpha" pyproject.toml)
then
sed -i 's/3 - Alpha/4 - Beta/' pyproject.toml
elif $(grep -Fq "Development Status :: 5 - Production/Stable" pyproject.toml)
then
sed -i 's|5 - Production/Stable|4 - Beta|' pyproject.toml
else
echo "Currently in unknown dev status, failing..."
exit 1
fi
else
if $(grep -Fq "Development Status :: 5 - Production/Stable" pyproject.toml)
then
echo "Already correct dev status"
elif $(grep -Fq "Development Status :: 3 - Alpha" pyproject.toml)
then
sed -i 's|3 - Alpha|5 - Production/Stable|' pyproject.toml
elif $(grep -Fq "Development Status :: 4 - Beta" pyproject.toml)
then
sed -i 's|4 - Beta|5 - Production/Stable|' pyproject.toml
else
echo "Currently in unknown dev status, failing..."
exit 1
fi
fi
env:
new_version: ${{ inputs.version }}
- name: Push changes
run: |
git config --global user.email "[email protected]"
git config --global user.name "Joshua Hampton"
git add .
git commit -m "Auto update version"
git push origin new_version
- name: Create PR
uses: devops-infra/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: new_version
target_branch: main
title: Version Update PR
body: "Automated pull request with updated version"