-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (142 loc) · 4.78 KB
/
release.yaml
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
161
162
163
164
165
166
167
168
169
170
171
name: Release
on:
push:
branches:
- master
workflow_dispatch:
inputs:
bump:
description: 'Bump rule'
required: false
default: prerelease
type: choice
options:
- major
- minor
- patch
- prerelease
- premajor
- preminor
- prepatch
version:
description: 'Release version (ommit to bump)'
required: false
env:
HYDRO_MONITORING_REPO: ${{ github.repository_owner }}/hydro-monitoring
IMAGE: shell-ui # name of the built image
REGISTRY: hydrosphere
defaults:
run:
shell: bash
jobs:
version:
name: 'Determine release version'
runs-on: ubuntu-20.04
outputs:
version: ${{ env.VERSION }}
steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Get the latest tag
id: get-latest-tag
uses: actions-ecosystem/action-get-latest-tag@v1
with:
semver_only: true
- uses: actions-ecosystem/action-bump-semver@v1
if: env.VERSION == '' && github.event_name == 'workflow_dispatch'
id: bump-semver
with:
current_version: ${{ steps.get-latest-tag.outputs.tag }}
level: ${{ github.event.inputs.bump }}
- name: Set VERSION variable for global release
if: env.VERSION == '' && github.event_name == 'workflow_dispatch'
run: echo VERSION=${{ steps.bump-semver.outputs.new_version }} >> $GITHUB_ENV
- name: Force set VERSION variable
if: github.event.inputs.version != '' && github.event_name == 'workflow_dispatch'
run: echo VERSION=${{ github.event.inputs.version }} >> $GITHUB_ENV
- name: Set VERSION variable for local release
if: github.event_name == 'push'
run: echo VERSION=${{ github.sha }} >> $GITHUB_ENV
build_push:
needs: version
name: 'Build and Push image to registry'
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE }}:${{ env.VERSION }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
update_image_version:
needs: [version, build_push]
if: github.event_name == 'push'
name: 'Update image version in hydro-monitoring repo'
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- uses: aurelien-baudet/[email protected]
with:
workflow: Local release
ref: main
token: ${{ secrets.HYDRO_SERVING_TOKEN }}
repo: ${{ env.HYDRO_MONITORING_REPO }}
inputs: '{"service_image_name":"${{ env.IMAGE }}", "registry_url":"${{ env.REGISTRY }}", "tag":"${{ env.VERSION }}"}'
release:
if: github.event_name == 'workflow_dispatch'
needs: [version, build_push]
name: 'Global release'
runs-on: ubuntu-20.04
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Push to repo
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
sudo chown -R "${USER:-$(id -un)}" .
git commit -m "Releasing ${{ env.IMAGE }}:${{ env.VERSION }}" -a --allow-empty
git push
- name: Reports
run: echo "::set-output name=tag-output::${{ env.VERSION }}"
- name: Create github release
uses: meeDamian/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.VERSION }}