Merge pull request #16 from jvvillanueva9104/feature/pipeline1 #45
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code, run tests, and deploy to Azure Web Apps | |
# For more information, see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | |
name: Node.js CI and Deployment | |
on: | |
push: | |
branches: | |
- "feature/*" | |
- "main" | |
- "develop" | |
pull_request: | |
branches: | |
- "develop" | |
- "main" | |
workflow_dispatch: | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [14.x, 16.x, 18.x] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
registry-url: "https://registry.npmjs.org" | |
- name: Install NPM | |
run: npm install | |
- name: Install Dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Run Tests | |
run: npm test | |
static_code_analysis: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install Snyk CLI | |
run: npm install -g snyk | |
- name: Authenticate with Snyk | |
run: snyk auth ${{ secrets.SNYK_TOKEN }} | |
- name: Run Snyk Scan | |
run: snyk test --all-projects --severity-threshold=high | |
deploy_to_test: | |
needs: [static_code_analysis, build_and_test] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'pull_request' && github.base_ref == 'refs/heads/develop' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js version | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v2 | |
with: | |
name: node-app | |
- name: "Deploy to Azure Web App - Testing" | |
uses: azure/webapps-deploy@v2 | |
id: deploy-to-webapp | |
with: | |
app-name: "turners-car-insurance-test-env" | |
slot-name: "testing" | |
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_936C3E3332AD406D90A7C20EFC2C8959 }} | |
package: . | |
deploy_to_production: | |
needs: [static_code_analysis, build_and_test] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'pull_request' && github.base_ref == 'refs/heads/main' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js version | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "18.x" | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v2 | |
with: | |
name: node-app | |
- name: "Deploy to Azure Web App - Production" | |
uses: azure/webapps-deploy@v2 | |
id: deploy-to-webapp | |
with: | |
app-name: "turners-car-insurance-quote" | |
slot-name: "Production" | |
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_B5AF5CA862324AC3980A3FDE92C61F45 }} | |
package: . | |
#comment test1 |