chore: trigger deploy (bot) #1317
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
name: Build and deploy | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'content/**' | |
- 'template/**' | |
- 'package-lock.json' | |
- '.ecomplus.cd.json' | |
- '.netlify/**' | |
- '.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@v3 | |
with: | |
ref: ${{ github.ref }} | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '14.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: 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@v2 | |
with: | |
path: .deploy/publish | |
key: ${{ hashFiles('.bundles.json') }}-${{ hashFiles('template/p*/**') }}-${{ hashFiles('content/**') }}-${{ steps.isg_state.outputs.rand }} | |
- name: Install dependencies | |
run: npm ci --only=production | |
- name: Check last changed files | |
uses: lots0logs/[email protected] | |
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 ] && [ -f .bundles.json ] && [ -f .deploy/publish/storefront.js ]; 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; | |
echo "::set-output name=isg::2"; | |
else | |
npm run build -- --prerender-limit=1000 --no-bundler; | |
echo "::set-output name=isg::1"; | |
fi | |
else | |
npm run build -- --prerender=index,app/index,search,404 --prerender-limit=300; | |
echo "::set-output name=isg::0"; | |
fi | |
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 diff-index --quiet HEAD && echo "::set-output name=diff::0") || echo "::set-output name=diff::1" | |
id: git_diff | |
- name: Commit local file changes | |
if: steps.git_diff.outputs.diff == 1 | |
run: | | |
git commit -m 'chore(post-build): update template defaults, bundles and isg states [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: Clear cache if not ISG | |
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 }} | |
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@v2 | |
with: | |
path: .deploy/publish | |
key: ${{ hashFiles('.bundles.json') }}-${{ hashFiles('template/p*/**') }}-${{ hashFiles('content/**') }}-${{ steps.new_isg_state.outputs.rand }} |