generated from ecomplus/storefront-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
117 lines (103 loc) · 3.96 KB
/
build-and-deploy.yml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Build and deploy
on:
push:
branches:
- master
paths:
- 'content/**'
- 'template/**'
- 'package-lock.json'
- '.ecomplus.cd.json'
- '.functions/**'
- 'firebase.json'
- '.github/build-and-deploy'
- '.github/workflows/build-and-deploy.yml'
jobs:
build-and-deploy:
name: Build Storefront and deploy
runs-on: ubuntu-latest
timeout-minutes: 30
if: |
github.event.head_commit.message != 'Initial commit' &&
!contains(github.event.head_commit.message, '[skip ci]')
steps:
- name: Set remote repo URL
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "::set-output name=url::https://${GITHUB_ACTOR}:${TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
id: remote_repo
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: '12.x'
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install root dependencies
run: npm ci --only=production
- name: Install functions dependencies
run: cd .functions && npm ci --only=production && cd ../..
- name: Check last changed files
uses: lots0logs/gh-action-get-changed-files@2.2.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
id: changed_files
- name: Run partial build
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all }}
run: |
IS_ECOMPLUS_CD=$(node -p "const f = JSON.parse('${CHANGED_FILES}'); f.length === 1 && f[0] === '.ecomplus.cd.json'");
if [ $IS_ECOMPLUS_CD != false ]; then
BUILD_SLUG=$(node -p "require('./.ecomplus.cd.json').slug || false");
STORE_DOMAIN=$(node -p "require('./content/settings.json').domain || false");
if [ $BUILD_SLUG != false ] && [ $STORE_DOMAIN != false ]; then
IFS=",";
read -ra slug <<< "$BUILD_SLUG";
for i in "${slug[@]}"; do
curl -X PURGE "https://$STORE_DOMAIN/$i"
done;
echo "::set-output name=isg::2";
exit 0;
fi
fi
npm run build -- --prerender=index,app/index,search,404,blog,admin/index --prerender-limit=0;
echo "::set-output name=isg::0";
id: partial_build
- name: Config Git and check diff
run: |
git config --local user.email 'action@github.com'
git config --local user.name 'GitHub Action'
git add content template
(git diff-index --quiet HEAD && echo "::set-output name=diff::0") || echo "::set-output name=diff::1"
id: git_diff
- name: Commit local file changes
continue-on-error: true
if: steps.git_diff.outputs.diff == 1
run: |
git commit -m 'chore(post-build): update template and content defaults [skip ci]'
- name: Push changes
if: steps.git_diff.outputs.diff == 1
continue-on-error: true
env:
REMOTE_REPO: ${{ steps.remote_repo.outputs.url }}
run: git push "${REMOTE_REPO}" HEAD:master --follow-tags
- name: Deploy to Firebase
if: steps.partial_build.outputs.isg == 0
env:
GCP_ACCOUNT_KEY: ${{ secrets.GCP_ACCOUNT_KEY }}
run: |
if [ -f .bundles.json ] && [ -f dist/storefront.js ]; then
export GOOGLE_APPLICATION_CREDENTIALS=".firebase-adminsdk.json";
echo $GCP_ACCOUNT_KEY > $GOOGLE_APPLICATION_CREDENTIALS;
PROJECT_ID=$(node -p "require('./$GOOGLE_APPLICATION_CREDENTIALS').project_id");
GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS npx firebase deploy --project=$PROJECT_ID;
fi