Test job in container #3
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: Deployment (Container) | |
on: | |
push: | |
branches: | |
- main | |
- dev | |
env: | |
CACHE_KEY: node-deps | |
MONGODB_DB_NAME: gha-demo | |
jobs: | |
test: | |
environment: testing | |
runs-on: ubuntu-latest | |
container: | |
image: node-16 | |
env: | |
MONGODB_CONNECTION_PROTOCOL: mongodb+srv | |
MONGODB_CLUSTER_ADDRESS: cluster0.rx6a7h7.mongodb.net | |
MONGODB_USERNAME: ${{ secrets.MONGODB_USERNAME }} | |
MONGODB_PASSWORD: ${{ secrets.MONGODB_PASSWORD }} | |
PORT: 8080 | |
steps: | |
- name: Get Code | |
uses: actions/checkout@v3 | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.npm | |
key: ${{ env.CACHE_KEY }}-${{ hashFiles('**/package-lock.json') }} | |
- name: Install dependencies | |
run: npm ci | |
- name: Run server | |
run: npm start & npx wait-on http://127.0.0.1:$PORT # requires MongoDB Atlas to accept requests from anywhere! | |
- name: Run tests | |
run: npm test | |
- name: Output information | |
run: | | |
echo "MONGODB_USERNAME: $MONGODB_USERNAME" | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Output information | |
env: | |
PORT: 3000 | |
run: | | |
echo "MONGODB_DB_NAME: $MONGODB_DB_NAME" | |
echo "MONGODB_USERNAME: $MONGODB_USERNAME" | |
echo "${{ env.PORT }}" |