Skip to content

Commit 83333dd

Browse files
committed
Add GitHub action to publish Python package on tag push
1 parent e4c70c3 commit 83333dd

File tree

6 files changed

+68
-24
lines changed

6 files changed

+68
-24
lines changed

.github/workflows/publish-docker-image.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ jobs:
2020
username: ${{ secrets.DOCKERHUB_USERNAME }}
2121
password: ${{ secrets.DOCKERHUB_TOKEN }}
2222

23-
- name: Log in GitHub Docker registry
24-
uses: docker/login-action@v1
25-
with:
26-
registry: ghcr.io
27-
username: ${{ github.actor }}
28-
password: ${{ secrets.GITHUB_TOKEN }}
29-
3023
- name: Extract metadata (tags, labels) for Docker
3124
id: meta
3225
uses: docker/metadata-action@v3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Publish Python Package
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish-package:
10+
name: Publish Package
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
16+
- name: Set tag version
17+
id: tag_version
18+
run: |
19+
tag=$(echo $GITHUB_REF | cut -d / -f 3)
20+
echo ::set-output name=version::${tag:1}
21+
22+
- name: Install dependencies
23+
run: python3 -m pip install setuptools wheel twine
24+
25+
- name: Build project
26+
run: python3 setup.py sdist bdist_wheel
27+
28+
- name: Check build
29+
run: python3 -m twine check dist/*
30+
31+
- name: Install leetcode-export
32+
run: sudo python3 setup.py install
33+
34+
- name: Check that tag version matched Python package version
35+
run: |
36+
expected="leetcode-export ${{ steps.tag_version.outputs.version }}"
37+
actual=$(leetcode-export --version)
38+
echo expected=\"$expected\"
39+
echo actual=\"$actual\"
40+
[[ $expected == $actual ]]
41+
42+
- name: Publish project
43+
run: python3 -m twine upload dist/* -u ${{ secrets.PYPY_USERNAME }} -p ${{ secrets.PYPY_PASSWORD }} --non-interactive

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,24 @@ python leetcode-export --cookies {COOKIES}
9595
The script accepts the following arguments:
9696
9797
```
98-
usage: leetcode-export [-h] [--cookies COOKIES] [--folder FOLDER] [-v] [-vv]
98+
usage: leetcode-export [-h] [--cookies COOKIES] [--folder FOLDER]
9999
[--problem-filename PROBLEM_FILENAME]
100-
[--submission-filename SUBMISSION_FILENAME]
100+
[--submission-filename SUBMISSION_FILENAME] [-v] [-vv]
101+
[-V]
101102
102103
Export LeetCode solutions
103104
104105
optional arguments:
105106
-h, --help show this help message and exit
106-
--cookies COOKIES Set LeetCode cookies
107-
--folder FOLDER Output folder
108-
-v, --verbose Enable verbose logging details
109-
-vv, --extra-verbose Enable more verbose logging details
107+
--cookies COOKIES set LeetCode cookies
108+
--folder FOLDER set output folder
110109
--problem-filename PROBLEM_FILENAME
111-
Problem description filename format
110+
problem description filename format
112111
--submission-filename SUBMISSION_FILENAME
113-
Submission filename format
112+
submission filename format
113+
-v, --verbose enable verbose logging details
114+
-vv, --extra-verbose enable more verbose logging details
115+
-V, --version show program's version number and exit
114116
```
115117

116118
Using the interactive menu is preferred as it will avoid storing your cookies in the command history.

leetcode_export/__main__.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env python3
21
import argparse
32
import logging
43
import os
54
from string import Template
65
from typing import Set
76

7+
from leetcode_export._version import __version__
88
from leetcode_export.leetcode import LeetCode
99

1010
PROBLEM_CONTENT_TEMPLATE = Template('''${question_id} - ${title}
@@ -16,16 +16,18 @@
1616

1717
def parse_args():
1818
parser = argparse.ArgumentParser(description='Export LeetCode solutions')
19-
parser.add_argument('--cookies', type=str, help='Set LeetCode cookies')
20-
parser.add_argument('--folder', type=str, default='.', help='Output folder')
21-
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='Enable verbose logging details')
22-
parser.add_argument('-vv', '--extra-verbose', dest='extra_verbose', action='store_true',
23-
help='Enable more verbose logging details')
19+
parser.add_argument('--cookies', type=str, help='set LeetCode cookies')
20+
parser.add_argument('--folder', type=str, default='.', help='set output folder')
2421
parser.add_argument('--problem-filename', type=str, default='${question_id} - ${title_slug}.txt',
25-
help='Problem description filename format')
22+
help='problem description filename format')
2623
parser.add_argument('--submission-filename', type=str,
2724
default='${date_formatted} - ${status_display} - runtime ${runtime} - memory ${memory}.${extension}',
28-
help='Submission filename format')
25+
help='submission filename format')
26+
parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='enable verbose logging details')
27+
parser.add_argument('-vv', '--extra-verbose', dest='extra_verbose', action='store_true',
28+
help='enable more verbose logging details')
29+
parser.add_argument('-V', '--version', action='version',
30+
version='%(prog)s {version}'.format(version=__version__))
2931
parser.set_defaults(verbose=False, extra_verbose=False)
3032

3133
return parser.parse_args()

leetcode_export/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.1.1'

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
from setuptools import setup, find_packages
22

3+
exec(open('leetcode_export/_version.py').read())
4+
35
with open("README.md", 'r') as f:
46
long_description = f.read()
57

68
setup(
79
name='leetcode-export',
8-
version='1.1.1',
10+
version=__version__,
911
url='https://github.com/NeverMendel/leetcode-export',
1012
license='MIT',
1113
author='Davide Cazzin',
14+
email='cazzindavide@gmail.com',
1215
description='Python script to export your LeetCode solutions',
1316
long_description=long_description,
1417
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)