Skip to content

Release/0.23.0

Release/0.23.0 #15

Workflow file for this run

# `release` workflow configuration
#
# This workflow is triggered when a release branch is merged into the main
# branch. It automates the process of creating a package and releasing it to
# GitHub and PyPI.
#
# Workflow steps:
# 0. A release branch named release/[TAG] is merged into main via a pull
# request.
# 1. `tagging` job runs:
# - A branch named [TAG] is created
# 2. `release` job runs:
# - Create a PyPI package
# - Create a release on GitHub
# - Release the package on PyPI
# 3. `delete-branch` job runs:
# - Delete the release branch
name: Release
on:
pull_request:
branches:
- main
types:
- closed
jobs:
tagging:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.head.ref, 'release/')
steps:
- name: Determine the tag name based on the branch name
id: get_version
run: |
echo "TAG=$(echo $BRANCH | cut -d / -f 2)" >> $GITHUB_OUTPUT
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
- name: Print the tag name for debugging
run: echo "${{ steps.get_version.outputs.TAG }}"
- uses: actions/checkout@v2
- name: Create a corresponding tag branch
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout main
git tag -a `echo '${{ github.event.pull_request.head.ref }}' | sed 's/release\///'` -m " "
git push origin `echo '${{ github.event.pull_request.head.ref }}' | sed 's/release\///'`
release:
name: release
runs-on: ubuntu-latest
needs: [tagging]
strategy:
# NOTE: Only one version should be set (It is aimed to reduce the cost to change versions)
matrix:
python-version: ['3.9']
steps:
- name: Determine the tag name based on the branch name
id: get_version
run: |
echo "TAG=$(echo $BRANCH | cut -d / -f 2)" >> $GITHUB_OUTPUT
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install poetry
poetry install
- name: Build the package
run: |
poetry build
- name: Push a release to GitHub. At the beginning of release, the body of pull request is shown.
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.TAG }}
release_name: ${{ steps.get_version.outputs.TAG }}
draft: false
prerelease: false
body: |
${{ github.event.pull_request.body }}
This release is automatically generated.
Please see the pull request for more details.
[${{ github.event.pull_request.html_url }}](${{ github.event.pull_request.html_url }})
- name: Generate checksum for all elements in dist directory
run: |
cd dist; sha256sum * > checksums.txt; cd -
- name: Attach an archive of source files to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/pfhedge-${{ steps.get_version.outputs.TAG }}.tar.gz
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}.tar.gz
asset_content_type: application/gzip
- name: Attach a Python wheel to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/pfhedge-${{ steps.get_version.outputs.TAG }}-py3-none-any.whl
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}-py3-none-any.whl
asset_content_type: application/x-pywheel+zip
- name: Attach the checksum of the files to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/checksums.txt
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}-checksums.txt
asset_content_type: text/plain
- name: Release the version to PyPI
run: |
poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}
delete-branch:
runs-on: ubuntu-latest
needs: [tagging, release]
steps:
- uses: actions/checkout@v2
- name: Delete the release branch
run: |
git push --delete origin ${{ github.event.pull_request.head.ref }}