Skip to content

Commit d5d0d88

Browse files
Merge pull request #194 from learnsoftwaredevelopment/added-nodejs-with-docker-db-github-workflow
Added additional GitHub Actions workflow which connects to a docker `mongodb` instance
2 parents 8012df6 + d76a2a1 commit d5d0d88

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3.8'
2+
3+
services:
4+
mongo:
5+
image: mongo
6+
restart: always
7+
environment:
8+
MONGO_INITDB_ROOT_USERNAME: root
9+
MONGO_INITDB_ROOT_PASSWORD: password
10+
volumes:
11+
- db-data:/data/db
12+
ports:
13+
- 27017:27017
14+
15+
volumes:
16+
db-data:
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node while connecting to a mongodb docker instance
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js with docker db CI
5+
6+
on:
7+
push:
8+
branches: [master]
9+
pull_request:
10+
branches: [master]
11+
# Added in response to recent changes by GitHub on 1 March 2021 involving dependabot pull requests running with read only permissions which resulted in by default GitHub secrets are unable to be read.
12+
# References:
13+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target (Announcement of changes to be made to dependabot pull requests)
14+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ (Recommended security mitigations by GitHub)
15+
# https://github.com/dependabot/dependabot-core/issues/3253#issuecomment-797125425 (Ongoing GitHub issues by users in response to the changes)
16+
pull_request_target:
17+
branches: [master]
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
23+
timeout-minutes: 18
24+
25+
strategy:
26+
matrix:
27+
node-version: [14.x]
28+
29+
# If the Pull Request is coming from a fork (pull_request_target), ensure it's opened by "dependabot[bot]". Otherwise, clone it normally.
30+
# References:
31+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target
32+
# https://github.com/dependabot/dependabot-core/issues/3253#issuecomment-797125425 (dependabot PM recommended solution)
33+
34+
if:
35+
${{ (github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]') ||
36+
(github.event_name != 'pull_request_target' && github.actor != 'dependabot[bot]') }}
37+
38+
steps:
39+
- name: checkout
40+
if: ${{ github.event_name != 'pull_request_target' }}
41+
uses: actions/checkout@v2.3.4
42+
43+
- name: checkout Pull Request (dependabot[bot] only)
44+
if: ${{ github.event_name == 'pull_request_target' }}
45+
uses: actions/checkout@v2.3.4
46+
with:
47+
# Without ref with pull_request_target, it does not actually build the PR, instead it builds the latest changeset from the target repository which is not the intended behaviour. (Reference: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ [Last example])
48+
ref: ${{ github.event.pull_request.head.sha }}
49+
50+
# Pull the latest image to build, and avoid caching pull-only images.
51+
# (docker pull is faster than caching in most cases.)
52+
- name: docker-compose pull
53+
run: docker-compose pull
54+
55+
- name: Use Node.js ${{ matrix.node-version }}
56+
uses: actions/setup-node@v2.2.0
57+
with:
58+
node-version: ${{ matrix.node-version }}
59+
cache: npm
60+
- name: npm ci
61+
run: npm ci
62+
- name: npm run build
63+
run: npm run build --if-present
64+
- name: Build and Start mongodb in docker instance
65+
shell: bash
66+
run: docker-compose up --file ./.github/ci/docker-compose-test-ci-db-only.yml up --build --detach
67+
- name: Running test cases
68+
run: npm test-ci
69+
env:
70+
PORT: ${{ secrets.PORT }}
71+
TEST_MONGODB_URI: mongodb://root:password@mongo:27017/softwareRepositoryTest?authSource=admin
72+
FIREBASE_CLIENT_API_KEY: ${{ secrets.FIREBASE_CLIENT_API_KEY }}
73+
# Your firebase service account information
74+
FIREBASE_ADMIN_SA_TYPE: ${{ secrets.FIREBASE_ADMIN_SA_TYPE }}
75+
FIREBASE_ADMIN_SA_PROJECT_ID: ${{ secrets.FIREBASE_ADMIN_SA_PROJECT_ID }}
76+
FIREBASE_ADMIN_SA_PRIVATE_KEY_ID: ${{ secrets.FIREBASE_ADMIN_SA_PRIVATE_KEY_ID }}
77+
FIREBASE_ADMIN_SA_PRIVATE_KEY: ${{ secrets.FIREBASE_ADMIN_SA_PRIVATE_KEY }}
78+
FIREBASE_ADMIN_SA_CLIENT_EMAIL: ${{ secrets.FIREBASE_ADMIN_SA_CLIENT_EMAIL }}
79+
FIREBASE_ADMIN_SA_CLIENT_ID: ${{ secrets.FIREBASE_ADMIN_SA_CLIENT_ID }}
80+
FIREBASE_ADMIN_SA_AUTH_URI: ${{ secrets.FIREBASE_ADMIN_SA_AUTH_URI }}
81+
FIREBASE_ADMIN_SA_TOKEN_URI: ${{ secrets.FIREBASE_ADMIN_SA_TOKEN_URI }}
82+
FIREBASE_ADMIN_SA_AUTH_PROVIDER_X509_CERT_URL: ${{ secrets.FIREBASE_ADMIN_SA_AUTH_PROVIDER_X509_CERT_URL}}
83+
FIREBASE_ADMIN_SA_CLIENT_X509_CERT_URL: ${{ secrets.FIREBASE_ADMIN_SA_CLIENT_X509_CERT_URL}}

0 commit comments

Comments
 (0)