-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (125 loc) · 4.18 KB
/
deployment.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Deploy Project
on:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
push:
branches:
- main
- fix-*
- feat/**
paths-ignore:
- wofkflows/*
env:
MONGODB_DB_NAME: gha-demo
jobs:
lint:
# Notice: ubuntu runner comes with node.js pre installed
runs-on: ubuntu-latest
steps:
# download the code from the repository
- name: Get code
uses: actions/checkout@v4
# To fix a node.js version
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: "18"
- name: info on kind of event triggering the workflow
run: echo '${{ toJSON(github.event) }}'
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: ~/.npm # npm cache folder path
# key to retrieve the cache
key: deps-node-module-${{ hashFiles('**/package-lock.json') }}
- name: install dependencies
run: npm ci # to ensure you don't install some breaking versions
- name: run linter
run: npm run lint
test:
env:
MONGODB_CLUSTER_ADDRESS: gha-udemy.njl9hgv.mongodb.net
MONGODB_USERNAME: lambda
MONGODB_PASSWORD: bN66ZWSga9pJ4GUF
PORT: 8080
needs: [lint]
runs-on: ubuntu-latest
steps:
# download the code from the repository
- name: Get code
uses: actions/checkout@v4
# To fix a node.js version
- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: "18"
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: ~/.npm # npm cache folder path
# key to retrieve the cache
key: deps-node-module-${{ hashFiles('**/package-lock.json') }}
- name: install dependencies
run: npm ci # to ensure you don't install some breaking versions
- name: ensure server is running before running tests
# requires mongodb atlas cluster to be accessible from anywhere
# run: npm start & npx wait-on -v http://127.0.0.1:${{ env.PORT }}
run: npm start & npx wait-on http://127.0.0.1:$PORT
- name: Run tests
run: npm test
- name: Output information
run: echo "Test passed successfully with mongodb cluster ${{ env.MONGODB_CLUSTER_ADDRESS }}"
# build:
# needs: [lint, test]
# runs-on: ubuntu-latest
# outputs:
# script_file: ${{ steps.publish_js_filename.outputs.script_file }}
# steps:
# # download the code from the repository
# - name: Get code
# uses: actions/checkout@v4
# # To fix a node.js version
# - name: Install NodeJS
# uses: actions/setup-node@v4
# with:
# node-version: "18"
# - name: Cache Dependencies
# uses: actions/cache@v4
# with:
# path: ~/.npm # npm cache folder path
# # key to retrieve the cache
# key: deps-node-module-${{ hashFiles('**/package-lock.json') }}
# - name: install dependencies
# run: npm ci # to ensure you don't install some breaking versions
# - name: Build code
# run: npm run build
# - name: Publish JS filename
# id: publish_js_filename
# run: |
# find dist/assets/*.js -type f -exec echo 'script_file={}' >> $GITHUB_OUTPUT ';'
# cat "$GITHUB_OUTPUT"
# # soon deprecated
# # run: find dist/assets/*.js -type f -execdir echo '::set-output name=script-file::{}' ';'
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# with:
# name: built-artifacts
# path: dist
# deploy:
# # to run the deployment only when the test job is successful...
# needs: [lint, test, build] # array of jobs to wait for
# runs-on: ubuntu-latest
# steps:
# - name: Get build artifacts
# uses: actions/download-artifact@v4
# with:
# name: built-artifacts
# - name: Output built files
# run: ls -la
# - name: Output file name
# # needs object contains all output of jobs
# run: |
# echo "${{ needs.build.outputs.script_file }}"
# - name: Deploy
# run: echo "Deploying project..."