-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 3.89 KB
/
build.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: build
# The workflow will run when a tag matching the pattern 'v*.*.*' is pushed to the repository
on:
push:
tags:
- 'v*.*.*'
jobs:
build:
runs-on: ubuntu-latest #build job runs on the latest ubuntu version
steps:
- uses: actions/checkout@v3 #checkout the repositories's code
with:
fetch-depth: 0 #fetch the entire history of repository, including all commits and tags
node-version: 16
# Work around https://github.com/actions/checkout/issues/290, this will fetch all the tags in the repository
- run: git fetch --force --tags
#Sets up a Node.js environment on the runner
- uses: actions/setup-node@v3
with:
node-version: 16
#Caches dependencies to speed up future builds
- uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
#Install the project's Node.js dependencies
- run: npm install
- run: mkdir artifacts
- name: create tarball #create .tar.gz containing project files,excluding artifacts folder and .git
run: |
GIT_DESCRIBE=$(git describe)
sed -i -e "s/%GIT_DESCRIBE%/$(git describe)/g" ./public/index.html
tar -czf artifacts/imbportal-${GIT_DESCRIBE}.tar.gz \
--transform "s/^\./imbportal-${GIT_DESCRIBE}/" \
--exclude=./artifacts \
--exclude=./.git \
.
# uploads the tarball created in the previous step as an artifact, making it available for download in later steps or jobs
- uses: actions/upload-artifact@v3
with:
name: release-artifacts
path: artifacts/imbportal-*.tar.gz
# ---- This section is to create docker image and pushing to harbor---
# Sets up Docker Buildx, a tool that allows for advanced Docker image building, including multi-platform support
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
#caches doker layers to speed up future builds
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-cache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-cache-
#logs into harbor registry
- name: Log in to Harbor
uses: docker/login-action@v2
with:
registry: ${{ secrets.HARBOR_REGISTRY }}
username: ${{ secrets.HARBOR_USERNAME }}
password: ${{ secrets.HARBOR_PASSWORD }}
#Extracts the version number of the tag
- name: Extract tag
id: extract_tag
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
# Builds a docker image and pushes it to harbor
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ secrets.HARBOR_REGISTRY }}/rcc-portals-a/apps-ipp:${{env.TAG}}
# ---end creating docker image and pushing to harbor ---
# Deploy job depends on the build job, deploy job will only run if event is a push, the ref starts with refs/tags/, and the tag name is master
deploy:
needs: build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && github.ref_name == 'master'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: release-artifacts
path: dist
- uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*