-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
134 lines (104 loc) · 3.87 KB
/
action.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
name: Build Image for test
env:
# IMAGE_NAME 用于 程序名
REGISTRY: ghcr.io/${{ github.repository }}
IMAGE_NAME: hello
SECRETS_GITHUB_TOKEN: ${{ secrets.SECRETS_GITHUB_TOKEN }}
on:
push:
branches: [ master ]
release:
types: [ published ]
jobs:
GetSHA:
runs-on: ubuntu-latest
outputs:
IMAGE_SHA: ${{ steps.get_short_sha.outputs.SHORT_SHA}}
steps:
- name: Get Short SHA
id: get_short_sha
run: |
SHORT_SHA=$(echo ${GITHUB_SHA} | cut -c1-7)
echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "Short SHA: $SHORT_SHA"
Build:
runs-on: ubuntu-latest
needs: GetSHA
if: ${{ github.ref_type == 'branch' }}
env:
IMAGE_SHA: ${{ needs.GetSHA.outputs.IMAGE_SHA}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to GitHub Packages
run: echo "${SECRETS_GITHUB_TOKEN}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Build images
run: make build ARGS="${REGISTRY}/" IMAGE_TAG="${IMAGE_SHA}" IMAGE_NAME=${IMAGE_NAME}
- name: Push images to repository
run: make push ARGS="${REGISTRY}/" IMAGE_TAG="${IMAGE_SHA}" IMAGE_NAME=${IMAGE_NAME}
Deploy_test:
runs-on: ubuntu-latest
needs: [ GetSHA, Build ]
if: ${{ github.ref_type == 'branch' }}
env:
IMAGE_SHA: ${{ needs.GetSHA.outputs.IMAGE_SHA}}
steps:
- name: Deploy Test
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST_TEST }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY_TEST }}
port: 22
envs: GITHUB_ACTOR,SECRETS_GITHUB_TOKEN,IMAGE_NAME,IMAGE_SHA,REGISTRY
script: |
echo "$GITHUB_ACTOR $REGISTRY $IMAGE_SHA $IMAGE_NAME $SECRETS_GITHUB_TOKEN" > test.txt
echo "$SECRETS_GITHUB_TOKEN" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker stop $IMAGE_NAME
docker rm $IMAGE_NAME
docker run -d --name $IMAGE_NAME ${REGISTRY}/${IMAGE_NAME}:${IMAGE_SHA}
Deploy_Prod:
runs-on: ubuntu-latest
needs: GetSHA
if: ${{ github.ref_type == 'zzz' }}
env:
IMAGE_SHA: ${{ needs.GetSHA.outputs.IMAGE_SHA}}
steps:
- name: Get Tag Name
id: get_tag_name
run: |
IMAGE_TAG=$(echo $GITHUB_REF | awk -F '/' '{print $NF}')
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: docker login github repo and push
run: echo "${SECRETS_GITHUB_TOKEN}" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: build image to prod
run: |
docker pull ${REGISTRY}/${IMAGE_NAME}:${IMAGE_SHA}
docker tag ${REGISTRY}/${IMAGE_NAME}:${IMAGE_SHA} ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
docker push ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
- name: Deploy prod
uses: appleboy/[email protected]
with:
host: ${{ secrets.REMOTE_HOST_TEST }}
username: ubuntu
key: ${{ secrets.SSH_PRIVATE_KEY_TEST }}
port: 22
envs: GITHUB_ACTOR,SECRETS_GITHUB_TOKEN,IMAGE_NAME,IMAGE_TAG,REGISTRY
script: |
echo "$GITHUB_ACTOR $REGISTRY $IMAGE_TAG $IMAGE_NAME $SECRETS_GITHUB_TOKEN IMAGE_SHA" > test.txt
echo "$SECRETS_GITHUB_TOKEN" | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker stop $IMAGE_NAME
docker rm $IMAGE_NAME
docker run -d --name $IMAGE_NAME ghcr.io/${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
build_test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: true
- name: Update Submodule
run: |
git submodule update --remote --merge
- name: Run submodule workflow
uses: .github/workflow