-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (71 loc) · 2.39 KB
/
action-package-workflow.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
name: Run NodeJS CI/CD process
on:
workflow_dispatch:
inputs:
test-nodejs:
description: "Do you want to run NodeJS test? (yes/no)"
required: true
default: 'yes'
permissions:
packages: write
env:
DOCKER_IMAGE_NAME: my-custom-nodeapp
DOCKER_IMAGE_VERSION: ${{ github.sha }}
IMAGE_REGISTRY_URL: ghcr.io
ORGANIZATION_NAME: githubschool
defaults:
run:
working-directory: nodejs
jobs:
NodeJS-Test:
runs-on: ubuntu-latest
name: Run NodeJS Test
if: ${{ github.event.inputs.test-nodejs == 'yes' }}
steps:
- name: Checkout files
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install NPM dependencies
run: npm install
- name: Run npm test
run: npm test
- name: Upload the test result in JSON to Artifact
uses: actions/upload-artifact@main
with:
name: Test Result
path: ${{ github.workspace }}/nodejs/output.txt
- name: Upload the test coverage result to Artifact
uses: actions/upload-artifact@main
with:
name: Test Coverage Result
path: ${{ github.workspace }}/nodejs/coverage
- name: Save NPM output
id: id-npm-test
# run: echo "::set-output name=result-node::$(cat output.txt)"
run: echo "::set-output name=result-node::$(cat output.txt | jq '.numFailedTests')"
- name: Print the output from last
run: echo ${{ steps.id-npm-test.outputs.result-node }}
Build-Image:
needs: NodeJS-Test
runs-on: ubuntu-latest
name: Build image
if: ${{ needs.NodeJS-Test.steps.id-npm-test.outputs.result-node == 0 }}
steps:
- name: Checkout files
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CUSTOM_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: nodejs
push: true
tags: ghcr.io/${{ env.ORGANIZATION_NAME }}/nodejs/${{ env.DOCKER_IMAGE_NAME }}:${{ env.DOCKER_IMAGE_VERSION }}