-
-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (152 loc) · 6.31 KB
/
w2-workflow-python-publish.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
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
# """
# The MIT License (MIT)
# Copyright (c) 2023 pkjmesra
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# """
# This workflows will upload a Python Package using Twine when a commit is pushed
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: 2. PyPi Publish
on:
workflow_dispatch:
inputs:
name:
description: 'PyPi Publish'
required: false
default: 'PyPi Publish'
branch-name:
description: 'branch-name'
required: true
type: string
default: 'main'
version:
description: 'Release version'
required: true
type: string
default: 'x.y.z'
# schedule:
# - cron: '30 7 * * 6'
workflow_call:
inputs:
branch-name:
required: true
type: string
default: 'main'
version:
required: true
type: string
default: 'x.y.z'
jobs:
check_should_run:
runs-on: windows-latest
name: Check latest commit
outputs:
should_run: ${{ steps.should_run.outputs.should_run }}
steps:
- uses: actions/checkout@v2
with:
ref: main
- name: print latest_commit
run: echo ${{ github.sha }}
- id: should_run
continue-on-error: true
name: check latest commit is less than a week
if: ${{ github.event_name == 'workflow_call' }} || ${{ github.event_name == 'workflow_dispatch' }}
run: test -z $(git rev-list --after="7 days" ${{ github.sha }}) && echo "::set-output name=should_run::false"
deploy:
runs-on: windows-latest
needs: check_should_run
permissions: write-all
steps:
- uses: actions/checkout@v2
with:
ref: ${{ inputs.branch-name }}
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Restore Dependencies from Cache
uses: actions/cache@v2
with:
path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install Python Dependencies
run: |
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
- name: Install setuptools
run: |
pip3 install setuptools wheel twine
pip3 install .
- name: Declare env variables
id: vars
shell: bash
run: |
GITHUB_REF=${GITHUB_REF#refs/tags/}
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
CURRENT_VERSION=`grep -o "'.*'" PKDevTools/classes/__init__.py | sed "s/'//g"`
VERSION_ARR=(${CURRENT_VERSION//./ })
MAJOR_MINOR=${VERSION_ARR[0]}.${VERSION_ARR[1]}
TODAY=`date +%Y%m%d`
THIS_VERSION=${MAJOR_MINOR}.${TODAY}.${{github.run_number}}
echo ${THIS_VERSION}
if [ "${{ inputs.version }}" == "x.y.z" ]; then
echo "default version x.y.z cannot be used"
else
THIS_VERSION="${{ inputs.version }}"
fi
rm -rf PKDevTools/classes/__init__.py
echo VERSION=\'`echo ${THIS_VERSION}`\' >> PKDevTools/classes/__init__.py
echo "##[set-output name=THIS_VERSION;]$(echo ${THIS_VERSION})"
echo "##[set-output name=CURRENT_VERSION;]$(echo ${CURRENT_VERSION})"
- name: Build and publish distribution 📦 to Test PyPI
if: ${{ needs.check_should_run.outputs.should_run != 'false' }}
env:
TWINE_USERNAME: ${{ secrets.TESTPYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TESTPYPI_PASSWORD }}
repository_url: https://test.pypi.org/legacy/
shell: cmd
run: |
rmdir /s /q build
rmdir /s /q dist
# del /s /q PKDevTools/classes/__init__.py
# echo VERSION='${{ steps.vars.outputs.THIS_VERSION }}' >> PKDevTools/classes/__init__.py
python3 setup.py clean build sdist bdist_wheel
twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*
- name: Publish distribution 📦 to PyPI
if: ${{ needs.check_should_run.outputs.should_run != 'false' }}
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
repository_url: https://upload.pypi.org/legacy/
shell: cmd
run: |
rmdir /s /q build
rmdir /s /q dist
# del /s /q PKDevTools/classes/__init__.py
# echo VERSION='${{ steps.vars.outputs.THIS_VERSION }}' >> PKDevTools/classes/__init__.py
python3 setup.py clean build sdist bdist_wheel
twine upload --verbose dist/*
- name: Delete history of workflow runs
shell: bash
run: |
gh run list --status completed --limit 100 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
# gh run list --status cancelled --limit 100 --json databaseId -q '.[].databaseId' | xargs -IID gh api "repos/$(gh repo view --json nameWithOwner -q .nameWithOwner)/actions/runs/ID" -X DELETE
env:
GH_TOKEN : ${{secrets.GITHUB_TOKEN}}