Skip to content

Deploy Dev Release Artifacts #54

Deploy Dev Release Artifacts

Deploy Dev Release Artifacts #54

########################################################################################################
# Deploys a develop release and commits pyproject.toml files with new versions.
#
# When will it run:
# This workflow will only run on push to develop when there is a python file change.
#
# How will it update:
# The script should update based upon the current version in the pyproject.toml file. The workflow
# should run poetry version prerelease to create a new version file. Since this
# repository houses multiple wheels we will be using the ./scripts/runoneach.sh to run this command.
########################################################################################################
name: Deploy Dev Release Artifacts
on:
push:
branches:
- develop
workflow_dispatch:
inputs:
upgrade-version:
description: "Upgrade version number regardless of whether a py file is altered."
required: false
default: false
type: boolean
defaults:
run:
shell: bash
env:
LANG: en_US.utf-8
LC_ALL: en_US.utf-8
PYTHON_VERSION: "3.10"
jobs:
deploy-dev-release:
runs-on: ubuntu-22.04
permissions:
contents: write # To push a branch
pull-requests: write # To create a PR from that branch
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- run: echo "The specified version is ${{ inputs.release-version }}."
- run: |
set -x
set -u
set -e
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# ref: develop
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
# To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g
# with:
# since_last_remote_commit: true
with:
files: |
**.py
- name: Should change version
id: should_update_version
env:
PYTHON_FILES_CHANGED: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
should_update=false
for file in ${PYTHON_FILES_CHANGED}; do
should_update=true
break
done
# handle input required update.
if ${{ inputs.upgrade-version }} ; then
should_update=true
fi
echo "Should update == ${should_update}"
echo "value=${should_update}" >> "$GITHUB_OUTPUT"
- name: Set up Python ${{ env.PYTHON_VERSION }}
if: ${{ steps.should_update_version.outputs.value == 'true' }}
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
if: ${{ steps.should_update_version.outputs.value == 'true' }}
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Update version and commit pyproject.toml file
if: ${{ steps.should_update_version.outputs.value == 'true' }}
run: |
./scripts/run_on_each.sh poetry version prerelease
git config --global user.name 'Commit Bot'
git config --global user.email '[email protected]'
git add **/pyproject.toml
git commit -m "Auto Update Version Number"
git push
- name: Install library
if: ${{ steps.should_update_version.outputs.value == 'true' }}
run: |
./scripts/poetry_install.sh
- name: Create build artifacts
id: version
if: ${{ steps.should_update_version.outputs.value == 'true' }}
run: |
# set the right version in pyproject.toml before build and publish
./scripts/poetry_build.sh
echo "value=v$(poetry version --short)" >> "$GITHUB_OUTPUT"
# TODO: Check for pipy token and only release to github if we have it.
- name: Push artifacts to github
env:
TAG: ${{ steps.version.outputs.value }}
if: ${{ steps.should_update_version.outputs.value == 'true' }}
uses: ncipollo/release-action@v1
with:
artifacts: "dist/*.gz,dist/*.whl"
artifactErrorsFailBuild: true
generateReleaseNotes: true
commit: ${{ github.ref }}
# check bump-rule and set accordingly
prerelease: true
tag: ${{ env.TAG }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to pypi
id: publish-to-pypi
if: ${{ steps.should_update_version.outputs.value == 'true' }}
run: |
# This is needed, because the poetry publish will fail at the top level of the project
# so ./scripts/run_on_each.sh fails for that.
echo "POETRY_PUBLISH_OPTIONS=''" >> $GITHUB_ENV
cd gridappsd-python-lib
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
cd ../gridappsd-field-bus-lib
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish