Skip to content

Commit

Permalink
chore(ci): tidy up frontend build shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Nov 23, 2024
1 parent ab2c2cf commit 0627e04
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/build-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,12 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Build UI
id: build_ui
run: |
make build-frontend
echo "ui_tarball=$(make -s pack-frontend)" >> $GITHUB_ENV
- name: Pack UI
id: pack
run: |
mkdir -p ./local/artalk_ui
cp -r ./public/dist ./public/sidebar ./local/artalk_ui
mkdir -p ./local/nightly_includes
tar -czf ./local/nightly_includes/artalk_ui_nightly.tar.gz -C ./local artalk_ui
- name: Upload UI
- name: Upload UI dist
uses: actions/upload-artifact@v4
with:
name: ui-src
Expand All @@ -100,11 +93,12 @@ jobs:
if-no-files-found: error
retention-days: 1

- name: Upload UI package
- name: Upload UI tarball (included in release)
uses: actions/upload-artifact@v4
with:
name: build-ui-pkg
path: local/nightly_includes/artalk_ui_nightly.tar.gz
name: build-ui-tarball
path: ${{ steps.build_ui.outputs.ui_tarball }}
if-no-files-found: error
retention-days: 1

#
Expand Down
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ before:
# install dependencies
- make install
- make build-frontend
- make pack-frontend

# build multi-platform
builds:
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ build:
$(PKG_NAME)

build-frontend:
./scripts/build-frontend.sh
@./scripts/build-frontend.sh

pack-frontend:
@./scripts/pack-frontend.sh

build-debug:
@echo "Building Artalk for debugging..."
Expand Down Expand Up @@ -73,7 +76,7 @@ docker-build:
docker-push:
./scripts/docker-build.sh --push

.PHONY: all install run build build-frontend build-debug dev \
.PHONY: all install run build build-frontend pack-frontend build-debug dev \
test test-coverage test-coverage-html test-frontend-e2e \
update-i18n update-conf update-conf-docs \
update-docs-features update-swagger \
Expand Down
38 changes: 14 additions & 24 deletions scripts/build-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

if ! command -v pnpm &> /dev/null
if ! command -v pnpm &>/dev/null && command -v apt-get &>/dev/null;
then
apt-get update && apt-get install --no-install-recommends -y -q curl ca-certificates

Expand All @@ -15,36 +15,26 @@ then
volta install [email protected]
fi

# build
pnpm install --frozen-lockfile
pnpm build:all
pnpm build:auth

## dist folders
DIST_DIR="./public/dist"
I18N_DIR="./public/dist/i18n"
SIDEBAR_DIR="./public/sidebar"
PLUGIN_DIR="./public/dist/plugins"

## dist
# clean
rm -rf ${DIST_DIR} && mkdir -p ${DIST_DIR}
cp -r ./ui/artalk/dist/{Artalk.css,Artalk.js} ${DIST_DIR}
cp -r ./ui/artalk/dist/{ArtalkLite.css,ArtalkLite.js} ${DIST_DIR}

I18N_DIR="${DIST_DIR}/i18n"
mkdir -p ${I18N_DIR}
cp -r ./ui/artalk/dist/i18n/*.js ${I18N_DIR}

## sidebar
rm -rf ${I18N_DIR} && mkdir -p ${I18N_DIR}
rm -rf ${SIDEBAR_DIR} && mkdir -p ${SIDEBAR_DIR}
cp -r ./ui/artalk-sidebar/dist/* ${SIDEBAR_DIR}

## plugins
PLUGIN_DIR="${DIST_DIR}/plugins"
mkdir -p ${PLUGIN_DIR}
rm -rf ${PLUGIN_DIR} && mkdir -p ${PLUGIN_DIR}

pnpm build:auth
cp -r ./ui/plugin-auth/dist/artalk-plugin-auth.js ${PLUGIN_DIR}

## create tarball for release
mkdir -p ./local/artalk_ui
cp -r ${DIST_DIR} ${SIDEBAR_DIR} ./local/artalk_ui

mkdir -p ./local/release_includes
tar -czf ./local/release_includes/artalk_ui.tar.gz -C ./local artalk_ui
## copy
cp ./ui/artalk/dist/{Artalk.css,Artalk.js} ${DIST_DIR}
cp ./ui/artalk/dist/{ArtalkLite.css,ArtalkLite.js} ${DIST_DIR}
cp ./ui/artalk/dist/i18n/*.js ${I18N_DIR}
cp -r ./ui/artalk-sidebar/dist/* ${SIDEBAR_DIR}
cp ./ui/plugin-*/dist/*.js ${PLUGIN_DIR}
9 changes: 9 additions & 0 deletions scripts/pack-frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

rm -rf ./local/artalk_ui && mkdir -p ./local/artalk_ui
cp -r ./public/* ./local/artalk_ui

mkdir -p ./local/release_includes
tar -czf ./local/release_includes/artalk_ui.tar.gz -C ./local artalk_ui

echo $(realpath ./local/release_includes/artalk_ui.tar.gz)

0 comments on commit 0627e04

Please sign in to comment.