Build dist branch #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build dist branch | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| source_ref: | |
| description: 'Source ref to build from (commit SHA, branch, or tag)' | |
| required: false | |
| default: 'main' | |
| jobs: | |
| build-dist: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.source_ref }} | |
| fetch-depth: 0 | |
| - name: Get source commit SHA | |
| id: source | |
| run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| run: pnpm run build | |
| - name: Checkout dist branch | |
| run: | | |
| git fetch origin dist:dist || git checkout --orphan dist | |
| git checkout dist | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Commit built files | |
| run: | | |
| # Remove everything except dist/ | |
| git rm -rf . 2>/dev/null || true | |
| git clean -fdx -e dist -e node_modules | |
| # Move dist contents to root | |
| mv dist/* . 2>/dev/null || true | |
| rmdir dist 2>/dev/null || true | |
| # Add package.json and other metadata | |
| git checkout ${{ steps.source.outputs.sha }} -- package.json README.md LICENSE 2>/dev/null || true | |
| # Stage all changes | |
| git add -A | |
| # Create merge commit with two parents: | |
| # 1. Previous dist commit (if exists) | |
| # 2. Source commit from main | |
| if git rev-parse --verify HEAD >/dev/null 2>&1; then | |
| # dist branch exists, create merge commit | |
| git commit -m "Build dist from ${{ steps.source.outputs.sha }}" || true | |
| git merge --no-ff -m "Merge built dist from main@${{ steps.source.outputs.sha }}" ${{ steps.source.outputs.sha }} -s ours || true | |
| else | |
| # First dist commit | |
| git commit -m "Initial dist build from ${{ steps.source.outputs.sha }}" | |
| # Can't create merge commit for first commit | |
| fi | |
| - name: Push dist branch | |
| run: git push origin dist --force-with-lease |