Skip to content

Release version 2025.01.8 #317

Release version 2025.01.8

Release version 2025.01.8 #317

Workflow file for this run

name: Release to PyPI
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: 'write'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v4
with:
python-version: 3.11.5
- name: Install dependencies with Yarn
run: yarn install --frozen-lockfile --production=false
- name: build the javascript bundle
run: |
yarn build
# Force Git to track the build file temporarily
git add -f src/genstudio/js/widget_build.js
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Install deps
run: poetry install --without dev
- name: Set version components
id: versions
run: |
# Check if current commit has a tag
HAS_TAG=$(git tag --points-at HEAD)
# If we're on main and there's a tag, skip the build
if [[ "${{ github.ref }}" == "refs/heads/main" && -n "$HAS_TAG" ]]; then
echo "CONTINUE=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "CONTINUE=true" >> $GITHUB_OUTPUT
# Handle different version scenarios
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# Dev version for main pushes without tag
BASE_VERSION=$(poetry version -s)
DEV_VERSION=$(date +'%Y%m%d%H%M')
PYTHON_VERSION="${BASE_VERSION}.dev${DEV_VERSION}"
NPM_VERSION="${BASE_VERSION}-dev.${DEV_VERSION}"
poetry version ${PYTHON_VERSION}
elif [[ "${{ github.ref }}" =~ ^refs/tags/v.*\.alpha ]]; then
# Alpha release from tag
PYTHON_VERSION=${GITHUB_REF#refs/tags/v}
NPM_VERSION=${PYTHON_VERSION/alpha/-alpha.}
else
# Regular release from tag
PYTHON_VERSION=$(poetry version -s)
NPM_VERSION=$PYTHON_VERSION
fi
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_OUTPUT
echo "NPM_VERSION=${NPM_VERSION}" >> $GITHUB_OUTPUT
- name: Update version query params in widget.py
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
run: |
VERSION=${{ steps.versions.outputs.PYTHON_VERSION }}
python scripts/update_asset_versions.py $VERSION
- name: Update widget URL and build Python package
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
run: |
NPM_BASE="https://cdn.jsdelivr.net/npm/@probcomp/genstudio@${{ steps.versions.outputs.NPM_VERSION }}/dist"
JSDELIVR_JS_URL="${NPM_BASE}/widget_build.js"
JSDELIVR_CSS_URL="${NPM_BASE}/widget.css"
# Update both URLs in the source
sed -i "s|CDN_SCRIPT_URL = None|CDN_SCRIPT_URL = \"${JSDELIVR_JS_URL}\"|" src/genstudio/util.py
sed -i "s|CDN_CSS_URL = None|CDN_CSS_URL = \"${JSDELIVR_CSS_URL}\"|" src/genstudio/util.py
poetry build
git checkout src/genstudio/util.py
- name: Deploy to PyPI
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
run: |
echo "=== Checking build artifacts ==="
ls -la dist/
echo "=== Publishing to PyPI ==="
poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
poetry publish
- name: Setup Node.js for npm publishing
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
run: |
npm version ${{ steps.versions.outputs.NPM_VERSION }} --no-git-tag-version
# Copy both files to npm dist directory
mkdir -p dist
cp src/genstudio/js/widget_build.js dist/
cp src/genstudio/widget.css dist/
echo "Publishing npm package version ${{ steps.versions.outputs.NPM_VERSION }}"
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Parse latest changelog entry
if: ${{ fromJSON(steps.versions.outputs.CONTINUE) }}
id: changelog
run: |
# Extract everything from start until the second occurrence of a line starting with ###
awk '/^###/{count++; if(count==2){exit} if(count==1){p=1}} p{print}' CHANGELOG.md > release_notes.md
- name: Create GitHub Release
if: ${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '.alpha') && fromJSON(steps.versions.outputs.CONTINUE) }}
uses: ncipollo/release-action@v1
with:
bodyFile: release_notes.md
artifacts: "dist/*"