Skip to content

Ersilia Release

Ersilia Release #24

Workflow file for this run

# Single workflow to increment Ersilia version in pyproject.toml,
# tag and push the commit to the repository, release to GitHub, PyPI, and DockerHub
# This job updates _static_version.py, pyproject.toml, CITATION.cff, and codemeta.json
name: Ersilia Release
on:
workflow_dispatch: # run manually
schedule:
- cron: '0 3 1 * *' # run at 3:00 AM on the first day of the month
# This pipeline updates several version-related files: _static_version.py, pyproject.toml, CITATION.cff, and codemeta.json.
jobs:
version:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
steps:
- name: Checkout persist credentials
uses: actions/checkout@v4.2.2
with:
persist-credentials: false # ensures use of personal token instead of GITHUB_TOKEN
fetch-depth: 0 # fetches all history for tagging
- name: Increment package version
id: version
run: |
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/static_version_writer.py
echo "VERSION=$(python static_version_writer.py)" >> "$GITHUB_OUTPUT"
rm static_version_writer.py
- name: Create a release tag
id: tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "ersilia-bot@users.noreply.github.com"
git config --local user.name "ersilia-bot"
git tag -a "v${{ steps.version.outputs.VERSION }}" -m "v${{ steps.version.outputs.VERSION }}"
# Tagging happens implicitly; no need to push explicitly
- name: Update version and release date in CITATION.cff
id: update-citation
env:
VERSION: ${{ steps.version.outputs.VERSION }}
RELEASE_DATE: ${{ github.run_started_at }} # This captures the timestamp when the workflow run was triggered/started
run: |
pip install PyYAML
python -c "
import os
import yaml
release_date = os.environ['RELEASE_DATE'].split('T')[0]
with open('CITATION.cff', 'r') as file:
citation = yaml.safe_load(file)
citation['version'] = os.environ['VERSION']
citation['date-released'] = release_date
with open('CITATION.cff', 'w') as file:
yaml.dump(citation, file, default_flow_style=False, sort_keys=False)
"
- name: Update version in codemeta.json and URL
id: update-codemeta
env:
VERSION: ${{ steps.version.outputs.VERSION }}
run: |
# Ensure jq is installed
sudo apt-get install -y jq
# Update the version and URL in codemeta.json
jq --arg VERSION "$VERSION" --arg URL "https://github.com/ersilia-os/ersilia/v$VERSION" \
'.version = $VERSION | .codeRepository = $URL' codemeta.json > codemeta_tmp.json && mv codemeta_tmp.json codemeta.json
- name: Commit and push changes to CITATION.cff and codemeta.json
uses: actions-js/push@v1.5
with:
author_name: "ersilia-bot"
author_email: "ersilia-bot@users.noreply.github.com"
message: "update version and release date [skip ci]"
repository: "ersilia-os/${{ github.event.repository.name }}"
github_token: ${{ secrets.GITHUB_TOKEN }}
amend: true
force: true
branch: "master"
tags: true
gh-release:
runs-on: ubuntu-latest
needs: version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4.2.2
- name: Create GitHub release
id: gh_release
run: |
# Get the version file that we updated in the previous job
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/ersilia/_static_version.py
month=$(date +'%B')
year=$(date +'%Y')
title="$month $year"
# Extract the version using sed from _static_version.py
version=$(sed -n 's/.*version = "\([^"]*\)".*/\1/p' _static_version.py)
gh release create "v$version" --title "$title" --generate-notes
pypi-release:
runs-on: ubuntu-latest
needs: version
steps:
- uses: actions/checkout@v4.2.2
with:
ref: master
- name: Set up Python
uses: actions/setup-python@v5.2.0
with:
python-version: '3.8'
- name: Python Poetry Action
uses: abatilo/actions-poetry@v3.0.1
- name: Build and publish
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
git pull origin master
poetry config -- http-basic.pypi $PYPI_USERNAME $PYPI_PASSWORD
poetry --build publish