refactor: 优化构建流程

This commit is contained in:
msojocs 2022-02-23 22:09:39 +08:00
parent 4744ec978d
commit b2b7881e89
5 changed files with 101 additions and 60 deletions

View File

@ -9,7 +9,7 @@ on:
push: push:
tags: tags:
- v* - v*
branches: [ master, reduce-wine] branches: [ master, actions-dev]
pull_request: pull_request:
branches: [ master ] branches: [ master ]
# # Allows you to run this workflow manually from the Actions tab # # Allows you to run this workflow manually from the Actions tab
@ -39,8 +39,9 @@ jobs:
pwd pwd
ls -l ls -l
export ACTION_MODE=true export ACTION_MODE=true
npm uninstall node-gyp -g sudo apt-get install -y libx11-dev libxkbfile-dev p7zip-full python2 python3 libkrb5-dev gcc openssl libssh2-1-dev g++ make
npm install node-gyp nw-gyp npm -g npm install node-gyp nw-gyp npm -g
node-gyp install
- id: Tag - id: Tag
run: | run: |
@ -55,65 +56,34 @@ jobs:
echo "::set-output name=name::$name" echo "::set-output name=name::$name"
- name: Build - name: Build
run: docker-compose up
- name: Refactor Directory Structure
run: | run: |
sudo chmod -R 777 package.nw node # docker-compose up
ls -l tools/setup-wechat-devtools-bash
sudo rm -rf cache tmp .git test sudo chmod -R 755 package.nw
mkdir ${{ env. name }} bash tools/build-release.sh ${{ steps.tag.outputs.tag }} ${{ matrix.ARCH }}
sudo find -maxdepth 1 -not -name ${{ env.name }} -not -name . -exec mv {} ${{ env.name }} \;
sudo cp -r "${{ env.name }}/package.nw/node_modules/nodegit" nodegit
sudo cp -r "${{ env.name }}/compiler" compiler
ls -l
env:
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
- name: Compress - name: Compress nodegit compiler
run: | run: |
ls -l ls -l
tar -zvcf compiler.tar.gz compiler sudo cp -r package.nw/node_modules/nodegit tmp/build/nodegit
tar -zvcf nodegit.tar.gz nodegit sudo cp -r compiler tmp/build/compiler
sudo rm -rf compiler nodegit ${{ env.name }}/node_modules cd tmp/build
ls -l
tar -zcf compiler.tar.gz compiler
tar -zcf nodegit.tar.gz nodegit
sudo rm -rf compiler nodegit
ls -l ls -l
env:
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
- name: Build AppImage && Pack - name: View Directory
run: | run: |
bash ./${{ env.name }}/tools/appimage.sh
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod a+x appimagetool-x86_64.AppImage
# build AppImage
./appimagetool-x86_64.AppImage ./${{ env.name }}/tmp/AppDir ${{ env.name }}_${{ env.ARCH }}_wine.AppImage
# pack
sudo rm -rf compiler nodegit ${{ env.name }}/tmp
tar -zvcf ${{ env.name }}_${{ env.ARCH }}_wine.tar.gz ${{ env.name }}
# reduce wine
export NO_WINE=true
bash ${{ env.name }}/tools/fix-core
bash ${{ env.name }}/tools/fix-other
bash ./${{ env.name }}/tools/appimage.sh
# build AppImage
./appimagetool-x86_64.AppImage ./${{ env.name }}/tmp/AppDir ${{ env.name }}_${{ env.ARCH }}_no_wine.AppImage
sudo rm -rf compiler nodegit ${{ env.name }}/tmp
# pack
tar -zvcf ${{ env.name }}_${{ env.ARCH }}_no_wine.tar.gz ${{ env.name }}
sudo rm -rf appimagetool-x86_64.AppImage ${{ env.name }}
ls -l ls -l
env:
name: 'WeChat_Dev_Tools_${{ steps.tag.outputs.tag }}'
ARCH: '${{ matrix.ARCH }}'
- name: Create release and upload artifacts - name: Create release and upload artifacts
if: startsWith(github.ref, 'refs/heads/') if: startsWith(github.ref, 'refs/heads/')
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
cd tmp/build
wget -q https://github.com/TheAssassin/pyuploadtool/releases/download/continuous/pyuploadtool-x86_64.AppImage wget -q https://github.com/TheAssassin/pyuploadtool/releases/download/continuous/pyuploadtool-x86_64.AppImage
chmod +x pyuploadtool-x86_64.AppImage chmod +x pyuploadtool-x86_64.AppImage
./pyuploadtool-x86_64.AppImage WeChat*.AppImage *.tar.gz ./pyuploadtool-x86_64.AppImage WeChat*.AppImage *.tar.gz
@ -127,5 +97,5 @@ jobs:
name: ${{ steps.tag.outputs.name }} name: ${{ steps.tag.outputs.name }}
tag_name: ${{ steps.tag.outputs.tag }} tag_name: ${{ steps.tag.outputs.tag }}
files: | files: |
*.tar.gz tmp/build/*.tar.gz
*.AppImage tmp/build/*.AppImage

76
tools/build-release.sh Normal file
View File

@ -0,0 +1,76 @@
#!/bin/bash
# 脚本执行前提已完成支持wine的基本构建
set -e
root_dir=$(cd `dirname $0`/.. && pwd -P)
tmp_dir="$root_dir/tmp"
build_dir="$tmp_dir/build"
version=$1
ARCH=$2
success() {
echo -e "\033[42;37m 成功 \033[0m $1"
}
notice() {
echo -e "\033[36m $1 \033[0m "
}
fail() {
echo -e "\033[41;37m 失败 \033[0m $1"
}
if [[ $version == '' ]];then
fail "请指定版本"
exit 1
elif [[ $ARCH == '' ]];then
fail "请指定架构"
exit 1
fi
export ARCH=$ARCH
rm -rf "$build_dir"
mkdir -p "$build_dir"
notice "下载AppImage构建工具"
if [ $ACTION_MODE!='true' ]; then
appimagetool_host="github.com"
else
appimagetool_host="download.fastgit.org"
fi
wget "https://$appimagetool_host/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" \
-O "$tmp_dir/appimagetool-x86_64.AppImage"
chmod a+x "$tmp_dir/appimagetool-x86_64.AppImage"
for type in wine no_wine; do
notice "当前构建类型: $type";
FULL_NAME="WeChat_Dev_Tools_${version}_${ARCH}_$type"
if [[ $type == 'no_wine' ]];then
notice "no wine handle"
export NO_WINE=true
bash "$root_dir/tools/fix-core"
bash "$root_dir/tools/fix-other"
fi
mkdir -p "$build_dir/$FULL_NAME"
# 构建压缩包
notice "COPY bin"
\cp -rf "$root_dir/bin" "$build_dir/$FULL_NAME/bin"
notice "COPY nwjs"
\cp -drf "$root_dir/nwjs" "$build_dir/$FULL_NAME/nwjs"
notice "COPY node"
rm -rf "$build_dir/$FULL_NAME/nwjs/node"
\cp -rf "$root_dir/node/bin/node" "$build_dir/$FULL_NAME/nwjs/node"
notice "COPY package.nw"
\cp -rf "$root_dir/package.nw" "$build_dir/$FULL_NAME/package.nw"
notice "MAKE tar.gz"
cd "$build_dir" && tar -zcf "$FULL_NAME.tar.gz" "$FULL_NAME"
# 构建AppImage
notice "BUILD AppImage"
bash "$root_dir/tools/appimage.sh"
"$tmp_dir/appimagetool-x86_64.AppImage" "$root_dir/tmp/AppDir" "$build_dir/$FULL_NAME.AppImage"
# 删除构建资源
notice "DELETE Build Source"
rm -rf "$build_dir/$FULL_NAME"
done

View File

@ -2,6 +2,7 @@
# 参数: # 参数:
# 1 ---- NW版本 # 1 ---- NW版本
set -e
SOURCE="${BASH_SOURCE[0]}" SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )" DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

View File

@ -77,16 +77,10 @@ const upgrade = function (extractPath) {
if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) { if (fs.existsSync(path.resolve(__dirname, "../nwjs"))) {
if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node"))) { if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node"))) {
fs.symlinkSync( execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -sr ../node/bin/node node`)
path.resolve(__dirname, "../node/bin/node"),
path.resolve(__dirname, "../nwjs/node")
);
} }
if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node.exe"))) { if (!fs.existsSync(path.resolve(__dirname, "../nwjs/node.exe"))) {
fs.symlinkSync( execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -s node node.exe`)
"node",
path.resolve(__dirname, "../nwjs/node.exe")
);
} }
} }

View File

@ -90,11 +90,11 @@ const upgrade = function (extractPath) {
execSync(`rm -rf ${extractPath}`); execSync(`rm -rf ${extractPath}`);
if (fs.existsSync(path.resolve(__dirname, "../node/bin/node"))) { if (fs.existsSync(path.resolve(__dirname, "../node/bin/node"))) {
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node")); execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -sr ../node/bin/node node`)
fs.linkSync(path.resolve(__dirname, "../node/bin/node"), path.resolve(__dirname, "../nwjs/node.exe")); execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -s node node.exe`)
} }
if (fs.existsSync(path.resolve(__dirname, "../package.nw"))) { if (fs.existsSync(path.resolve(__dirname, "../package.nw"))) {
fs.symlinkSync(path.resolve(__dirname, "../package.nw"), path.resolve(__dirname, "../nwjs/package.nw")); execSync(`cd ${path.resolve(__dirname, "../nwjs")} && ln -sr ../package.nw package.nw`)
} }
resolve(); resolve();