11---
22name : " CI"
33on : # 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 : ~
911
1012jobs :
1113 black :
4143 uses : " networktocode/gh-action-setup-poetry-environment@v2"
4244 - name : " Linting: bandit"
4345 run : " poetry run invoke bandit"
44- needs :
45- - " black"
4646 pydocstyle :
4747 runs-on : " ubuntu-20.04"
4848 env :
5454 uses : " networktocode/gh-action-setup-poetry-environment@v2"
5555 - name : " Linting: pydocstyle"
5656 run : " poetry run invoke pydocstyle"
57- needs :
58- - " black"
5957 flake8 :
6058 runs-on : " ubuntu-20.04"
6159 env :
6765 uses : " networktocode/gh-action-setup-poetry-environment@v2"
6866 - name : " Linting: flake8"
6967 run : " poetry run invoke flake8"
70- needs :
71- - " black"
7268 yamllint :
7369 runs-on : " ubuntu-20.04"
7470 env :
@@ -80,44 +76,14 @@ jobs:
8076 uses : " networktocode/gh-action-setup-poetry-environment@v2"
8177 - name : " Linting: yamllint"
8278 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 :
11580 needs :
11681 - " bandit"
11782 - " pydocstyle"
11883 - " flake8"
11984 - " yamllint"
120- pylint :
85+ - " black"
86+ - " mypy"
12187 runs-on : " ubuntu-20.04"
12288 strategy :
12389 fail-fast : true
@@ -131,31 +97,11 @@ jobs:
13197 uses : " actions/checkout@v2"
13298 - name : " Setup environment"
13399 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"
154100 - name : " Linting: Pylint"
155101 run : " poetry run invoke pylint"
156- needs :
157- - " build"
158102 pytest :
103+ needs :
104+ - " pylint"
159105 strategy :
160106 fail-fast : true
161107 matrix :
@@ -169,31 +115,11 @@ jobs:
169115 uses : " actions/checkout@v2"
170116 - name : " Setup environment"
171117 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"
192118 - name : " Run Tests"
193119 run : " poetry run invoke pytest"
194- needs :
195- - " pylint"
196120 publish_gh :
121+ needs :
122+ - " pytest"
197123 name : " Publish to GitHub"
198124 runs-on : " ubuntu-20.04"
199125 if : " startsWith(github.ref, 'refs/tags/v')"
@@ -220,9 +146,9 @@ jobs:
220146 tag : " ${{ github.ref }}"
221147 overwrite : true
222148 file_glob : true
149+ publish_pypi :
223150 needs :
224151 - " pytest"
225- publish_pypi :
226152 name : " Push Package to PyPI"
227153 runs-on : " ubuntu-20.04"
228154 if : " startsWith(github.ref, 'refs/tags/v')"
@@ -248,5 +174,39 @@ jobs:
248174 password : " ${{ secrets.PYPI_API_TOKEN }}"
249175 # Using PyPi dev.
250176 repository_url : " https://test.pypi.org/legacy/"
177+ slack-notify :
251178 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/slack-github-action@v1.17.0"
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