-
Notifications
You must be signed in to change notification settings - Fork 1
213 lines (194 loc) · 6.55 KB
/
release.yml
File metadata and controls
213 lines (194 loc) · 6.55 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
202
203
204
205
206
207
208
209
210
211
212
213
name: Release
on:
workflow_dispatch:
inputs:
type:
description: 'Release type, one of [major, minor, patch]'
required: true
default: 'minor'
jobs:
pypi-release:
if: |
(github.event.inputs.type == 'major') ||
(github.event.inputs.type == 'minor') ||
(github.event.inputs.type == 'patch')
name: PyPI Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Merge release branch
run: |
git merge --strategy-option=theirs origin/release
- name: Set version
run: |
echo "NEW_VERSION=$(./scripts/set_version ${{github.event.inputs.type}})" >> $GITHUB_ENV
- name: Install pep517
run: >-
python -m
pip install
pep517
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
pep517.build
--source
--binary
--out-dir dist/
.
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
- name: Set version
run: |
echo "CURRENT_BRANCH=$(git branch --show-current)" >> $GITHUB_ENV
echo "COMMIT_MESSAGE=Released $NEW_VERSION to PyPI" >> $GITHUB_ENV
- name: Create release branch
run: |
git config --global user.name 'GitHub'
git config --global user.email 'github@users.noreply.github.com'
git checkout -b release-$NEW_VERSION
git add ./setup.py ./pyproject.toml ./jock/__init__.py
git commit -m "$COMMIT_MESSAGE"
git push --set-upstream origin release-$NEW_VERSION
echo "CURRENT_REF=$(git show-ref --hash --head HEAD)" >> $GITHUB_ENV
- name: Create release PR
id: create-release-pr
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GIT_JOCK }}
script: |
const {data: {number}} = await github.request('POST /repos/{owner}/{repo}/pulls', {
owner: 'git-jock',
repo: 'git-jock-cli',
head: `release-${process.env.NEW_VERSION}`,
base: 'release',
title: process.env.COMMIT_MESSAGE
})
console.log(`Created PR ${number}`)
return number
result-encoding: string
- name: Approve release PR
uses: actions/github-script@v3
env:
PULL_NUMBER: ${{ steps.create-release-pr.outputs.result }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.request('POST /repos/{owner}/{repo}/pulls/{pull_number}/reviews', {
owner: 'git-jock',
repo: 'git-jock-cli',
pull_number: process.env.PULL_NUMBER,
event: 'APPROVE'
})
- name: Merge release PR
uses: actions/github-script@v3
env:
PULL_NUMBER: ${{ steps.create-release-pr.outputs.result }}
with:
github-token: ${{ secrets.GIT_JOCK }}
script: |
let retries = 0
const checkStatus = async () => {
console.log(`Getting check status; attempt ${++retries}`)
try {
await github.request('PUT /repos/{owner}/{repo}/pulls/{pull_number}/merge', {
owner: 'git-jock',
repo: 'git-jock-cli',
pull_number: process.env.PULL_NUMBER,
commit_title: process.env.COMMIT_MESSAGE,
merge_method: 'squash'
})
} catch (error) {
if (error.status != 405 || retries > 30) {
console.error('Retries exceeded, throwing last error')
throw error
}
setTimeout(checkStatus, 5000)
}
}
await checkStatus()
- name: Checkout release branch
run: |
git fetch
git checkout release
git tag v${{ env.NEW_VERSION }}
git push --tags
git fetch
git checkout v${{ env.NEW_VERSION }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.NEW_VERSION }}
release_name: Release v${{ env.NEW_VERSION }}
- name: Store Upload URL
run: |
echo '${{ steps.create_release.outputs.upload_url }}'
echo '${{ steps.create_release.outputs.upload_url }}' > upload_url.txt
cat upload_url.txt
- name: Upload upload_url
uses: actions/upload-artifact@v2
with:
name: upload_url
path: ./upload_url.txt
release-matrix:
name: Release Matrix
needs: pypi-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Clone git-jock-cli
run: git clone https://github.com/git-jock/git-jock-cli.git
- name: Install git-jock-cli dependencies
run: |
cd git-jock-cli
pip install -r requirements.txt
- name: Install PyInstaller
run: pip install pyinstaller
- name: Run PyInstaller
run: |
cd git-jock-cli
pyinstaller jock/__main__.py --onefile --name jock
- name: Download upload_url
uses: actions/download-artifact@v2
with:
name: upload_url
- name: Set Env Variables
run: |
ZIP_NAME=jock-$(uname)-$(uname -m)
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV
echo "ZIP_FILE=$ZIP_NAME.zip" >> $GITHUB_ENV
echo "UPLOAD_URL=$(cat ./upload_url.txt)" >> $GITHUB_ENV
- name: Debug
run: |
ls
cat upload_url.txt
echo $ZIP_NAME
echo $ZIP_FILE
echo $UPLOAD_URL
- name: Zip
run: zip -j $ZIP_NAME git-jock-cli/dist/jock
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: ${{ env.ZIP_FILE }}
asset_name: ${{ env.ZIP_FILE }}
asset_content_type: application/zip