From 8985c7b4a0ebc4815bd049e44e78200df73e9626 Mon Sep 17 00:00:00 2001 From: thuhole Date: Tue, 21 Jul 2020 19:39:43 +0800 Subject: [PATCH] travis update --- .env | 1 - .travis.yml | 13 ++----------- package.json | 2 +- travis_deploy.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 travis_deploy.sh diff --git a/.env b/.env index 6b30cee..bf999ca 100644 --- a/.env +++ b/.env @@ -1,3 +1,2 @@ REACT_APP_VERSION=$npm_package_version EXTEND_ESLINT=true -PUBLIC_URL=https://cdn.jsdelivr.net/gh/thuhole/webhole@gh-pages diff --git a/.travis.yml b/.travis.yml index 57e6af8..4c509f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,14 +6,5 @@ cache: - node_modules after_success: - - git config --global user.name "thuhole" - - git config --global user.email "thuhole@users.noreply.github.com" - - git remote rm origin - - git remote add origin https://thuhole:${GH_TOKEN}@github.com/thuhole/webhole.git - - CI=false REACT_APP_BUILD_INFO=$(printf "Dev%s" "$(TZ=Asia/Shanghai date +"%y%m%d%H%M%S")") npm run build - #额,这里用了个骚操作来修复Service Worker在Precache CDN内容的时候index.html返回content-type text/plain的问题 - - sed -i 's/\/\/cdn.jsdelivr.net\/gh\/thuhole\/webhole@gh-pages\/index.html/.\/index.html/g' build/*-* - - sed -i 's/\/\/cdn.jsdelivr.net\/gh\/thuhole\/webhole@gh-pages\/service-worker.js/.\/service-worker.js/g' build/*-* - - sed -i 's/"\/\/cdn.jsdelivr.net\/gh\/thuhole\/webhole@gh-pages","\/service-worker.js"/".","\/service-worker.js"/' build/static/js/*.js - - sed -i 's/storage.googleapis.com\/workbox-cdn\/releases\/4.3.1/cdn.jsdelivr.net\/npm\/workbox-cdn@4.3.1\/workbox/g' build/service-worker.js - - npm run deploy + - chmod +x ./travis_deploy.sh + - ./travis_deploy.sh diff --git a/package.json b/package.json index 36912ab..433f2c8 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "build": "react-scripts build", "test": "echo 'skipped react-scripts test --env=jsdom'", "predeploy": "", - "deploy": "gh-pages -d build -m $(TZ=Asia/Shanghai date +\"%y%m%d%H%M%S\")", + "deploy": "gh-pages -b $DEPLOY_BRANCH -d build -m $(TZ=Asia/Shanghai date +\"%y%m%d%H%M%S\")", "eject": "react-scripts eject", "lint": "eslint --fix src/*.js" }, diff --git a/travis_deploy.sh b/travis_deploy.sh new file mode 100644 index 0000000..1a7604e --- /dev/null +++ b/travis_deploy.sh @@ -0,0 +1,27 @@ +#!/bin/bash +if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then + echo "skip deploy for pull request..." + exit 0 +fi + +if [ "$TRAVIS_BRANCH" = "master" ]; then + export DEPLOY_BRANCH="gh-pages-master" +else + export DEPLOY_BRANCH="gh-pages" +fi + +CDN_URL="https://cdn.jsdelivr.net/gh/thuhole/webhole@$DEPLOY_BRANCH" +VERSION_NUMBER="v$(grep -oP '"version": "\K[^"]+' package.json | head -n1).$TRAVIS_BUILD_NUMBER" + +echo "DEPLOY_BRANCH=$DEPLOY_BRANCH, VERSION_NUMBER=$VERSION_NUMBER, CDN_URL=$CDN_URL" +git config --global user.name "thuhole" +git config --global user.email "thuhole@users.noreply.github.com" +git remote rm origin +git remote add origin https://thuhole:"${GH_TOKEN}"@github.com/thuhole/webhole.git +CI=false PUBLIC_URL=$CDN_URL REACT_APP_BUILD_INFO=$VERSION_NUMBER npm run build +#额,这里用了个骚操作来修复Service Worker在Precache CDN内容的时候index.html返回content-type text/plain的问题 +sed -i 's|//cdn.jsdelivr.net/gh/thuhole/webhole@'"$DEPLOY_BRANCH"'/index.html|./index.html|g' build/*-* +sed -i 's|//cdn.jsdelivr.net/gh/thuhole/webhole@'"$DEPLOY_BRANCH"'/service-worker.js|./service-worker.js|g' build/*-* +sed -i 's|"//cdn.jsdelivr.net/gh/thuhole/webhole@'"$DEPLOY_BRANCH"'","/service-worker.js"|".","/service-worker.js"|' build/static/js/*.js +sed -i 's|storage.googleapis.com/workbox-cdn/releases/4.3.1|cdn.jsdelivr.net/npm/workbox-cdn@4.3.1/workbox|g' build/service-worker.js +npm run deploy \ No newline at end of file