Skip to content

Build and publish a new version #66

Build and publish a new version

Build and publish a new version #66

name: Build and publish a new version
on:
workflow_dispatch:
inputs:
tag:
description: 'Release Tag. This is in the form x.y.z'
required: true
jobs:
build-and-publish:
name: Build DeepView.Profile
runs-on: ubuntu-latest
env:
CI_COMMIT_AUTHOR: CentML
CI_COMMIT_EMAIL: centml-machine-user@users.noreply.github.com
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.8'
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-in-project: true
- name: Create release branch
run: |
git checkout -b release/${{ github.event.inputs.tag }}
git fetch
git branch --set-upstream-to=origin/main release/${{ github.event.inputs.tag }}
- name: Update version number
run: |
poetry version ${{ github.event.inputs.tag }}
- name: Commit updated version number and tag it
run: |
git config --global user.name "${{ env.CI_COMMIT_AUTHOR }}"
git config --global user.email "${{ env.CI_COMMIT_EMAIL }}"
git commit -am "Release version ${{ github.event.inputs.tag }}"
git push origin release/${{ github.event.inputs.tag }}
git tag ${{ github.event.inputs.tag }}
- name: Build Python artifacts
run: |
poetry build
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.inputs.tag }}
path: dist/*${{ github.event.inputs.tag }}*
- name: Publish a release
run: |
RELEASE_NOTES="$(git log $(git describe --abbrev=0 --tags).. --merges --pretty=format:"%s %b" | cut -f 4,7- -d ' ')"
echo "Autogenerated Release Notes:"
echo "$RELEASE_NOTES"
RELEASE_ARTIFACTS=$(find ./dist -name "*${{ github.event.inputs.tag }}*" -type f | paste -s -d ' ' - )
VERSION_TAG="v${{ github.event.inputs.tag }}"
gh auth login --with-token <<< "${{ secrets.GH_TOKEN }}"
gh release create "$VERSION_TAG" \
--title "$VERSION_TAG" \
--notes "$RELEASE_NOTES" \
--target "$GITHUB_SHA" \
$RELEASE_ARTIFACTS
gh pr create --title "Release $VERSION_TAG" --body "$RELEASE_NOTES"
publish-to-test-pypi:
name: Publish to Test PyPI
needs: build-and-publish
runs-on: ubuntu-latest
environment: Test
concurrency: Test
permissions:
id-token: write
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ github.event.inputs.tag }}
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository_url: https://test.pypi.org/legacy/
publish-to-pypi:
name: Publish to PyPI
needs: publish-to-test-pypi
runs-on: ubuntu-latest
environment: Production
concurrency: Production
permissions:
id-token: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ${{ github.event.inputs.tag }}
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository_url: https://upload.pypi.org/legacy/