Skip to content

Commit 6d3bfa0

Browse files
git-jock-botGavinF17GitHub
authored
Released 0.1.2 to PyPI
* 87 add release action (#93) * #87 Started action * #87 Updated release action * #94 Readded version string in setup (#95) * Released 0.1.0b28 to Test PyPI Co-authored-by: GitHub <github@users.noreply.github.com> * #87 Updated needed job ID (#97) * #87 Removed repo url from pypi release (#98) * #87 Removed repo url from pypi release * #87 [skip-beta] * Released 0.1.0 to PyPI Co-authored-by: GitHub <github@users.noreply.github.com> * #87 Changed PR base; added fetch before checkout (#100) * Released 0.2.0b1 to Test PyPI Co-authored-by: GitHub <github@users.noreply.github.com> * #87 Updated set_version script (#102) * Released 0.2.0b2 to Test PyPI Co-authored-by: GitHub <github@users.noreply.github.com> * #87 Wrapped release string (#104) * Released 0.2.0b3 to Test PyPI Co-authored-by: GitHub <github@users.noreply.github.com> * Released 0.1.2 to PyPI Co-authored-by: Gavin Fenton <gavin_fenton@msn.com> Co-authored-by: GitHub <github@users.noreply.github.com>
1 parent f1b94e0 commit 6d3bfa0

4 files changed

Lines changed: 231 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "jock"
33
# This will be updated automatically
4-
version = "0.1.0b27"
4+
version = "0.1.2"
55
description = "Group and manage multiple git repositories"
66
authors = [
77
"Gavin Fenton <contact@gavinfenton.com>"

scripts/set_version

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ RELEASES = 'https://pypi.org/rss/project/git-jock/releases.xml'
1010

1111
def get_current_release():
1212
releases_xml = subprocess.run(['curl', RELEASES], capture_output=True)
13-
1413
match = re.search('<title>(\\w+.\\w+.\\w+)</title>', str(releases_xml))
1514
if match:
1615
return match.group(1)
@@ -19,10 +18,27 @@ def get_current_release():
1918
return '0.0.0'
2019

2120

21+
def get_next_major_release():
22+
current_release = get_current_release()
23+
current_release_split = current_release.split('.')
24+
current_release_split[1] = str(int(current_release_split[1]) + 1)
25+
current_release_split[2] = '0'
26+
current_release_split[3] = '0'
27+
return '.'.join(current_release_split)
28+
29+
2230
def get_next_minor_release():
2331
current_release = get_current_release()
2432
current_release_split = current_release.split('.')
2533
current_release_split[1] = str(int(current_release_split[1]) + 1)
34+
current_release_split[2] = '0'
35+
return '.'.join(current_release_split)
36+
37+
38+
def get_next_patch_release():
39+
current_release = get_current_release()
40+
current_release_split = current_release.split('.')
41+
current_release_split[2] = str(int(current_release_split[2]) + 1)
2642
return '.'.join(current_release_split)
2743

2844

@@ -51,6 +67,7 @@ def beta_version():
5167
switcher = {
5268
'alpha': lambda: get_next_prerelease('a'),
5369
'beta': lambda: get_next_prerelease('b'),
70+
'patch': get_next_patch_release,
5471
'minor': get_next_minor_release
5572
}
5673

@@ -76,4 +93,5 @@ def replace_version_in_file(file_path, find, replace):
7693

7794
replace_version_in_file('./jock/__init__.py', "__version__\\s*=\\s*'[\\w.]+'",
7895
"__version__ = '" + release_version + "'")
96+
replace_version_in_file('./setup.py', "version\\s*=\\s*'[\\w.]+'", "version='" + release_version + "'")
7997
replace_version_in_file('./pyproject.toml', 'version\\s*=\\s*"[\\w.]+"', 'version = "' + release_version + '"')

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
from jock import __version__
32
from setuptools import setup, find_packages
43

54
with open('README.md', 'r') as fh:
@@ -8,7 +7,7 @@
87
setup(
98
name='git-jock',
109
# This will be updated automatically
11-
version=__version__,
10+
version='0.1.2',
1211
author='Gavin Fenton',
1312
author_email='contact@gavinfenton.com',
1413
description='Git helper for multi-repository management',

0 commit comments

Comments
 (0)