Skip to content

Release version 2025.2.2 #344

Release version 2025.2.2

Release version 2025.2.2 #344

Workflow file for this run

name: Release to PyPI
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
jobs:
check:
runs-on: ubuntu-latest
outputs:
skip: ${{ steps.check.outputs.skip }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if build should be skipped
id: check
run: |
if [[ "${{ github.ref }}" == "refs/heads/main" ]] && [[ -n "$(git tag --points-at HEAD)" ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
build:
needs: check
if: needs.check.outputs.skip != 'true'
runs-on: ubuntu-latest
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: Set version components
id: versions
run: |
# 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=$(echo ${PYTHON_VERSION} | sed 's/\.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: Install deps
run: poetry install --without dev
- name: Update version query params in widget.py
run: |
VERSION=${{ steps.versions.outputs.PYTHON_VERSION }}
python scripts/update_asset_versions.py $VERSION
- name: Update widget URL and build Python package
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
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
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Publish to npm
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
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: github.ref_type == 'tag' && !contains(github.ref, '.alpha')
uses: ncipollo/release-action@v1
with:
bodyFile: release_notes.md
artifacts: "dist/*"