@@ -28,40 +28,43 @@ concurrency:
28
28
group : ${{ github.workflow }}-${{ github.ref }}
29
29
cancel-in-progress : true
30
30
31
- # Set Workflow-level environment variables
32
- env :
33
- PROJECT : demoapp-frontend
34
-
35
31
jobs :
36
- build :
32
+ unit-test :
37
33
# Run job when not triggered by a merge
38
34
if : (github.event_name == 'push' && contains(toJSON(github.event.head_commit.message), 'Merge pull request ') == false) || (github.event_name != 'push')
39
35
runs-on : ubuntu-latest
36
+ steps :
37
+ - name : Checkout repository
38
+ uses : actions/checkout@v4 # https://github.com/marketplace/actions/checkout
39
+
40
+ # Cache NPM dependencies
41
+ - name : Cache NPM dependencies
42
+ id : cache
43
+ uses : actions/cache@v3 # https://github.com/marketplace/actions/cache#using-a-combination-of-restore-and-save-actions
44
+ with :
45
+ path : |
46
+ node_modules
47
+ key : npm-${{ hashFiles('package-lock.json') }}
48
+
49
+ # Install NPM dependencies
50
+ - name : Install NPM dependencies
51
+ run : npm ci
52
+
53
+ - name : Run tests
54
+ run : npm run test
55
+
56
+ build :
57
+ needs : unit-test
58
+ runs-on : ubuntu-latest
40
59
environment : docker-hub # Use `docker-hub` repository environment
41
- # Uncomment lines below to run `build` job on container
42
- # Note: container image must contains commands required for step execution, e.g. docker, gzip, etc.
43
- # container:
44
- # image: mcr.microsoft.com/openjdk/jdk:17-ubuntu # Image Java version must match with `project.version` in pom.xml
45
- # # Set credentials when container registry requires authentication to pull the image
46
- # # credentials:
47
- # # username: ${{ github.actor }}
48
- # # password: ${{ secrets.github_token }}
49
60
steps :
50
- # Workaround for the absence of github.branch_name
51
- # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
52
- - name : Set VERSION
53
- if : github.head_ref != ''
54
- run : |
55
- echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
56
- - name : Set VERSION
57
- if : github.head_ref == ''
58
- run : |
59
- echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
61
+ # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
62
+ - uses : FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
60
63
61
64
# Set Complete Container Image URL
62
65
- name : Set CONTAINER_IMAGE_URL
63
66
run : |
64
- echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
67
+ echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
65
68
66
69
- name : Checkout repository
67
70
uses : actions/checkout@v4 # https://github.com/marketplace/actions/checkout
@@ -91,21 +94,13 @@ jobs:
91
94
runs-on : ubuntu-latest
92
95
environment : docker-hub # Use `docker-hub` repository environment
93
96
steps :
94
- # Workaround for the absence of github.branch_name
95
- # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
96
- - name : Set VERSION
97
- if : github.head_ref != ''
98
- run : |
99
- echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
100
- - name : Set VERSION
101
- if : github.head_ref == ''
102
- run : |
103
- echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
97
+ # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
98
+ - uses : FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
104
99
105
100
# Set Complete Container Image URL
106
101
- name : Set CONTAINER_IMAGE_URL
107
102
run : |
108
- echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
103
+ echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
109
104
110
105
- name : Login to DockerHub
111
106
uses : docker/login-action@v3 # https://github.com/marketplace/actions/docker-login
@@ -137,21 +132,13 @@ jobs:
137
132
env :
138
133
TRIVY_CACHE_DIR : /tmp/trivy/
139
134
steps :
140
- # Workaround for the absence of github.branch_name
141
- # Setting an environment variable: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
142
- - name : Set VERSION
143
- if : github.head_ref != ''
144
- run : |
145
- echo "VERSION=${{ github.head_ref }}" >> $GITHUB_ENV
146
- - name : Set VERSION
147
- if : github.head_ref == ''
148
- run : |
149
- echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
135
+ # Workaround for the absence of github.branch_name, use github-env-vars-action to define useful environment variables not available by default
136
+ - uses : FranzDiebold/github-env-vars-action@v2 # https://github.com/marketplace/actions/github-environment-variables-action
150
137
151
138
# Set Complete Container Image URL
152
139
- name : Set CONTAINER_IMAGE_URL
153
140
run : |
154
- echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.PROJECT }}:${{ env.VERSION }}" >> $GITHUB_ENV
141
+ echo "CONTAINER_IMAGE_URL=${{ vars.DOCKER_REGISTRY_URL }}/${{ vars.DOCKER_REPOSITORY }}/${{ env.CI_REPOSITORY_NAME }}:${{ env.CI_ACTION_REF_NAME }}" >> $GITHUB_ENV
155
142
156
143
- name : Checkout repository
157
144
uses : actions/checkout@v4 # https://github.com/marketplace/actions/checkout
0 commit comments