-
Notifications
You must be signed in to change notification settings - Fork 22
85 lines (79 loc) · 2.42 KB
/
web.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
name: Web
on:
workflow_call:
jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get Node version
run: echo "BUILD_NODE_VER=$(grep -o -P -m 1 '(?<=node":\s").*(?=")' package.json)" >> $GITHUB_ENV
- name: Node setup
uses: actions/setup-node@v3
with:
node-version: ${{ env.BUILD_NODE_VER }}
- name: Attach SHA to build
if: github.ref_name == 'develop'
run: |
BUILD_VERSION=$(grep -o -P -m 1 '(?<=version":\s").*(?=")' package.json)
sed -i "s/$BUILD_VERSION/$BUILD_VERSION-${GITHUB_SHA::7}/g" package.json
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
restore-keys: npm-
- name: Install dependencies
run: npm ci
- name: Build
run: |
if [[ "${{ github.ref_name }}" == "master" ]]; then
npm run build-prod-web
elif [[ "${{ github.ref_name }}" == "develop" ]]; then
npm run build-dev-web
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: ./dist
if-no-files-found: error
retention-days: 3
deploy-dev:
if: github.ref_name == 'develop'
runs-on: [self-hosted, dev]
needs: build
env:
APACHE_DIR: /var/www/html
BACKUP_DIR: /opt/actions-runner/backups
steps:
- name: Get artifact
uses: actions/download-artifact@v4
with:
name: dist
- name: Deploy
run: |
tar -czf $BACKUP_DIR/measur_$(printf '%(%Y-%m-%d)T\n' -1)_${GITHUB_SHA::7}.tar.gz $APACHE_DIR/measur
rm -rf $APACHE_DIR/measur/*
chgrp -R apache ./
mv -v ./* $APACHE_DIR/measur/
deploy-prod:
if: github.ref_name == 'master'
runs-on: [self-hosted, prod]
needs: build
env:
APACHE_DIR: /var/www/html
BACKUP_DIR: /opt/actions-runner/backups
steps:
- name: Get artifact
uses: actions/download-artifact@v4
with:
name: dist
- name: Deploy
run: |
tar -czf $BACKUP_DIR/measur_$(printf '%(%Y-%m-%d)T\n' -1)_${GITHUB_SHA::7}.tar.gz $APACHE_DIR/measur
rm -rf $APACHE_DIR/measur/*
chgrp -R apache ./
mv -v ./* $APACHE_DIR/measur/