1
1
---
2
2
name : " CI"
3
3
on : # yamllint disable-line rule:truthy rule:comments
4
- - " push"
5
- - " pull_request"
6
-
7
- env :
8
- IMAGE_NAME : " jdiff"
4
+ push :
5
+ branches :
6
+ - " main"
7
+ - " develop"
8
+ tags :
9
+ - " v*"
10
+ pull_request : ~
9
11
10
12
jobs :
11
13
black :
41
43
uses : " networktocode/gh-action-setup-poetry-environment@v2"
42
44
- name : " Linting: bandit"
43
45
run : " poetry run invoke bandit"
44
- needs :
45
- - " black"
46
46
pydocstyle :
47
47
runs-on : " ubuntu-20.04"
48
48
env :
54
54
uses : " networktocode/gh-action-setup-poetry-environment@v2"
55
55
- name : " Linting: pydocstyle"
56
56
run : " poetry run invoke pydocstyle"
57
- needs :
58
- - " black"
59
57
flake8 :
60
58
runs-on : " ubuntu-20.04"
61
59
env :
67
65
uses : " networktocode/gh-action-setup-poetry-environment@v2"
68
66
- name : " Linting: flake8"
69
67
run : " poetry run invoke flake8"
70
- needs :
71
- - " black"
72
68
yamllint :
73
69
runs-on : " ubuntu-20.04"
74
70
env :
@@ -80,44 +76,14 @@ jobs:
80
76
uses : " networktocode/gh-action-setup-poetry-environment@v2"
81
77
- name : " Linting: yamllint"
82
78
run : " poetry run invoke yamllint"
83
- needs :
84
- - " black"
85
- build :
86
- strategy :
87
- fail-fast : true
88
- matrix :
89
- python-version : ["3.7", "3.8", "3.9", "3.10"]
90
- runs-on : " ubuntu-20.04"
91
- env :
92
- PYTHON_VER : " ${{ matrix.python-version }}"
93
- steps :
94
- - name : " Check out repository code"
95
- uses : " actions/checkout@v2"
96
- - name : " Setup environment"
97
- uses : " networktocode/gh-action-setup-poetry-environment@v2"
98
- - name : " Get image version"
99
- run : " echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
100
- - name : " Set up Docker Buildx"
101
- id : " buildx"
102
- uses : " docker/setup-buildx-action@v1"
103
- - name : " Build"
104
- uses : " docker/build-push-action@v2"
105
- with :
106
- builder : " ${{ steps.buildx.outputs.name }}"
107
- context : " ./"
108
- push : false
109
- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
110
- file : " ./Dockerfile"
111
- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
112
- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
113
- build-args : |
114
- PYTHON_VER=${{ env.PYTHON_VER }}
79
+ pylint :
115
80
needs :
116
81
- " bandit"
117
82
- " pydocstyle"
118
83
- " flake8"
119
84
- " yamllint"
120
- pylint :
85
+ - " black"
86
+ - " mypy"
121
87
runs-on : " ubuntu-20.04"
122
88
strategy :
123
89
fail-fast : true
@@ -131,31 +97,11 @@ jobs:
131
97
uses : " actions/checkout@v2"
132
98
- name : " Setup environment"
133
99
uses : " networktocode/gh-action-setup-poetry-environment@v2"
134
- - name : " Get image version"
135
- run : " echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
136
- - name : " Set up Docker Buildx"
137
- id : " buildx"
138
- uses : " docker/setup-buildx-action@v1"
139
- - name : " Load the image from cache"
140
- uses : " docker/build-push-action@v2"
141
- with :
142
- builder : " ${{ steps.buildx.outputs.name }}"
143
- context : " ./"
144
- push : false
145
- load : true
146
- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
147
- file : " ./Dockerfile"
148
- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
149
- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
150
- build-args : |
151
- PYTHON_VER=${{ env.PYTHON_VER }}
152
- - name : " Debug: Show docker images"
153
- run : " docker image ls"
154
100
- name : " Linting: Pylint"
155
101
run : " poetry run invoke pylint"
156
- needs :
157
- - " build"
158
102
pytest :
103
+ needs :
104
+ - " pylint"
159
105
strategy :
160
106
fail-fast : true
161
107
matrix :
@@ -169,31 +115,11 @@ jobs:
169
115
uses : " actions/checkout@v2"
170
116
- name : " Setup environment"
171
117
uses : " networktocode/gh-action-setup-poetry-environment@v2"
172
- - name : " Get image version"
173
- run : " echo IMAGE_VER=`poetry version -s`-py${{ matrix.python-version }} >> $GITHUB_ENV"
174
- - name : " Set up Docker Buildx"
175
- id : " buildx"
176
- uses : " docker/setup-buildx-action@v1"
177
- - name : " Load the image from cache"
178
- uses : " docker/build-push-action@v2"
179
- with :
180
- builder : " ${{ steps.buildx.outputs.name }}"
181
- context : " ./"
182
- push : false
183
- load : true
184
- tags : " ${{ env.IMAGE_NAME }}:${{ env.IMAGE_VER }}"
185
- file : " ./Dockerfile"
186
- cache-from : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
187
- cache-to : " type=gha,scope=${{ env.IMAGE_NAME }}-${{ env.IMAGE_VER }}-py${{ matrix.python-version }}"
188
- build-args : |
189
- PYTHON_VER=${{ env.PYTHON_VER }}
190
- - name : " Debug: Show docker images"
191
- run : " docker image ls"
192
118
- name : " Run Tests"
193
119
run : " poetry run invoke pytest"
194
- needs :
195
- - " pylint"
196
120
publish_gh :
121
+ needs :
122
+ - " pytest"
197
123
name : " Publish to GitHub"
198
124
runs-on : " ubuntu-20.04"
199
125
if : " startsWith(github.ref, 'refs/tags/v')"
@@ -220,9 +146,9 @@ jobs:
220
146
tag : " ${{ github.ref }}"
221
147
overwrite : true
222
148
file_glob : true
149
+ publish_pypi :
223
150
needs :
224
151
- " pytest"
225
- publish_pypi :
226
152
name : " Push Package to PyPI"
227
153
runs-on : " ubuntu-20.04"
228
154
if : " startsWith(github.ref, 'refs/tags/v')"
@@ -248,5 +174,39 @@ jobs:
248
174
password : " ${{ secrets.PYPI_API_TOKEN }}"
249
175
# Using PyPi dev.
250
176
repository_url : " https://test.pypi.org/legacy/"
177
+ slack-notify :
251
178
needs :
252
- - " pytest"
179
+ - " publish_gh"
180
+ - " publish_pypi"
181
+ name : " Send notification to the Slack"
182
+ runs-on : " ubuntu-20.04"
183
+ env :
184
+ SLACK_WEBHOOK_URL : " ${{ secrets.SLACK_WEBHOOK_URL }}"
185
+ SLACK_MESSAGE : >-
186
+ *NOTIFICATION: NEW-RELEASE-PUBLISHED*\n
187
+ Repository: <${{ github.server_url }}/${{ github.repository }}|${{ github.repository }}>\n
188
+ Release: <${{ github.server_url }}/${{ github.repository }}/releases/tag/${{ github.ref_name }}|${{ github.ref_name }}>\n
189
+ Published by: <${{ github.server_url }}/${{ github.actor }}|${{ github.actor }}>
190
+ steps :
191
+ - name : " Send a notification to Slack"
192
+ # ENVs cannot be used directly in job.if. This is a workaround to check
193
+ # if SLACK_WEBHOOK_URL is present.
194
+ if : " ${{ env.SLACK_WEBHOOK_URL != '' }}"
195
+ uses :
" slackapi/[email protected] "
196
+ with :
197
+ payload : |
198
+ {
199
+ "text": "${{ env.SLACK_MESSAGE }}",
200
+ "blocks": [
201
+ {
202
+ "type": "section",
203
+ "text": {
204
+ "type": "mrkdwn",
205
+ "text": "${{ env.SLACK_MESSAGE }}"
206
+ }
207
+ }
208
+ ]
209
+ }
210
+ env :
211
+ SLACK_WEBHOOK_URL : " ${{ secrets.SLACK_WEBHOOK_URL }}"
212
+ SLACK_WEBHOOK_TYPE : " INCOMING_WEBHOOK"
0 commit comments