generated from ecomplus/storefront-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(build-and-deploy): deploy to firebase
- Loading branch information
1 parent
8fe7355
commit 51a0a40
Showing
3 changed files
with
32 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ on: | |
- 'template/**' | ||
- 'package-lock.json' | ||
- '.ecomplus.cd.json' | ||
- '.netlify/**' | ||
- '.functions/**' | ||
- 'firebase.json' | ||
- '.github/build-and-deploy' | ||
- '.github/workflows/build-and-deploy.yml' | ||
|
||
|
@@ -31,14 +32,14 @@ jobs: | |
id: remote_repo | ||
|
||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.ref }} | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '16.x' | ||
node-version: '14.x' | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v4 | ||
|
@@ -48,25 +49,12 @@ jobs: | |
restore-keys: | | ||
${{ runner.os }}-node- | ||
- name: Get ISG state | ||
id: isg_state | ||
run: | | ||
if [ -f .isg ]; then | ||
echo "::set-output name=rand::$(cat .isg)"; | ||
else | ||
echo "::set-output name=rand::0"; | ||
fi | ||
- name: Cache output | ||
continue-on-error: true | ||
uses: actions/cache@v4 | ||
with: | ||
path: .deploy/publish | ||
key: ${{ hashFiles('.bundles.json') }}-${{ hashFiles('template/p*/**') }}-${{ hashFiles('content/**') }}-${{ steps.isg_state.outputs.rand }} | ||
|
||
- name: Install dependencies | ||
- 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/[email protected] | ||
with: | ||
|
@@ -78,46 +66,36 @@ jobs: | |
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 ] && [ -f .bundles.json ] && [ -f .deploy/publish/storefront.js ]; then | ||
if [ $IS_ECOMPLUS_CD != false ]; then | ||
BUILD_SLUG=$(node -p "require('./.ecomplus.cd.json').slug || false"); | ||
if [ $BUILD_SLUG != false ]; then | ||
npm run build -- --prerender=index,$BUILD_SLUG --no-bundler; | ||
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"; | ||
else | ||
npm run build -- --prerender-limit=1000 --no-bundler; | ||
echo "::set-output name=isg::1"; | ||
exit 0; | ||
fi | ||
else | ||
npm run build -- --prerender=index,app/index,search,404 --prerender-limit=300; | ||
echo "::set-output name=isg::0"; | ||
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: Output ISG state | ||
id: new_isg_state | ||
env: | ||
ISG_ENUM: ${{ steps.partial_build.outputs.isg }} | ||
run: | | ||
if [ $ISG_ENUM != 0 ] || [ ! -f .isg ]; then | ||
ISG_STATE=$RANDOM; | ||
echo $ISG_STATE > .isg; | ||
else | ||
ISG_STATE=$(cat .isg); | ||
fi | ||
echo "::set-output name=rand::$ISG_STATE"; | ||
- name: Config Git and check diff | ||
run: | | ||
git config --local user.email '[email protected]' | ||
git config --local user.name 'GitHub Action' | ||
git add .isg .bundles.json content template | ||
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 defaults, bundles and isg states [skip ci]' | ||
git commit -m 'chore(post-build): update template and content defaults [skip ci]' | ||
- name: Push changes | ||
if: steps.git_diff.outputs.diff == 1 | ||
|
@@ -126,61 +104,14 @@ jobs: | |
REMOTE_REPO: ${{ steps.remote_repo.outputs.url }} | ||
run: git push "${REMOTE_REPO}" HEAD:master --follow-tags | ||
|
||
- name: Clear cache if not ISG | ||
- name: Deploy to Firebase | ||
if: steps.partial_build.outputs.isg == 0 | ||
continue-on-error: true | ||
run: rm -rf .deploy | ||
|
||
- name: Setup output directory to deploy | ||
run: | | ||
mkdir -p .deploy/publish | ||
cp .nvmrc .deploy/ 2>/dev/null || : | ||
cp -r dist/* .deploy/publish/ | ||
rm -rf .deploy/publish/netlify.toml | ||
cp -r .netlify/* .deploy/ | ||
cp -r template .deploy/functions/ssr/ | ||
rm -rf .deploy/functions/ssr/template/public | ||
rm -rf .deploy/functions/ssr/template/scss | ||
cp -r content .deploy/functions/ssr/ | ||
cp .bundles.json .deploy/functions/ssr/bundles.json | ||
mkdir -p .deploy/functions/ssr/template/pages/@ecomplus/storefront-template/template | ||
cp -r node_modules/@ecomplus/widget-* .deploy/functions/ssr/template/pages/@ecomplus/ 2>/dev/null || : | ||
cp -r node_modules/@ecomplus/storefront-template/template/pages .deploy/functions/ssr/template/pages/@ecomplus/storefront-template/template/ || : | ||
- name: Clear functions directory | ||
continue-on-error: true | ||
run: rm -rf .deploy/functions/ssr/template/pages/**/node_modules | ||
|
||
- name: Zip Lambda functions | ||
run: | | ||
npx zip-it-and-ship-it .deploy/functions .deploy/functions-zip | ||
rm -rf .deploy/functions | ||
- name: Reset dist to clear Git ref | ||
if: steps.partial_build.outputs.isg == 0 | ||
continue-on-error: true | ||
env: | ||
REMOTE_REPO: ${{ steps.remote_repo.outputs.url }} | ||
GCP_ACCOUNT_KEY: ${{ secrets.GCP_ACCOUNT_KEY }} | ||
run: | | ||
git push "${REMOTE_REPO}" --delete dist; | ||
git checkout --orphan dist | ||
git rm -rf . | ||
git commit --no-verify --allow-empty -m "Reset dist [skip ci]" | ||
git push "${REMOTE_REPO}" HEAD:dist --force --follow-tags | ||
git checkout master | ||
- name: Push to branch dist to trigger deploy | ||
uses: JamesIves/github-pages-deploy-action@releases/v3 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
BRANCH: dist | ||
FOLDER: .deploy | ||
CLEAN: true | ||
|
||
- name: Cache output force update | ||
if: steps.new_isg_state.outputs.rand != steps.isg_state.outputs.rand | ||
continue-on-error: true | ||
uses: actions/cache@v4 | ||
with: | ||
path: .deploy/publish | ||
key: ${{ hashFiles('.bundles.json') }}-${{ hashFiles('template/p*/**') }}-${{ hashFiles('content/**') }}-${{ steps.new_isg_state.outputs.rand }} | ||
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 |