-
Notifications
You must be signed in to change notification settings - Fork 1
ci: build dist on merge to main, publish to dedicated dist branch
#66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| name: Publish dist branch | ||
|
|
||
| # Builds the CSS bundles after every merge to main and force-pushes the | ||
| # resulting dist/ tree to a dedicated `dist` branch. The `dist` branch is | ||
| # orphan (no shared history with main) and contains only the generated | ||
| # bundles at its root, so consumers can reference them via: | ||
| # | ||
| # https://cdn.jsdelivr.net/gh/codeslash-dev/SLASHED@dist/slashed.essential.min.css | ||
| # | ||
| # Source files (core/, optional/, etc.) live only on main; built files live | ||
| # only on dist. This keeps main free of generated artifacts while still | ||
| # giving the CDN something to serve. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
|
|
||
| # If several merges land in quick succession, cancel any in-flight publish | ||
| # and rerun against the newest commit only. Prevents racing force-pushes. | ||
| concurrency: | ||
| group: publish-dist | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| publish-dist: | ||
| name: Build and force-push dist branch | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout main | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Don't write GITHUB_TOKEN into .git/config; the build steps | ||
| # (npm install, npm run build) shouldn't have implicit push | ||
| # credentials. We re-authenticate explicitly at push time below. | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build dist bundles | ||
| run: npm run build | ||
|
|
||
| - name: Stage dist for orphan branch | ||
| run: | | ||
| set -euo pipefail | ||
| mkdir -p /tmp/sf-dist | ||
| cp -R dist/. /tmp/sf-dist/ | ||
| # Stamp file so consumers can verify exactly which source commit | ||
| # produced this dist tree. | ||
| { | ||
| echo "source-commit: ${GITHUB_SHA}" | ||
| echo "source-ref: ${GITHUB_REF}" | ||
| echo "built-at: $(date -u +%Y-%m-%dT%H:%M:%SZ)" | ||
| echo "built-by: .github/workflows/publish-dist.yml" | ||
| } > /tmp/sf-dist/SOURCE.txt | ||
|
|
||
| - name: Force-push dist branch | ||
| env: | ||
| # Scoped to this step only β checkout was started with | ||
| # persist-credentials: false, so GITHUB_TOKEN never landed in | ||
| # .git/config and never leaked into the build/install steps. | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GIT_AUTHOR_NAME: github-actions[bot] | ||
| GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | ||
| GIT_COMMITTER_NAME: github-actions[bot] | ||
| GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | ||
| run: | | ||
| set -euo pipefail | ||
| git checkout --orphan dist | ||
| # The orphan checkout still stages main's tree; remove it all so | ||
| # only built artifacts end up on the dist branch. | ||
| git rm -rf . > /dev/null | ||
| shopt -s dotglob | ||
| cp -R /tmp/sf-dist/. . | ||
| git add -A | ||
| git commit -m "build: dist for ${GITHUB_SHA}" | ||
| git push --force \ | ||
| "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \ | ||
| dist | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Script executed:
Repository: codeslash-dev/SLASHED
Length of output: 173
π Script executed:
Repository: codeslash-dev/SLASHED
Length of output: 3307
Pin GitHub Actions to immutable SHAs.
.github/workflows/publish-dist.ymluses mutable tags:uses: actions/checkout@v4(line 34)uses: actions/setup-node@v4(line 39)Suggested fix
π§° Tools
πͺ zizmor (1.25.2)
[error] 34-34: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
π€ Prompt for AI Agents