-
Notifications
You must be signed in to change notification settings - Fork 53
126 lines (110 loc) · 4.5 KB
/
release_hosted.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: Embedbase hosted release
on:
push:
branches:
- main
- next
- rc
paths:
- "hosted/**"
workflow_run:
workflows: ["Embedbase core release"]
types:
- completed
workflow_dispatch:
env:
PROJECT_ID: embedbase
SERVICE: embedbase-hosted
jobs:
build:
runs-on: ubuntu-latest
# or workflow dispatch
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions-ecosystem/action-regex-match@v2
id: regex-match
with:
text: ${{ github.event.head_commit.message }}
# match "Release core <some version>" but also "Release hosted <some version>"
regex: "Release (core|hosted) ([^ ]+)"
- name: Install deps
run: |
python -m pip install --upgrade pip
python -m pip install virtualenv
make install
working-directory: hosted
- name: Bump version if necessary
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
run: |
env/bin/python3 bump.py bump
working-directory: hosted
- name: Get the version
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
id: get_version
run: echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV
working-directory: hosted
- name: Bump service version if necessary
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
run: |
sed -i 's/gcr.io\/embedbase\/embedbase-hosted:.*$/gcr.io\/embedbase\/embedbase-hosted:${{ env.VERSION }}/g' service.prod.yaml
working-directory: hosted
- name: Commit version bump
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add version.txt service.prod.yaml
git commit -m "chore(hosted): bump to ${{ env.VERSION }}"
git push
working-directory: hosted
# TODO: Add tests
- id: auth
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
uses: google-github-actions/auth@v0
with:
credentials_json: "${{ secrets.GCP_SA_KEY_PROD }}"
- name: Authorize Docker push
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
run: gcloud auth configure-docker
- name: Build and push
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
uses: docker/build-push-action@v2
with:
context: hosted
file: ./hosted/Dockerfile
platforms: linux/amd64
push: true
tags: |
gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:latest
gcr.io/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ env.VERSION }}
- name: Deploy to Cloud Run
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
id: deploy
uses: google-github-actions/deploy-cloudrun@v0
with:
metadata: hosted/service.prod.yaml
project_id: ${{ env.PROJECT_ID }}
region: us-central1
tag: ${{ env.VERSION }}
- uses: rickstaa/action-create-tag@v1
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
id: "tag_create"
with:
tag: hosted-${{ env.VERSION }}
tag_exists_error: true
message: ${{ github.event.head_commit.message }}
- name: Create Release
if: steps.regex-match.outputs.match != '' || github.event.workflow_run || github.event_name == 'workflow_dispatch'
uses: softprops/action-gh-release@v1
with:
tag_name: hosted-${{ env.VERSION }}
name: hosted-${{ env.VERSION }}
draft: false
prerelease: false
# TODO: iterate on this changelog thing later
body: ${{ github.event.head_commit.message }}