rewrite(build.yaml): rewrite the build script for forgejo actions

This commit is contained in:
cocobo1 2025-09-14 11:01:33 +03:00
parent 6fb3eabf62
commit 788d0c12a8

View file

@ -1,4 +1,4 @@
name: Node.js CI / CD
name: Node.js CI / CD (Bun + Forgejo)
on:
push:
@ -6,82 +6,56 @@ on:
jobs:
buildAndRelease:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: latest
run_install: false
- name: Get pnpm store directory
id: pnpm-cache
shell: bash
- name: Install Bun
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- name: Setup pnpm cache
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
curl -fsSL https://bun.sh/install | bash
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
echo "$BUN_INSTALL/bin" >> $GITHUB_PATH
- name: Install dependencies
run: pnpm install
- run: |
pnpm build --release-branch=${{ github.ref_name }} --build-minify
# - name: Create Release
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: v${{ github.run_number }}
# release_name: Release v${{ github.run_number }}
# draft: false
# prerelease: false
run: |
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
bun install
- name: Build project
run: |
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
bun run build --release-branch=${GITHUB_REF_NAME:-${CI_COMMIT_REF_NAME}} --build-minify
- name: Push JS files to dist branch
run: |
# Configure git
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
# Create a temporary directory for the dist branch
mkdir -p temp_dist
# Copy only JS files from dist/ to temp directory
find dist -name "*.js" -exec cp {} temp_dist/ \;
# Create and checkout dist branch
git checkout --orphan dist-temp
git rm -rf --cached .
# Move the JS files to the root
cp -r temp_dist/* .
rm -rf temp_dist
# Add, commit and push to dist branch
git add *.js
git commit -m "Update build $GITHUB_SHA" || exit 0
git push -f origin HEAD:dist
# Return to the original branch
git checkout -f ${GITHUB_REF#refs/heads/}
git config --local user.email "actions@forgejo.local"
git config --local user.name "Forgejo Actions"
mkdir -p temp_dist
find dist -name "*.js" -exec cp {} temp_dist/ \;
git checkout --orphan dist-temp
git rm -rf --cached .
cp -r temp_dist/* .
rm -rf temp_dist
git add *.js
git commit -m "Update build $GITHUB_SHA" || exit 0
git push -f origin HEAD:dist
git checkout -f ${GITHUB_REF_NAME:-${CI_COMMIT_REF_NAME}}
- name: Merge main into github
if: github.ref == 'refs/heads/main'
run: |
git config --local user.email "actions@forgejo.local"
git config --local user.name "Forgejo Actions"
git fetch origin
git checkout github || git checkout -b github
git merge origin/main --no-edit
git push origin github