Skip to content

Commit a9df733

Browse files
author
jiyungSong
committed
etc: add github action
1 parent abbd2bf commit a9df733

4 files changed

Lines changed: 354 additions & 0 deletions

File tree

.github/workflows/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Naming rule
2+
```
3+
[EVENT] CONTENT
4+
```
5+
6+
## Versionning
7+
- format
8+
```
9+
{major}.{minor}.{patch}.{current_date}
10+
```
11+
- scenario
12+
```
13+
1.2.3 -> 1.2.3.xxxx -> 1.2.3.yyyy -> 1.2.4
14+
```
15+
16+
17+
## Workflows
18+
> By default, [Push] includes a manual trigger (dispatch).
19+
20+
- `[Push] Build dev`
21+
- EVENT
22+
- When code is pushed to master
23+
- (triggered by `[Push] Sync CI`)
24+
- When the workflow is manually triggered
25+
- CONTENT
26+
- Build code and push docker image to pyengine
27+
- `[Dispatch] Release`
28+
- EVENT
29+
- When the workflow is manually triggered
30+
- CONTENT
31+
- Build code and push docker image to pyengine and spaceone
32+
- `[Push] Sync CI`
33+
- EVENT
34+
- When code is pushed to master
35+
- (trigger `[Push] Build dev`)
36+
- When the workflow is manually triggered
37+
- CONTENT
38+
- [Push]
39+
- Get workflows from actions and Trigger `[Push] Build dev`
40+
- [Dispatch]
41+
- Just get workflows from actions
42+
43+
- `[PR] Review (TODO)`
44+
45+
## Scenario
46+
- Release:
47+
- Manually trigger `[Dispatch] Release`
48+
- Build Dev (Push):
49+
- Commit code to master branch(`[Push] Sync CI` -> `[Push] Build dev`)
50+
- Build Dev (Dispatch):
51+
- Manually trigger `[Push] Build dev`
52+
- Update workflows:
53+
- Manually trigger `[Push] Sync CI`
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: "[Dispatch] Release"
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: '`vx.y.z` 형태로 버전을 입력해주세요.'
8+
required: true
9+
default: v1.0.0
10+
11+
env:
12+
TAG: ${{ github.event.inputs.tag }}
13+
SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
14+
15+
jobs:
16+
owner_check:
17+
if: github.repository_owner == 'cloudforet-io'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- run: echo ${{ github.repository_owner }}
21+
condition_check:
22+
if: github.repository_owner == 'cloudforet-io'
23+
runs-on: ubuntu-latest
24+
needs: owner_check
25+
steps:
26+
- name: check version format
27+
run: |
28+
if [[ !(${{ env.TAG }} =~ ^v[0-9]\.[0-9]?[0-9]\.[0-9]?[0-9]$) ]];
29+
then
30+
echo "You entered an incorrect version format."
31+
exit 1
32+
fi
33+
- name: debugging
34+
run: |
35+
echo "major=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f1)"
36+
echo "minor=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f2)"
37+
echo "patch=$(echo ${{env.TAG}} | cut -c 2- | cut -d'.' -f3)"
38+
- name: notice when job fails
39+
if: failure()
40+
uses: 8398a7/action-slack@v3.2.0
41+
with:
42+
status: ${{job.status}}
43+
fields: repo,workflow,job
44+
author_name: Github Action Slack
45+
46+
update_master_branch_version_file:
47+
needs: condition_check
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v2
51+
with:
52+
token: ${{ secrets.PAT_TOKEN }}
53+
- name: get versions
54+
run: |
55+
echo "old_version=$(cat src/VERSION)" >> $GITHUB_ENV
56+
echo "old_major=$(cat src/VERSION | cut -c 2- | cut -d'.' -f1)" >> $GITHUB_ENV
57+
echo "old_minor=$(cat src/VERSION | cut -c 2- | cut -d'.' -f2)" >> $GITHUB_ENV
58+
echo "old_patch=$(cat src/VERSION | cut -c 2- | cut -d'.' -f3)" >> $GITHUB_ENV
59+
echo "new_major=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f1)" >> $GITHUB_ENV
60+
echo "new_minor=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f2)" >> $GITHUB_ENV
61+
echo "new_patch=$(echo ${{ env.TAG }} | cut -c 2- | cut -d'.' -f3)" >> $GITHUB_ENV
62+
- name: compare versions
63+
run: |
64+
if [ ${{ env.TAG }} -eq ${{ env.old_version }} ];
65+
then
66+
echo "New version cannot be the same as old version."
67+
exit 1
68+
elif [ ${{ env.old_major }} -gt ${{ env.new_major }} ];
69+
then
70+
echo "Old major version cannot be greater than new major version"
71+
exit 1
72+
elif [ ${{ env.old_minor }} -gt ${{ env.new_minor }} ];
73+
then
74+
echo "Old minor version cannot be greater than new minor version"
75+
exit 1
76+
elif [ ${{ env.old_minor }} -eq ${{ env.new_minor }} ];
77+
then
78+
if [ ${{ env.old_patch }} -ge ${{ env.new_patch }} ];
79+
then
80+
echo "Old patch version cannot be greater than new patch version in same minor version"
81+
exit 1
82+
else
83+
echo "version=${{ env.TAG }}"
84+
fi
85+
else
86+
echo "version=${{ env.TAG }}"
87+
fi
88+
- name: update version file
89+
run: |
90+
echo ${{ env.TAG }} > src/VERSION
91+
git config user.name github-actions
92+
git config user.email github-actions@github.com
93+
git add .
94+
git commit -m "[CI/CD] release version ${{ env.TAG }}"
95+
- name: push changes
96+
uses: ad-m/github-push-action@master
97+
with:
98+
github_token: ${{ secrets.PAT_TOKEN }}
99+
branch: master
100+
- name: notice when job fails
101+
if: failure()
102+
uses: 8398a7/action-slack@v3.2.0
103+
with:
104+
status: ${{job.status}}
105+
fields: repo,workflow,job
106+
author_name: Github Action Slack
107+
108+
tagging:
109+
needs: update_master_branch_version_file
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: actions/checkout@v2
113+
with:
114+
token: ${{ secrets.PAT_TOKEN }}
115+
- name: git tagging
116+
run: |
117+
git tag ${{ env.TAG }}
118+
git push origin "${{ env.TAG }}"
119+
- name: notice when job fails
120+
if: failure()
121+
uses: 8398a7/action-slack@v3.2.0
122+
with:
123+
status: ${{job.status}}
124+
fields: repo,workflow,job
125+
author_name: Github Action Slack
126+
127+
docker:
128+
needs: tagging
129+
runs-on: ubuntu-latest
130+
steps:
131+
- uses: actions/checkout@v2
132+
- name: get version
133+
run: |
134+
echo "VERSION=$(echo ${{ env.TAG }} | cut -c 2-)" >> $GITHUB_ENV
135+
- name: get service name
136+
run: |
137+
echo "SERVICE=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV
138+
- name: Build and push to pyengine
139+
uses: docker/build-push-action@v1
140+
with:
141+
path: .
142+
repository: pyengine/${{ env.SERVICE }}
143+
username: ${{ secrets.DOCKER_USERNAME }}
144+
password: ${{ secrets.DOCKER_PASSWORD }}
145+
tags: ${{ env.VERSION }}
146+
- name: Build and push to spaceone
147+
uses: docker/build-push-action@v1
148+
with:
149+
path: .
150+
repository: spaceone/${{ env.SERVICE }}
151+
username: ${{ secrets.DOCKER_USERNAME }}
152+
password: ${{ secrets.DOCKER_PASSWORD }}
153+
tags: ${{ env.VERSION }}
154+
- name: Notice when job fails
155+
if: failure()
156+
uses: 8398a7/action-slack@v3.2.0
157+
with:
158+
status: ${{job.status}}
159+
fields: repo,workflow,job
160+
author_name: Github Action Slack
161+
162+
notification:
163+
needs: docker
164+
runs-on: ubuntu-latest
165+
steps:
166+
- name: Slack
167+
if: always()
168+
uses: 8398a7/action-slack@v3.2.0
169+
with:
170+
status: ${{job.status}}
171+
fields: repo,message,commit,author,action,ref,workflow,job
172+
author_name: Github Action Slack
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "[Push] Build dev"
2+
3+
on:
4+
workflow_dispatch:
5+
repository_dispatch:
6+
types: [master_push]
7+
8+
env:
9+
SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
10+
11+
jobs:
12+
versioning:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
version: ${{ steps.versioning.outputs.VERSION }}
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: get current date
19+
run: |
20+
sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
21+
echo "TIME=$(date +'%Y%m%d.%H%M%S')" >> $GITHUB_ENV
22+
- name: set version with current date
23+
id: versioning
24+
run: |
25+
echo "::set-output name=VERSION::$(cat src/VERSION | cut -c 2-).${{ env.TIME }}"
26+
- name: Notice when job fails
27+
if: failure()
28+
uses: 8398a7/action-slack@v3.2.0
29+
with:
30+
status: ${{job.status}}
31+
fields: repo,workflow,job
32+
author_name: Github Action Slack
33+
34+
docker:
35+
if: github.repository_owner == 'cloudforet-io'
36+
needs: versioning
37+
runs-on: ubuntu-latest
38+
env:
39+
VERSION: ${{ needs.versioning.outputs.version }}
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: get service name
43+
run: |
44+
echo "SERVICE=$(echo ${{ github.repository }} | cut -d '/' -f2)" >> $GITHUB_ENV
45+
- name: Upload docker
46+
uses: docker/build-push-action@v1
47+
with:
48+
path: .
49+
repository: pyengine/${{ env.SERVICE }}
50+
username: ${{ secrets.DOCKER_USERNAME }}
51+
password: ${{ secrets.DOCKER_PASSWORD }}
52+
tags: ${{ env.VERSION }}
53+
- name: Notice when job fails
54+
if: failure()
55+
uses: 8398a7/action-slack@v3.2.0
56+
with:
57+
status: ${{job.status}}
58+
fields: repo,workflow,job
59+
author_name: Github Action Slack
60+
61+
notification:
62+
runs-on: ubuntu-latest
63+
needs: docker
64+
steps:
65+
- name: Slack
66+
if: always()
67+
uses: 8398a7/action-slack@v3.2.0
68+
with:
69+
status: ${{job.status}}
70+
fields: repo,message,commit,author,action,ref,workflow,job
71+
author_name: Github Action Slack
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: "[Push] Sync CI"
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '.github/**'
9+
- 'src/VERSION'
10+
- 'docs/**'
11+
workflow_dispatch:
12+
13+
env:
14+
workflow_file_name: deploy.yaml
15+
owner: cloudforet-io
16+
repo: actions
17+
ref: master
18+
19+
jobs:
20+
owner_check:
21+
if: github.repository_owner == 'cloudforet-io'
22+
runs-on: ubuntu-latest
23+
steps:
24+
- run: echo ${{ github.repository_owner }}
25+
master_push:
26+
if: github.event_name == 'push'
27+
runs-on: ubuntu-latest
28+
needs: owner_check
29+
steps:
30+
- name: git pull
31+
uses: convictional/trigger-workflow-and-wait@v1.3.0
32+
with:
33+
owner: ${{ env.owner }}
34+
repo: ${{ env.repo }}
35+
github_token: ${{ secrets.PAT_TOKEN }}
36+
workflow_file_name: ${{ env.workflow_file_name }}
37+
ref: ${{ env.ref }}
38+
wait_interval: 10
39+
inputs: '{"repository" : "${{ github.repository }}"}'
40+
trigger_workflow: true
41+
wait_workflow: true
42+
pull_workflows:
43+
if: github.event_name == 'workflow_dispatch'
44+
runs-on: ubuntu-latest
45+
needs: owner_check
46+
steps:
47+
- name: git pull
48+
uses: convictional/trigger-workflow-and-wait@v1.3.0
49+
with:
50+
owner: ${{ env.owner }}
51+
repo: ${{ env.repo }}
52+
github_token: ${{ secrets.PAT_TOKEN }}
53+
workflow_file_name: ${{ env.workflow_file_name }}
54+
ref: ${{ env.ref }}
55+
wait_interval: 10
56+
inputs: '{"repository" : "${{ github.repository }}" , "sync_only" : "true"}'
57+
trigger_workflow: true
58+
wait_workflow: true

0 commit comments

Comments
 (0)