Based on Distributed Systems with Node.js:
bit.ly/34SHToF
.github/workflows/*.yml
uses: actions/setup-node@v2.1.4
github.com/actions/setup-node
.github/workflows/pr-lint-test.yml
name: Linter and Acceptance Tests
on:
pull_request:
branches:
- main
workflow_dispatch: # Allow manual execution
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2.1.4
with:
node-version: 14.15.3
- name: Install Dependencies
run: npm install
- name: Run Linter
run: npm run lint
- name: Build and Start Docker Containers
run: docker-compose -f docker-compose.yml up -d
- name: Run Acceptance Tests
run: TARGET=http://localhost:1337 npm test
.github/workflows/main-deploy.yml
name: Deploy to Production
on:
push:
branches:
- main
workflow_dispatch: # Allow manual execution
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check Out Repo
uses: actions/checkout@v2
- name: Set up Docker Builder
uses: docker/setup-buildx-action@v1
- name: Build and Push to Container Registry
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: |
registry.foo.com/x/y:latest
registry.foo.com/x/y:sha-${{github.sha}}
deploy: # Job
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy app to VPS
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{secrets.SSH_HOST}}
username: ${{secrets.SSH_USER}}
key: ${{secrets.SSH_KEY}}
script: |
docker pull registry.foo.com/x/y:latest
docker stop my-app || true
docker rm my-app || true
docker run -d \
-e SOMEVAL=${{secrets.SOMEVAL}} \
--name my-app \
registry.foo.com/x/y:latest \
node /srv/app.js
action.yml
name: 'Hello World'
description: 'Greet someone and record the time'
inputs:
whom: # id of input
description: 'Who to greet'
required: false
default: 'World'
outputs:
time: # id of output
description: 'The time we greeted you'
runs:
using: 'node12'
main: 'index.js'
index.js
const core = require('@actions/core');
const github = require('@actions/github');
try {
const nameToGreet = core.getInput('whom');
console.log(`Hello ${nameToGreet}!`);
const time = new Date().toISOString();
core.setOutput('time', time);
void github.context.payload; // Useful Data
} catch (error) {
core.setFailed(error.message);
}
jobs:
hello_world:
steps:
- name: Hello World
uses: actions/hello-world-javascript-action
id: hello
with:
whom: 'Audience'
- name: Echo Outputs
run: echo ${{steps.hello.outputs.time}}