Skip to content

Commit

Permalink
Automate release process (#50)
Browse files Browse the repository at this point in the history
* Update yaml file

* Use OIDC as a trusted publisher to publish on PyPI
  • Loading branch information
michaelshin authored Apr 27, 2023
1 parent bc39585 commit 3366147
Showing 1 changed file with 34 additions and 84 deletions.
118 changes: 34 additions & 84 deletions .github/workflows/build-and-publish-new-version.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
name: Build and publish a new version

on:
pull_request_target:
types:
- closed
branches:
- main
workflow_dispatch:
branches: main
inputs:
tag:
description: 'Release Tag. This is in the form x.y.z'
required: true

jobs:
build:
if: (startsWith(github.head_ref, 'release-') && github.event.pull_request.merged == true)
name: Build DeepView.Profile
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -27,17 +26,23 @@ jobs:
with:
virtualenvs-in-project: true

- name: Build Python package
- name: Create release branch
run: |
git branch release/${{ github.event.inputs.tag }}
- name: Update version number
run: |
poetry version ${{ github.event.inputs.tag }}
- name: Build Python artifacts
run: |
NEXT_CLI_VERSION=$(poetry version --short)
echo "NEXT_CLI_VERSION=$NEXT_CLI_VERSION" >> $GITHUB_ENV
poetry build
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.NEXT_CLI_VERSION }}
path: dist/*${{ env.NEXT_CLI_VERSION }}*
name: ${{ github.event.inputs.tag }}
path: dist/*${{ github.event.inputs.tag }}*

publish-release:
name: Publish Release
Expand All @@ -50,81 +55,46 @@ jobs:
with:
fetch-depth: 0

- 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: Fetch current version
run: |
echo "NEXT_CLI_VERSION=$(poetry version --short)" >> $GITHUB_ENV
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.NEXT_CLI_VERSION }}
name: ${{ github.event.inputs.tag }}
path: dist

- name: Publish a release
run: |
NEXT_CLI_VERSION=${{ env.NEXT_CLI_VERSION }}
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 "*$NEXT_CLI_VERSION*" -type f | paste -s -d ' ' - )
VERSION_TAG="v$NEXT_CLI_VERSION"
gh auth login --with-token <<< "${{ secrets.GH_TOKEN }}"
gh release create "$VERSION_TAG" \
--title "$VERSION_TAG" \
--notes "$RELEASE_NOTES" \
--target "$GITHUB_SHA" \
$RELEASE_ARTIFACTS
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: publish-release
runs-on: ubuntu-latest
environment: Test
concurrency: Test
permissions:
id-token: write

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: Fetch current version
run: |
echo "NEXT_CLI_VERSION=$(poetry version --short)" >> $GITHUB_ENV
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.NEXT_CLI_VERSION }}
name: ${{ github.event.inputs.tag }}
path: dist

- name: Display structure of downloaded files
run: ls -Ral
working-directory: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/

publish-to-pypi:
Expand All @@ -133,38 +103,18 @@ jobs:
runs-on: ubuntu-latest
environment: Production
concurrency: Production
permissions:
id-token: write

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: Fetch current version
run: |
echo "NEXT_CLI_VERSION=$(poetry version --short)" >> $GITHUB_ENV

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: ${{ env.NEXT_CLI_VERSION }}
name: ${{ github.event.inputs.tag }}
path: dist

- name: Display structure of downloaded files
run: ls -Ral
working-directory: dist

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
repository_url: https://upload.pypi.org/legacy/

0 comments on commit 3366147

Please sign in to comment.