-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (117 loc) · 4.5 KB
/
release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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/*"