Build and deploy Node.js app to Azure Web App - cote-strapi #201
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
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | |
# More GitHub Actions for Azure: https://github.com/Azure/actions | |
name: Build and deploy Node.js app to Azure Web App - cote-strapi | |
env: | |
AZURE_WEBAPP_NAME: cote-strapi # set this to your application's name | |
AZURE_WEBAPP_PACKAGE_PATH: './apps/strapi' # set this to the path to your web app project, defaults to the repository root | |
NODE_VERSION: '18.x' # set this to the node version to use | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
changes: | |
runs-on: 'ubuntu-latest' | |
outputs: | |
strapi: ${{ steps.filter.outputs.strapi }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: '[check if build necessary]' | |
uses: dorny/paths-filter@v2 | |
id: filter | |
with: | |
filters: | | |
strapi: | |
- '.github/workflows/azure-deploy.yml' | |
- '**/apps/strapi/**/*' | |
build: | |
runs-on: ubuntu-latest | |
needs: changes | |
if: ${{ needs.changes.outputs.strapi == 'true' }} | |
strategy: | |
matrix: | |
node-version: [18.x] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
# TODO: Fix yarn cache | |
cache: 'yarn' | |
cache-dependency-path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/yarn.lock | |
# - name: Get yarn cache directory path | |
# id: yarn-cache-dir-path | |
# run: echo "::set-output name=dir::$(yarn cache dir)" | |
# - uses: actions/cache@v3 | |
# id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
# with: | |
# path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
# key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
# restore-keys: | | |
# ${{ runner.os }}-yarn- | |
- name: install & build | |
run: yarn --prefer-offline && NODE_ENV=production yarn build | |
working-directory: ${{env.AZURE_WEBAPP_PACKAGE_PATH}} | |
- name: 'rm cache' | |
run: rm -rf .cache | |
working-directory: ${{env.AZURE_WEBAPP_PACKAGE_PATH}} | |
- name: 'Deploy to Azure WebApp' | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: ${{ env.AZURE_WEBAPP_NAME }} | |
slot-name: 'Production' # <-- this property wasn't in suggested file | |
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_48C35E5FD0E54E52AFC6BDFFE8471FA5 }} | |
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} | |
# - name: 'Tar files' | |
# # run: cd apps/strapi && rm -rf .cache && tar -zvcf ../../node-app.tar.gz . && cd ../.. | |
# run: tar -zvcf ../../node-app.tar.gz . | |
# working-directory: ${{env.working-directory}} | |
# # - name: 'zip that thang' | |
# # run: zip -r node-app.zip apps/strapi | |
# - name: Upload artifact for deployment job | |
# uses: actions/upload-artifact@v2 | |
# with: | |
# name: node-app | |
# path: node-app.tar.gz | |
# deploy: | |
# env: | |
# working-directory: ./apps/strapi | |
# runs-on: ubuntu-latest | |
# needs: build | |
# environment: | |
# name: 'Production' | |
# url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | |
# steps: | |
# - name: Download artifact from build job | |
# uses: actions/download-artifact@v2 | |
# with: | |
# name: node-app | |
# - name: 'Untar files' | |
# run: tar -xzf node-app.tar.gz | |
# - name: 'Cleanup Tar' | |
# run: rm node-app.tar.gz | |
# - name: 'Deploy to Azure Web App' | |
# id: deploy-to-webapp | |
# uses: azure/webapps-deploy@v2 | |
# with: | |
# app-name: 'cote-strapi' | |
# slot-name: 'Production' | |
# publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_48C35E5FD0E54E52AFC6BDFFE8471FA5 }} | |
# package: . |