Skip to content

Commit eefb961

Browse files
committed
ci: add build-dist workflow with version suffix
1 parent 3fbf3d9 commit eefb961

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

.github/workflows/build-dist.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build dist branch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
source_ref:
7+
description: 'Source branch to build from'
8+
required: false
9+
default: ''
10+
11+
jobs:
12+
build-dist:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
ref: ${{ inputs.source_ref || github.ref_name }}
18+
fetch-depth: 0
19+
20+
- name: Get source info
21+
id: info
22+
run: |
23+
echo "source_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
24+
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
25+
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
26+
27+
- uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
cache: 'npm'
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Build bundle
36+
run: npm run bundle
37+
38+
- name: Create dist branch
39+
env:
40+
SOURCE_REF: ${{ inputs.source_ref || github.ref_name }}
41+
SOURCE_SHA: ${{ steps.info.outputs.source_sha }}
42+
SHORT_SHA: ${{ steps.info.outputs.short_sha }}
43+
SOURCE_VERSION: ${{ steps.info.outputs.version }}
44+
run: |
45+
DIST_BRANCH="${SOURCE_REF}-dist"
46+
DIST_VERSION="${SOURCE_VERSION}-dist.${SHORT_SHA}"
47+
48+
# Configure git
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
# Save files we need before switching branches
53+
mkdir -p /tmp/dist-build
54+
cp -r dist/ /tmp/dist-build/
55+
cp package.json /tmp/dist-build/
56+
cp package-lock.json /tmp/dist-build/
57+
58+
# Fetch and checkout dist branch (or create orphan)
59+
if git fetch origin "$DIST_BRANCH" 2>/dev/null; then
60+
git checkout "$DIST_BRANCH"
61+
else
62+
git checkout --orphan "$DIST_BRANCH"
63+
git rm -rf .
64+
fi
65+
66+
# Clean and restore dist files
67+
rm -rf dist/
68+
cp -r /tmp/dist-build/dist/ ./
69+
cp /tmp/dist-build/package.json ./
70+
cp /tmp/dist-build/package-lock.json ./
71+
72+
# Update version in package.json
73+
jq --arg v "$DIST_VERSION" '.version = $v' package.json > package.json.tmp
74+
mv package.json.tmp package.json
75+
76+
# Commit
77+
git add -A
78+
git commit -m "plotly.js@${DIST_VERSION}
79+
80+
Built from ${SOURCE_SHA}"
81+
82+
# Push
83+
git push origin "$DIST_BRANCH" --force
84+
85+
echo "✅ Pushed $DIST_BRANCH with version $DIST_VERSION"
86+
echo ""
87+
echo "Install with:"
88+
echo " pnpm add github:${{ github.repository }}#$DIST_BRANCH"

0 commit comments

Comments
 (0)