-
Notifications
You must be signed in to change notification settings - Fork 2
126 lines (107 loc) · 4.66 KB
/
push-service.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
name: push-services
on:
push:
branches:
- main
paths:
- "services/**"
env:
SERVICE_TYPE: fe
jobs:
get-versioning:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
runs-on: ubuntu-latest
outputs:
type: ${{ steps.versioning.outputs.type }}
steps:
- name: Check Out The Repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GHP_TOKEN }}
- name: Get Prefix By Commit
id: get_commit_prefix
run: echo $(echo "${{ github.event.head_commit.message }}" | cut -d ":" -f 1 | cut -d "(" -f 1 | cut -d " " -f 1)
- name: Parse xquare-versioning.json
id: parse_xquare_versioning
run: |
content=`cat ./xquare-versioning.json`
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=xquareVersioning::$content"
- name: Get Do Versioning
id: versioning
run: |
echo "::set-output name=type::${{ fromJson(steps.parse_xquare_versioning.outputs.xquareVersioning).commit.fix }}"
get-diff-workspace:
needs: get-versioning
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Check Out The Repository
uses: actions/checkout@v3
with:
fetch-depth: '2'
token: ${{ secrets.GHP_TOKEN }}
- name: diff-workspace
id: set-matrix
run: echo "::set-output name=matrix::{\"workspaces\":[$(yarn changed list --git-range $(git rev-parse HEAD^) --json --exclude xquare-frontend --exclude @shared/xbridge | tr "\n" ",")]}"
build:
name: Build
needs: [get-diff-workspace, get-versioning]
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.get-diff-workspace.outputs.matrix) }}
steps:
- name: Login to ECR
id: ecr
uses: elgohr/ecr-login-action@master
with:
access_key: ${{ secrets.AWS_ACCESS_KEY }}
secret_access_key: ${{ secrets.AWS_SECRET_KEY }}
region: ${{ secrets.AWS_REGION }}
- name: Login to Docker
run: docker login -u ${{ steps.ecr.outputs.username }} -p ${{ steps.ecr.outputs.password }} https://${{ secrets.AWS_SPECIFIC_URI }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com
- name: Check Out The Repository
uses: actions/checkout@v3
with:
token: ${{ secrets.GHP_TOKEN }}
- name: Get Service
id: get_service
run: echo ::set-output name=SERVICE::$(echo ${{ matrix.workspaces.name }} | cut -d / -f 2)
- name: Sync Package Version
run: yarn workspace @service/${{ steps.get_service.outputs.SERVICE }} version ${{ needs.get-versioning.outputs.type }}
- name: Get Package Version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
with:
path: ${{ matrix.workspaces.location }}
- name: Docker Build
run: yarn docker build @service/${{steps.get_service.outputs.SERVICE}} -t ${{ secrets.AWS_SPECIFIC_URI }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{steps.get_service.outputs.SERVICE}}-${{env.SERVICE_TYPE}}:${{ steps.package-version.outputs.current-version}}
- name: Docker Push
run: docker push ${{ secrets.AWS_SPECIFIC_URI }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/${{steps.get_service.outputs.SERVICE}}-${{env.SERVICE_TYPE}}:${{ steps.package-version.outputs.current-version}}
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.GITOPS_DEPLOY_STAGE_TOKEN }}
repository: team-xquare/xquare-gitops-repo-production
event-type: update_image
client-payload: '{
"ref": "${{ github.ref }}",
"version": "${{ steps.package-version.outputs.current-version}}",
"service_name": "${{steps.get_service.outputs.SERVICE}}",
"service_type": "${{ env.SERVICE_TYPE }}"
}'
- name: Pull Commit
run: git pull
- name: Commit With Versioning
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "release(${{steps.get_service.outputs.SERVICE}}): ${{ steps.package-version.outputs.current-version }} [skip ci]"
branch: main
commit_options: '--no-verify --signoff'
repository: .
commit_user_name: XQUARE Frontend Bot
commit_user_email: [email protected]
commit_author: XQUARE Frontend Bot <[email protected]>