Skip to content

Merge pull request #14 from webflow/sphere-updates #14

Merge pull request #14 from webflow/sphere-updates

Merge pull request #14 from webflow/sphere-updates #14

Workflow file for this run

name: Release
on:
push:
branches:
- main
jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 10.20.0
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
run: pnpm build
- name: Stage dist folder (if changed)
id: stage_dist
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add packages/scripts/dist/
if git diff --staged --quiet; then
echo "No changes to dist folder"
echo "has_dist_changes=false" >> $GITHUB_OUTPUT
else
echo "Dist folder has changes"
echo "has_dist_changes=true" >> $GITHUB_OUTPUT
fi
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
# Don't publish to npm - we only use GitHub releases
# Using a no-op command since package is marked private
publish: echo "Package is private, skipping npm publish"
version: pnpm changeset version
commit: 'chore: version packages'
title: 'chore: version packages'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create PR for dist changes (if no changesets PR was created)
if: steps.stage_dist.outputs.has_dist_changes == 'true' && steps.changesets.outputs.pullRequestNumber == ''
run: |
# Re-stage dist changes (in case changesets action reset staging)
git add packages/scripts/dist/
if ! git diff --staged --quiet; then
echo "Creating PR for dist changes"
BRANCH_NAME="chore/build-scripts-$(date +%s)"
git checkout -b "$BRANCH_NAME"
git commit -m "chore: build scripts package"
git push origin "$BRANCH_NAME"
gh pr create \
--title "chore: build scripts package" \
--body "Automated build of scripts package dist folder." \
--base main \
--head "$BRANCH_NAME"
else
echo "Dist changes were already committed"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check if version was updated
id: check_version
run: |
# Get current version from package.json
CURRENT_VERSION=$(grep -o '"version": "[^"]*"' packages/scripts/package.json | cut -d'"' -f4)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if there's already a tag for this version
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag v$CURRENT_VERSION already exists, skipping release"
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "New version detected: $CURRENT_VERSION"
echo "should_release=true" >> $GITHUB_OUTPUT
fi
- name: Get Scripts Package Version
if: steps.check_version.outputs.should_release == 'true'
id: version
run: |
VERSION="${{ steps.check_version.outputs.current_version }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
echo "Released version: $VERSION"
- name: Create Git Tag
if: steps.check_version.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.tag }}" -m "Release ${{ steps.version.outputs.tag }}"
git push origin "${{ steps.version.outputs.tag }}"
- name: Create GitHub Release for Scripts
if: steps.check_version.outputs.should_release == 'true'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.tag }}
name: Scripts Release ${{ steps.version.outputs.tag }}
body: |
Automated release of scripts package.
**Version:** ${{ steps.version.outputs.version }}
**jsdelivr URLs:**
- Latest from this version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js`
- Latest from major version: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.version }}.*/packages/scripts/dist/index.js`
- Specific commit: `https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ github.sha }}/packages/scripts/dist/index.js`
**Usage in HTML:**
```html
<script defer src="https://cdn.jsdelivr.net/gh/${{ github.repository }}@${{ steps.version.outputs.tag }}/packages/scripts/dist/index.js"></script>
```
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload Scripts Artifacts
if: steps.check_version.outputs.should_release == 'true'
uses: actions/upload-artifact@v4
with:
name: scripts-dist
path: packages/scripts/dist/**
retention-days: 90