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: Using Reusable Deployment | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v3 | |
- name: Cache dependencies | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit != 'true' # cache-hit is an output of the actions/cache@v3. Boolean | |
run: npm ci | |
- name: Lint code | |
run: npm run lint | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v3 | |
- name: Cache dependencies | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: npm ci | |
- name: Test code | |
id: run-tests | |
run: npm run test | |
- name: Upload test report | |
if: steps.run-tests.outcome == 'failure' # This step will be run only if prev failed. Overall workflow will fail | |
uses: actions/upload-artifact@v3 | |
with: | |
name: test-report | |
path: test.json | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get code | |
uses: actions/checkout@v3 | |
- name: Cache dependencies | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: node_modules | |
key: deps-node-modules-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: npm ci | |
- name: Build website | |
id: build-website | |
run: npm run build | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dist-files | |
path: dist | |
deploy: | |
needs: build | |
uses: ./.github/workflows/reusable.yml # Reusable workflow | |
with: | |
my-artifact-name: dist-files # function params, e.g. here - dist-files | |
#secrets: | |
#some-secret: ${{ secrets.SOME_SECRET }} # secret function params | |
print-deploy-result: | |
needs: deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Output deploy result | |
run: echo "${{ needs.deploy.outputs.my-result }}" # function return value | |
report: | |
needs: [lint, deploy] # first and last of the sequence (lint is parallel). Important for IF statement to work, otherwise report will run in parallel and won't do the trick | |
if: failure() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Output information | |
run: echo "${{ toJSON(github) }}" |