-
Notifications
You must be signed in to change notification settings - Fork 2
201 lines (171 loc) · 5.88 KB
/
Copy pathrelease.yaml
File metadata and controls
201 lines (171 loc) · 5.88 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Release
on:
push:
branches:
- master
- main
workflow_dispatch:
inputs:
bump:
description: bump rule (major|minor|patch|premajor|preminor|prepatch|prerelease)
default: prerelease
required: false
version:
description: manual version
default: ''
required: false
sdk_version:
description: manual sdk version
default: ''
required: false
release:
description: release type (local|global)
default: local
required: false
# Secrets:
# pypi_token - pypi API token
jobs:
Verify_version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get latest tag
id: get-latest-tag
uses: actions-ecosystem/action-get-latest-tag@v1
outputs:
latest_version: ${{ steps.get-latest-tag.outputs.tag }}
Release:
needs: Verify_version
runs-on: ubuntu-latest
env:
BUMP: ${{ github.event.inputs.bump }} # default values for push-triggered run
RELEASE: local
VERSION: ${{ github.event.inputs.version }}
SDK_VERSION: ${{ github.event.inputs.sdk_version }}
if: >
needs.Verify_version.outputs.latest_version != github.event.inputs.version && (
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push')
steps:
- name: Validate inputs #TODO create an action for this
if: github.event_name == 'workflow_dispatch'
run: |
case ${{ github.event.inputs.bump }} in
major)
;;
premajor)
;;
minor)
;;
preminor)
;;
patch)
;;
prepatch)
;;
prerelease)
;;
*)
echo "invalid bump rule: ${{ github.event.inputs.bump }}"
exit 1
;;
esac
case ${{ github.event.inputs.release }} in
local)
;;
global)
;;
*)
echo invalid release type: ${{ github.event.inputs.release }}
exit 1
;;
esac
echo BUMP=${{ github.event.inputs.bump }} >> $GITHUB_ENV
echo RELEASE=${{ github.event.inputs.release }} >> $GITHUB_ENV
echo VERSION=${{ github.event.inputs.version }} >> $GITHUB_ENV
echo SDK_VERSION=${{ github.event.inputs.sdk_version }} >> $GITHUB_ENV
# Checkout and prerequisite tools
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2.2.2
with:
python-version: 3.7
- name: Setup poetry
uses: abatilo/actions-poetry@v2.1.0
# Bump version
- name: Bump sdk
if: env.SDK_VERSION == '' && env.RELEASE == 'local'
run: |
SDK_VERSION=$(curl -Ls https://pypi.org/pypi/hydrosdk/json | jq -r '.releases | keys[]' | sort -V | tail -n 1)
echo $SDK_VERSION
# poetry add hydrosdk=$SDK_VERSION
- name: Bump sdk to latest stable version
if: env.SDK_VERSION == '' && env.RELEASE == 'global'
run: |
SDK_VERSION=$(curl -Ls https://pypi.org/pypi/hydrosdk/json | jq -r .info.version)
echo $SDK_VERSION
poetry add hydrosdk=$SDK_VERSION
- name: Set manual sdk version
if: env.SDK_VERSION != ''
run: poetry add hydrosdk=${{ env.SDK_VERSION }}
# Bump version
- name: Bump service version
run: poetry version ${{ env.BUMP }}
- name: force bump version
if: env.VERSION != ''
run: poetry version ${{ env.VERSION }}
- name: Build
run: poetry build
- name: Release to pypi
run: poetry publish -u __token__ -p ${{ secrets.pypi_token }}
- name: Add version env
run: echo VERSION=$(poetry version -s) >> $GITHUB_ENV
- name: Commit new version
run: "echo ${{ env.VERSION }} > version"
- 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]"
git commit -m "Releasing hydro-serving-cli:${{ env.VERSION }}" -a
git push
- name: Reports
id: generate-output
run: echo "::set-output name=tag-output::${{ env.VERSION }}"
- name: Create github release
uses: meeDamian/github-release@2.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ env.VERSION }}
outputs:
tag: ${{ steps.generate-output.outputs.tag-output }}
slackNotification:
name: Slack Notification
needs: Release
runs-on: ubuntu-latest
steps:
- name: Slack Notification success
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: hydrosphere
SLACK_USERNAME: HydroRobot
SLACK_ICON: https://avatars.githubusercontent.com/u/17550625?s=200&v=4
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: Build status - success
SLACK_MESSAGE: "Releasing hydro-serving-cli ${{ needs.Release.outputs.tag }} :rocket:"
MSG_MINIMAL: true
- name: Slack Notification failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: hydrosphere
SLACK_USERNAME: HydroRobot
SLACK_ICON: https://avatars.githubusercontent.com/u/17550625?s=200&v=4
SLACK_COLOR: ${{ job.status }}
SLACK_TITLE: Build status - failure
SLACK_MESSAGE: "Check build $GITHUB_RUN_ID status"
MSG_MINIMAL: true