Skip to content

Commit

Permalink
优化发布脚本,支持更加健壮的变化检测,只在必要时才对外发布
Browse files Browse the repository at this point in the history
  • Loading branch information
rdkmaster authored Nov 3, 2022
1 parent 5f5fa64 commit 2824d8d
Show file tree
Hide file tree
Showing 8 changed files with 2,858 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dist
angular.json

# dependencies
/node_modules
node_modules

# IDEs and editors
/.idea
Expand Down
2,749 changes: 2,749 additions & 0 deletions build/package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@compodoc/compodoc": "1.0.9",
"puppeteer": "18.1.0"
}
}
147 changes: 97 additions & 50 deletions build/publish.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#!/bin/bash

scriptDir=$(cd `dirname $0`; pwd);

cd $scriptDir/..
jigsawRepo=`pwd`

params=("$@")
target=${params[0]}
source ~/.bashrc

function checkRepo() {
local repo=$1
Expand All @@ -16,25 +10,25 @@ function checkRepo() {
fi
cd $repo
local code=0
git status | grep "分支 master" > /dev/null
git status | grep -P "(位于分支|On branch) master" > /dev/null
if [ "$?" != "0" ]; then
echo "Error: the repo $repo is not in master branch"
echo "Error: the repo $repo is not in branch master!"
exit 1
fi
git status | grep "干净的工作区" > /dev/null
if [ "$?" != "0" ]; then
echo "Error: the repo $repo is not clean"
git status | grep -P "(您的分支领先|Your branch is ahead of) 'origin/.+'" > /dev/null
if [ "$?" == "0" ]; then
echo "Error: the repo $repo has unpushed commits!"
exit 1
fi
git status | grep "与上游分支 'origin/master' 一致" > /dev/null
if [ "$?" != "0" ]; then
echo "Error: the repo $repo has unpushed commits"
if [ "`git status --porcelain`" != "" ]; then
echo "Error: the repo $repo is not clean!"
exit 1
fi
echo "Great! the repo $repo is ready to work!"
}

function publishToGitee() {
echo "publishing to gitee server...."
if [[ "$GITEE_USER" == "" || "$GITEE_PWD" == "" ]]; then
echo "Error: invalid gitee user or password, need this info to auto deploy ued site"
exit 1
Expand All @@ -46,6 +40,11 @@ function publishToGitee() {
git pull origin master
rm -fr ./*
cp -r $jigsawRepo/dist/* ./
if [ "`git status --porcelain`" == "" ]; then
echo "Info: there is nothing updated to the ued site!"
return 1
fi

git add .
git commit -m 'auto updated'
git push origin master
Expand All @@ -65,6 +64,7 @@ function publishToGitee() {
}

function publishToRDK() {
echo "publishing to rdk server...."
if [ "$AWADE_ALL_WORK_DIR" == "" ]; then
echo "Error: invalid AWADE_ALL_WORK_DIR environment variable!"
exit 1
Expand All @@ -80,14 +80,12 @@ function publishToRDK() {
}

function publishUed() {
local server=${params[1]}
if [[ "$server" != "gitee" && "$server" != "rdk" ]]; then
echo "Error: invalid target server, need gitee/rdk"
exit 1
fi

cd $jigsawRepo
git pull
node build/build.js jigsaw-app-external prod
if [ "$?" != "0" ]; then
echo "Error: failed to build jigsaw external app!"
Expand All @@ -100,23 +98,44 @@ function publishUed() {
fi
}

tmpNpmPackagePath=/tmp/jigsaw-npm-package

function getNewVersion() {
local proxy=`git config --list --local | grep http.proxy | sed "s#http.proxy=##"`
local pkg=`curl -x "$proxy" -s -L https://cdn.jsdelivr.net/npm/@rdkmaster/jigsaw@latest/package.json`
if [ "$pkg" == "" ]; then
pkg=`curl -x "$proxy" -s -L https://unpkg.com/@rdkmaster/jigsaw@latest/package.json`
fi
if [ "$pkg" == "" ]; then
echo "Error: failed to read the latest version num of jigsaw!"
exit 1
fi
local curVersion=`echo $pkg | grep -Po '"version": ".+?"'`
local pkg=`cat $tmpNpmPackagePath/node_modules/@rdkmaster/jigsaw/package.json`
local curVersion=`echo $pkg | grep -Po '"version":\s*".+?"'`
local version1=`echo $curVersion | grep -Po "\d+\.\d+\."`
local version2=`echo $curVersion | grep -Po '\d+"' | grep -Po "\d+"`
version2=$((version2+1))
echo $version1$version2
}

function md5Dir() {
for file in ` ls -a $1 `
do
if [ $file == . ] || [ $file == .. ]; then
continue
fi
if [ -d $1/$file ]; then
md5Dir $1/$file
elif [ "$file" != "package.json" ]; then
allMd5sum="$allMd5sum | `md5sum $1/$file`"
fi
done
}

function getPublishedNpmChecksum() {
rm -fr $tmpNpmPackagePath
mkdir $tmpNpmPackagePath
cd $tmpNpmPackagePath
npm install @rdkmaster/jigsaw --no-optional >/dev/null 2>&1
if [ "$?" != "0" ]; then
return 1
fi
cd node_modules/@rdkmaster/jigsaw
allMd5sum="" && md5Dir .
echo $allMd5sum | md5sum
}

function publishNpm() {
npm whoami
if [ "$?" != "0" ]; then
Expand All @@ -130,10 +149,35 @@ function publishNpm() {
echo "Error: failed to build jigsaw lib!"
exit 1
fi

echo "downloading the published npm package from npm server...."
local publishedChecksum=`getPublishedNpmChecksum`
if [ "$?" != "0" ]; then
echo "Warn: failed to download published npm package!"
return
fi
cd dist/@rdkmaster/jigsaw/
allMd5sum="" && md5Dir .
local currentChecksum=`echo $allMd5sum | md5sum`
echo "The publishedChecksum: $publishedChecksum"
echo "The currentChecksum: $currentChecksum"
if [ "$publishedChecksum" == "$currentChecksum" ]; then
echo "Info: there is nothing updated to the npm package!"
return
fi

cd $jigsawRepo
local newVersion=`getNewVersion`
if [ "$?" != "0" ]; then
echo "Error: failed to read the latest version num of jigsaw!"
exit 1
fi

echo "The next version to be used: $newVersion"
sed -i 's#"version":\s*".\+"#"version":"'$newVersion'"#' dist/@rdkmaster/jigsaw/package.json

echo "publishing jigsaw lib to npm registry with new version $newVersion ..."
# npm publish --dry-run --tag latest --access public dist/@rdkmaster/jigsaw
npm publish --tag latest --access public dist/@rdkmaster/jigsaw
if [ "$?" != "0" ]; then
echo "Error: failed to publish jigsaw lib to npm registry!"
Expand All @@ -142,36 +186,39 @@ function publishNpm() {
echo "Success to publish jigsaw lib to npm registry!"
}

function checkNeedUpdate() {
checkRepo $jigsawRepo

local lastIndex=$((${#params[@]} - 1))
local forceBuild=${params[$lastIndex]}
if [ "$forceBuild" == "force" ]; then
echo "Will build forcibly"
return
fi

function updateJigsawRepo() {
cd $jigsawRepo
local gitLog1=`git log -1 --no-merges`
git pull
local gitLog2=`git log -1 --no-merges`
if [ "$gitLog1" == "$gitLog2" ]; then
echo "There is no change since last build, doing nothing."
echo "Tip: use the following command to build forcibly"
echo " sh publish.sh ${params[@]} force"
exit
fi
npm install
cd build
npm install
}

function onExit() {
cd $jigsawRepo
git checkout .
}

checkNeedUpdate
#######################################################################

target=$1
if [[ "$target" != "ued" && "$target" != "npm" ]]; then
echo "Error: invalid publish target, need ued/npm"
echo "Usage:"
echo " sh publish.sh ued rdk"
echo " sh publish.sh ued gitee"
echo " sh publish.sh npm"
exit 1
fi

trap onExit EXIT
jigsawRepo=$(cd `dirname $0`/..; pwd);
checkRepo $jigsawRepo
updateJigsawRepo

if [ "$target" == "ued" ]; then
server=$2
publishUed
elif [ "$target" == "npm" ]; then
publishNpm
else
echo "Error: invalid publish target, need ued/npm"
exit 1
fi

4 changes: 3 additions & 1 deletion build/scripts/doc-generator/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ if [ "$?" != "0" ]; then
npm install @compodoc/[email protected]
fi

rm -fr $output/documentation.json $output/fragments
rm -fr $output/documentation.json $output/fragments src/jigsaw/mobile-components
./node_modules/.bin/compodoc src/jigsaw -p tsconfig.json --silent --disableSourceCode \
--disableGraph --disableCoverage --disablePrivate --disableInternal --disableLifeCycleHooks \
--disableRoutesGraph --exportFormat json --output $output
git checkout src/jigsaw/mobile-components
if [ "$?" != "0" ]; then
echo "ERROR: cannot generate documentation(json)!"
exit 1
Expand All @@ -34,4 +35,5 @@ if [ "$?" != "0" ]; then
echo "ERROR: parse documentation error!"
exit 1
fi
rm -fr $output/documentation.json
chmod 755 -R $output
1 change: 1 addition & 0 deletions build/tools/deploy-ued-sites.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// npm i [email protected]
const puppeteer = require('puppeteer');

const user = process.env.GITEE_USER, pwd = process.env.GITEE_PWD;
Expand Down
1 change: 0 additions & 1 deletion jigsaw
Submodule jigsaw deleted from c0fd37
1 change: 1 addition & 0 deletions src/jigsaw/pc-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"jquery": "~3.5.1",
"ztree": "~3.5.24",
"ngx-perfect-scrollbar": "~8.0.0",
"ngx-color-picker": "~8.0.0",
"@rdkmaster/icon-font": "^1.0.6",
"@angular/animations": "~9.1.9",
"@angular/common": "~9.1.9",
Expand Down

0 comments on commit 2824d8d

Please sign in to comment.