-
Notifications
You must be signed in to change notification settings - Fork 8
111 lines (100 loc) · 3.36 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
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
107
108
109
110
111
name: Main CI/CD
on:
pull_request:
branches: ['main']
types: ['closed']
permissions:
contents: read
jobs:
check-branch:
if: contains(github.head_ref, 'release')
runs-on: ubuntu-latest
steps:
- name: Check branch
run: |
echo "This is a release branch"
check-merged:
needs: check-branch
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Check merged
run: |
echo "This is a merged release branch"
extract-version:
needs: check-merged
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Extract version
id: extract-version
run: |
echo "version=$(echo "$(git show -s --format=%s)" | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')" >> "$GITHUB_OUTPUT"
CI:
name: Main Server CI Check
needs: extract-version
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16
- name: Check version
run: |
echo "This release version: ${{ needs.extract-version.outputs.version }}"
- name: Install dependencies
run: npm install
- name: Prettier
run: npm run format
- name: Lint
run: npm run lint
- name: Build Test
run: npm run build
CD:
name: Main Server CD Check
needs: [CI, extract-version]
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build and push Docker image
run: |
touch .env.production
echo "${{ secrets.MAIN_ENV }}" >> .env.production
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }}:${{ needs.extract-version.outputs.version }} .
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }}:${{ needs.extract-version.outputs.version }}
- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.MAIN_HOST }}
port: 4222
username: ${{ secrets.MAIN_USERNAME }}
password: ${{ secrets.MAIN_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }}:${{ needs.extract-version.outputs.version }}
docker stop ${{ secrets.MAIN_DOCKER_IMAGE }}
docker rm -f ${{ secrets.MAIN_DOCKER_IMAGE }}
docker run --name=${{ secrets.MAIN_DOCKER_IMAGE }} -d -p 3000:3000 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.MAIN_DOCKER_IMAGE }}:${{ needs.extract-version.outputs.version }}
docker container prune -f
docker image prune -f
create-release:
needs: [CD, extract-version]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: create release
uses: ncipollo/[email protected]
with:
tag: ${{ needs.extract-version.outputs.version }}
name: ${{ needs.extract-version.outputs.version }}