-
Notifications
You must be signed in to change notification settings - Fork 4
160 lines (137 loc) · 4.86 KB
/
pr_deploy.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Build and deploy devnet
on:
pull_request_target:
branches:
- master
jobs:
backend_build_and_deploy:
if: |
( startsWith(github.head_ref, 'feature') ||
startsWith(github.head_ref, 'fix') )
name: Test and deploy on backend PR
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@master
- name: check out trigger branch
run: |
git fetch origin $BRANCH
git checkout $BRANCH
env:
BRANCH: ${{ github.head_ref }}
- uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install dependencies
run: cd backend && npm install
- name: Record branch env
id: branch
run: |
echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# echo $repo
# echo $branch
# echo $commit
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- name: Determine Docker Image Name
id: image
run: |
echo "name=xinfinorg/subnet-stats-service:${{ steps.branch.outputs.branch }}" >> $GITHUB_OUTPUT
- name: Docker build and tag image
run: cd backend && docker build . --file Dockerfile --tag ${{ steps.image.outputs.name }}
- name: Docker push
run: docker push ${{ steps.image.outputs.name }}
frontend_build_and_deploy:
if: |
( startsWith(github.head_ref, 'feature') ||
startsWith(github.head_ref, 'fix') )
name: Test and deploy on frontend PR
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- name: check out code
uses: actions/checkout@master
- name: check out trigger branch
run: |
git fetch origin $BRANCH
git checkout $BRANCH
env:
BRANCH: ${{ github.head_ref }}
- uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Record branch env
id: branch
run: |
echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
# echo $repo
# echo $branch
# echo $commit
- name: Docker login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
DOCKER_PASSWORD: ${{secrets.DOCKER_ACCESS_TOKEN}}
run: |
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- name: Determine Docker Image Name
id: image
run: |
echo "name=xinfinorg/subnet-frontend:${{ steps.branch.outputs.branch }}" >> $GITHUB_OUTPUT
- name: Docker build and tag image
run: docker build . --file Dockerfile --tag ${{ steps.image.outputs.name }}
- name: Test run docker
run: docker run --entrypoint /bin/sh ${{ steps.image.outputs.name }} -c 'yarn run build && yarn global add serve'
- name: Docker push
run: docker push ${{ steps.image.outputs.name }}
trigger_deploy_workflow:
name: Trigger deployment workflow
needs: [frontend_build_and_deploy, backend_build_and_deploy]
runs-on: ubuntu-latest
steps:
- name: check out code
uses: actions/checkout@master
- name: check out trigger branch
run: |
git fetch origin $BRANCH
git checkout $BRANCH
env:
BRANCH: ${{ github.head_ref }}
- name: Record branch env
id: branch
run: |
echo "repo=${{ github.repository }}" >> $GITHUB_OUTPUT
echo "branch=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: trigger deploy workflow
id: trigger_deploy
run: |
echo "RESPONSE_CODE=$( \
curl -L \
-o response.txt \
-w %{response_code} \
-s \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.CICD_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/hash-laboratories-au/subnet-deployment/actions/workflows/subnet-deploy.yaml/dispatches \
-d '{"ref":"master", "inputs":{"caller_repo": "${{ steps.branch.outputs.repo }}", "caller_ref": "${{ steps.branch.outputs.branch }}", "caller_sha": "${{ steps.branch.outputs.commit }}"}}' \
)" >> $GITHUB_ENV
- name: Check response fail or success
run: |
cat response.txt
echo "RESPONSE_CODE=${{ env.RESPONSE_CODE }}"
if [ ${{ env.RESPONSE_CODE }} != 204 ]
then
exit 1
fi