generated from unsegnor/new-app
-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (60 loc) · 1.99 KB
/
main.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
name: "Test and publish"
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
name: "Test and publish"
runs-on: ubuntu-latest
permissions:
contents: write
steps:
#Prepare node environment
- name: "Checkout source code"
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Read Node.js version from .nvmrc
id: read_nvmrc
run: |
echo "::set-output name=node_version::$(cat .nvmrc)"
- name: "Setup Node.js"
uses: actions/setup-node@v4
with:
node-version: ${{ steps.read_nvmrc.outputs.node_version }}
registry-url: 'https://registry.npmjs.org'
- name: Install Compose
uses: ndeloof/[email protected]
with:
legacy: true # will also install in PATH as `docker-compose`
- name: Check docker-compose is installed
run: docker-compose -v
#Run tests
- run: npm ci
- run: npm test
#Increase version in main branch
- name: "Automated Version Bump"
if: github.ref == 'refs/heads/master'
id: version-bump
uses: "phips28/gh-action-bump-version@master"
with:
tag-prefix: ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#Publish to npm in main branch
- run: npm publish
if: github.ref == 'refs/heads/master'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Login to Docker Hub
if: github.ref == 'refs/heads/master'
run: |
DOCKERHUB_USERNAME=$(node -p "require('./package.json').dockerHubUsername")
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- name: Build and push Docker images
if: github.ref == 'refs/heads/master'
run: |
./publish-on-docker-hub.sh "http-api"
./publish-on-docker-hub.sh "lambda-function"