forked from treehollow/webhole
-
Notifications
You must be signed in to change notification settings - Fork 0
49 lines (46 loc) · 2.67 KB
/
deploy.yml
File metadata and controls
49 lines (46 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# This is a basic workflow to help you get started with Actions
name: Build and Deploy
on: [ push ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
with:
persist-credentials: false
submodules: true
- name: Extract branch name
shell: bash
run: echo "branch_name=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV
id: extract_branch
- name: Install and Build 🔧 # This example project is built using npm and outputs the result to the 'build' folder. Replace with the commands required to build your project, or remove this step entirely if your site is pre-built.
env:
REPO_NAME: ${{ github.event.repository.full_name }}
BRANCH_NAME: ${{ env.branch_name }}
run: |
if [ "$BRANCH_NAME" = "master" ]; then
export DEPLOY_BRANCH="gh-pages-master"
else
export DEPLOY_BRANCH="gh-pages"
fi
echo "deploy_branch=${DEPLOY_BRANCH}" >> $GITHUB_ENV
CDN_URL="https://cdn.jsdelivr.net/gh/${REPO_NAME}@${DEPLOY_BRANCH}"
#CDN_URL="."
VERSION_NUMBER="v$(grep -oP '"version": "\K[^"]+' package.json | head -n1)"
npm install
echo "DEPLOY_BRANCH=$DEPLOY_BRANCH, VERSION_NUMBER=$VERSION_NUMBER, CDN_URL=$CDN_URL"
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|https://cdn.jsdelivr.net/gh/'"${REPO_NAME}"'@'"$DEPLOY_BRANCH"'/index.html|./index.html|g' build/*-*
sed -i 's|https://cdn.jsdelivr.net/gh/'"${REPO_NAME}"'@'"$DEPLOY_BRANCH"'/service-worker.js|./service-worker.js|g' build/*-*
sed -i 's|"https://cdn.jsdelivr.net/gh/'"${REPO_NAME}"'@'"$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
- name: Deploy 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: ${{ env.deploy_branch }} # The branch the action should deploy to.
FOLDER: build # The folder the action should deploy.
CLEAN: true # Automatically remove deleted files from the deploy branch