1+ name : Release
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ type :
7+ description : ' Release type, one of [major, minor, patch]'
8+ required : true
9+ default : ' minor'
10+
11+ jobs :
12+ pypi-release :
13+ if : |
14+ (github.event.inputs.type == 'major') ||
15+ (github.event.inputs.type == 'minor') ||
16+ (github.event.inputs.type == 'patch')
17+ name : PyPI Release
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - uses : actions/checkout@v2
22+ - name : Set up Python 3.9
23+ uses : actions/setup-python@v2
24+ with :
25+ python-version : 3.9
26+ - name : Set version
27+ run : |
28+ echo "NEW_VERSION=$(./scripts/set_version ${{github.event.inputs.type}})" >> $GITHUB_ENV
29+ - name : Install pep517
30+ run : >-
31+ python -m
32+ pip install
33+ pep517
34+ --user
35+ - name : Build a binary wheel and a source tarball
36+ run : >-
37+ python -m
38+ pep517.build
39+ --source
40+ --binary
41+ --out-dir dist/
42+ .
43+ - name : Publish distribution to PyPI
44+ uses : pypa/gh-action-pypi-publish@master
45+ with :
46+ password : ${{ secrets.pypi_password }}
47+ - name : Set version
48+ run : |
49+ echo "CURRENT_BRANCH=$(git branch --show-current)" >> $GITHUB_ENV
50+ echo "COMMIT_MESSAGE=Released $NEW_VERSION to PyPI" >> $GITHUB_ENV
51+ - name : Create release branch
52+ run : |
53+ git config --global user.name 'GitHub'
54+ git config --global user.email 'github@users.noreply.github.com'
55+ git checkout -b release-$NEW_VERSION
56+ git add ./setup.py ./pyproject.toml
57+ git commit -m "$COMMIT_MESSAGE"
58+ git push --set-upstream origin release-$NEW_VERSION
59+ echo "CURRENT_REF=$(git show-ref --hash --head HEAD)" >> $GITHUB_ENV
60+ - name : Create release PR
61+ id : create-release-pr
62+ uses : actions/github-script@v3
63+ with :
64+ github-token : ${{ secrets.GIT_JOCK }}
65+ script : |
66+ const {data: {number}} = await github.request('POST /repos/{owner}/{repo}/pulls', {
67+ owner: 'git-jock',
68+ repo: 'git-jock-cli',
69+ head: `release-${process.env.NEW_VERSION}`,
70+ base: 'release',
71+ title: process.env.COMMIT_MESSAGE
72+ })
73+ console.log(`Created PR ${number}`)
74+ return number
75+ result-encoding : string
76+ - name : Approve release PR
77+ uses : actions/github-script@v3
78+ env :
79+ PULL_NUMBER : ${{ steps.create-release-pr.outputs.result }}
80+ with :
81+ github-token : ${{ secrets.GITHUB_TOKEN }}
82+ script : |
83+ await github.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews', {
84+ owner: 'git-jock',
85+ repo: 'git-jock-cli',
86+ pull_number: process.env.PULL_NUMBER,
87+ event: 'APPROVE'
88+ })
89+ - name : Merge release PR
90+ uses : actions/github-script@v3
91+ env :
92+ PULL_NUMBER : ${{ steps.create-release-pr.outputs.result }}
93+ with :
94+ github-token : ${{ secrets.GIT_JOCK }}
95+ script : |
96+ let retries = 0
97+ const checkStatus = async () => {
98+ console.log(`Getting check status; attempt ${++retries}`)
99+
100+ try {
101+ await github.request('PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge', {
102+ owner: 'git-jock',
103+ repo: 'git-jock-cli',
104+ pull_number: process.env.PULL_NUMBER,
105+ commit_title: process.env.COMMIT_MESSAGE,
106+ merge_method: 'squash'
107+ })
108+ } catch (error) {
109+ if (error.status != 405 || retries > 30) {
110+ console.error('Retries exceeded, throwing last error')
111+ throw error
112+ }
113+ setTimeout(checkStatus, 5000)
114+ }
115+ }
116+ await checkStatus()
117+
118+ - name : Checkout release branch
119+ run : |
120+ git fetch
121+ git checkout release
122+ git tag v${{ env.NEW_VERSION }}
123+ git push --tags
124+ git fetch
125+ git checkout v${{ env.NEW_VERSION }}
126+
127+ - name : Create Release
128+ id : create_release
129+ uses : actions/create-release@v1
130+ env :
131+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
132+ with :
133+ tag_name : v${{ env.NEW_VERSION }}
134+ release_name : Release v${{ env.NEW_VERSION }}
135+
136+ - name : Store Upload URL
137+ run : |
138+ echo '${{ steps.create_release.outputs.upload_url }}'
139+ echo '${{ steps.create_release.outputs.upload_url }}' > upload_url.txt
140+ cat upload_url.txt
141+
142+ - name : Upload upload_url
143+ uses : actions/upload-artifact@v2
144+ with :
145+ name : upload_url
146+ path : ./upload_url.txt
147+
148+ release-matrix :
149+ name : Release Matrix
150+ needs : pypi-release
151+ runs-on : ${{ matrix.os }}
152+ strategy :
153+ matrix :
154+ os : [ubuntu-latest, macos-latest]
155+
156+ steps :
157+ - name : Setup Python
158+ uses : actions/setup-python@v2
159+ with :
160+ python-version : 3.7
161+
162+ - name : Clone git-jock-cli
163+ run : git clone https://github.com/git-jock/git-jock-cli.git
164+
165+ - name : Install git-jock-cli dependencies
166+ run : |
167+ cd git-jock-cli
168+ pip install -r requirements.txt
169+
170+ - name : Install PyInstaller
171+ run : pip install pyinstaller
172+
173+ - name : Run PyInstaller
174+ run : |
175+ cd git-jock-cli
176+ pyinstaller jock/__main__.py --onefile --name jock
177+
178+ - name : Download upload_url
179+ uses : actions/download-artifact@v2
180+ with :
181+ name : upload_url
182+
183+ - name : Set Env Variables
184+ run : |
185+ ZIP_NAME=jock-$(uname)-$(uname -m)
186+ echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
187+ echo "ZIP_FILE=$ZIP_NAME.zip" >> $GITHUB_ENV
188+ echo "UPLOAD_URL=$(cat ./upload_url.txt)" >> $GITHUB_ENV
189+
190+ - name : Debug
191+ run : |
192+ ls
193+ cat upload_url.txt
194+ echo $ZIP_NAME
195+ echo $ZIP_FILE
196+ echo $UPLOAD_URL
197+
198+ - name : Zip
199+ run : zip -j $ZIP_NAME git-jock-cli/dist/jock
200+
201+ - name : Upload Release Asset
202+ id : upload-release-asset
203+ uses : actions/upload-release-asset@v1
204+ env :
205+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
206+ with :
207+ upload_url : ${{ env.UPLOAD_URL }}
208+ asset_path : ${{ env.ZIP_FILE }}
209+ asset_name : ${{ env.ZIP_FILE }}
210+ asset_content_type : application/zip
0 commit comments