Skip to content

Commit 2bfcbc8

Browse files
authored
Merge pull request #8 from jtpio/pypi
Use Local PyPI Server for Dry Run
2 parents eb575ca + bb2c3fe commit 2bfcbc8

File tree

12 files changed

+74
-72
lines changed

12 files changed

+74
-72
lines changed

.github/workflows/check-release.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@ on:
33
push:
44
branches: ["*"]
55

6-
permissions:
7-
contents: write
8-
96
jobs:
107
check_release:
118
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
1211
steps:
1312
- name: Checkout
14-
uses: actions/checkout@v1
13+
uses: actions/checkout@v2
1514
- name: Install Python
16-
uses: actions/setup-python@v1
15+
uses: actions/setup-python@v2
1716
with:
1817
python-version: 3.9
1918
architecture: "x64"
@@ -22,7 +21,7 @@ jobs:
2221
run: |
2322
echo "::set-output name=dir::$(pip cache dir)"
2423
- name: Cache pip
25-
uses: actions/cache@v1
24+
uses: actions/cache@v2
2625
with:
2726
path: ${{ steps.pip-cache.outputs.dir }}
2827
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}
@@ -43,8 +42,6 @@ jobs:
4342
run: |
4443
pip install -e .
4544
- name: Check Release
46-
env:
47-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
4845
uses: ./.github/actions/check-release
4946
with:
5047
token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/draft-changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
python-version: ["3.9"]
2121
steps:
2222
- name: Checkout
23-
uses: actions/checkout@v1
23+
uses: actions/checkout@v2
2424
- name: Install Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v1
25+
uses: actions/setup-python@v2
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828
architecture: "x64"

.github/workflows/draft-release.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,15 @@ jobs:
2626
POST_VERSION_SPEC: ${{ github.event.inputs.post_version_spec }}
2727
steps:
2828
- name: Checkout
29-
uses: actions/checkout@v1
29+
uses: actions/checkout@v2
3030
- name: Install Python ${{ matrix.python-version }}
31-
uses: actions/setup-python@v1
31+
uses: actions/setup-python@v2
3232
with:
3333
python-version: ${{ matrix.python-version }}
3434
architecture: "x64"
3535
- name: Upgrade packaging dependencies
3636
run: |
3737
pip install --upgrade pip setuptools wheel --user
38-
- name: Get pip cache dir
39-
id: pip-cache
40-
run: |
41-
echo "::set-output name=dir::$(pip cache dir)"
42-
- name: Cache pip
43-
uses: actions/cache@v1
44-
with:
45-
path: ${{ steps.pip-cache.outputs.dir }}
46-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
47-
restore-keys: |
48-
${{ runner.os }}-pip-${{ matrix.python-version }}-
49-
${{ runner.os }}-pip-
5038
- name: Install Dependencies
5139
run: |
5240
pip install -e .

.github/workflows/publish-release.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,12 @@ jobs:
1414
with:
1515
access_token: ${{ github.token }}
1616
- name: Checkout
17-
uses: actions/checkout@v1
17+
uses: actions/checkout@v2
1818
- name: Install Python
19-
uses: actions/setup-python@v1
19+
uses: actions/setup-python@v2
2020
with:
2121
python-version: 3.9
2222
architecture: "x64"
23-
- name: Get pip cache dir
24-
id: pip-cache
25-
run: |
26-
echo "::set-output name=dir::$(pip cache dir)"
27-
- name: Cache pip
28-
uses: actions/cache@v1
29-
with:
30-
path: ${{ steps.pip-cache.outputs.dir }}
31-
key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }}
32-
restore-keys: |
33-
${{ runner.os }}-pip-
34-
${{ runner.os }}-pip-
3523
- name: Upgrade packaging dependencies
3624
run: |
3725
pip install --upgrade pip setuptools wheel --user

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ jobs:
4242
with:
4343
access_token: ${{ github.token }}
4444
- name: Checkout
45-
uses: actions/checkout@v1
45+
uses: actions/checkout@v2
4646
- name: Install Python ${{ matrix.python-version }}
47-
uses: actions/setup-python@v1
47+
uses: actions/setup-python@v2
4848
with:
4949
python-version: ${{ matrix.python-version }}
5050
architecture: "x64"
5151
- name: Set up Node
52-
uses: actions/setup-node@v1
52+
uses: actions/setup-node@v2
5353
with:
54-
node-version: "12.x"
54+
node-version: "14.x"
5555
- run: git --version
5656
- name: Upgrade packaging dependencies
5757
run: |
@@ -61,7 +61,7 @@ jobs:
6161
run: |
6262
echo "::set-output name=dir::$(pip cache dir)"
6363
- name: Cache pip
64-
uses: actions/cache@v1
64+
uses: actions/cache@v2
6565
with:
6666
path: ${{ steps.pip-cache.outputs.dir }}
6767
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ version_info = get_version_info(__version__)
184184
- name: Check Release
185185
if: ${{ matrix.python-version == '3.9' }}
186186
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v1
187-
env:
188-
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_TOKEN }}
189187
with:
190188
token: ${{ secrets.GITHUB_TOKEN }}
191189
```

jupyter_releaser/actions/publish_release.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3+
import atexit
34
import os
5+
from subprocess import Popen
6+
from tempfile import TemporaryDirectory
47

8+
from jupyter_releaser.util import CHECKOUT_NAME
59
from jupyter_releaser.util import run
610

7-
811
os.environ.setdefault("TWINE_USERNAME", "__token__")
9-
10-
if os.environ.get("RH_DRY_RUN") == "true":
11-
os.environ.setdefault("TWINE_COMMAND", "twine upload --skip-existing")
12-
os.environ.setdefault("TWINE_REPOSITORY_URL", "https://test.pypi.org/legacy/")
13-
os.environ.setdefault("RH_NPM_COMMAND", "npm publish --dry-run")
14-
1512
release_url = os.environ["release_url"]
1613
run(f"jupyter-releaser extract-release {release_url}")
1714
run(f"jupyter-releaser forwardport-changelog {release_url}")

jupyter_releaser/cli.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def invoke(self, ctx):
3535
envvars[param.name] = param.envvar
3636

3737
for key in sorted(envvars):
38-
print(f"{key.replace('_', '-')}: {envvars[key]}")
38+
util.log(f"{key.replace('_', '-')}: {envvars[key]}")
3939

4040
return
4141

@@ -52,9 +52,9 @@ def invoke(self, ctx):
5252
options = config.get("options", {})
5353

5454
# Print a separation header
55-
print(f'\n\n{"-" * 50}')
56-
print(cmd_name)
57-
print(f'{"-" * 50}\n\n')
55+
util.log(f'\n\n{"-" * 50}')
56+
util.log(cmd_name)
57+
util.log(f'{"-" * 50}\n\n')
5858

5959
# Handle all of the parameters
6060
for param in self.commands[cmd_name].get_params(ctx):
@@ -412,7 +412,6 @@ def draft_release(
412412
@main.command()
413413
@add_options(auth_options)
414414
@click.argument("release-url", nargs=1)
415-
@use_checkout_dir()
416415
def delete_release(auth, release_url):
417416
"""Delete a draft GitHub release by url to the release page"""
418417
lib.delete_release(auth, release_url)

jupyter_releaser/lib.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3+
import atexit
34
import os
45
import os.path as osp
56
import re
7+
import shlex
68
import shutil
79
import sys
810
import uuid
911
from datetime import datetime
1012
from glob import glob
1113
from pathlib import Path
14+
from subprocess import PIPE
15+
from subprocess import Popen
1216
from tempfile import TemporaryDirectory
1317

1418
import requests
@@ -348,6 +352,25 @@ def publish_release(
348352
"""Publish release asset(s) and finalize GitHub release"""
349353
util.log(f"Publishing {release_url} in with dry run: {dry_run}")
350354

355+
if dry_run:
356+
# Start local pypi server with no auth, allowing overwrites,
357+
# in a temporary directory
358+
temp_dir = TemporaryDirectory()
359+
cmd = f"pypi-server -p 8081 -P . -a . -o -v {temp_dir.name}"
360+
proc = Popen(shlex.split(cmd), stderr=PIPE)
361+
# Wait for the server to start
362+
while True:
363+
line = proc.stderr.readline().decode("utf-8").strip()
364+
util.log(line)
365+
if "Listening on" in line:
366+
break
367+
atexit.register(proc.kill)
368+
atexit.register(temp_dir.cleanup)
369+
twine_cmd = "twine upload --repository-url=http://localhost:8081"
370+
os.environ["TWINE_USERNAME"] = "foo"
371+
os.environ["TWINE_PASSWORD"] = "bar"
372+
npm_cmd = "npm publish --dry-run"
373+
351374
match = parse_release_url(release_url)
352375

353376
if npm_token:
@@ -387,7 +410,7 @@ def publish_release(
387410
util.actions_output("release_url", release.html_url)
388411

389412

390-
def prep_git(branch, repo, auth, username, url):
413+
def prep_git(branch, repo, auth, username, url, install=True):
391414
"""Set up git"""
392415
repo = repo or util.get_repo()
393416

@@ -409,7 +432,7 @@ def prep_git(branch, repo, auth, username, url):
409432
checkout_dir = os.environ.get("RH_CHECKOUT_DIR", util.CHECKOUT_NAME)
410433
checkout_exists = False
411434
if osp.exists(osp.join(checkout_dir, ".git")):
412-
print("Git checkout already exists", file=sys.stderr)
435+
util.log("Git checkout already exists")
413436
checkout_exists = True
414437

415438
if not checkout_exists:
@@ -440,7 +463,7 @@ def prep_git(branch, repo, auth, username, url):
440463
util.run(f"git checkout {branch}")
441464

442465
# Install the package with test deps
443-
if util.SETUP_PY.exists():
466+
if util.SETUP_PY.exists() and install:
444467
util.run('pip install ".[test]"')
445468

446469
os.chdir(orig_dir)
@@ -459,8 +482,10 @@ def forwardport_changelog(
459482
tag = release.tag_name
460483

461484
repo = f'{match["owner"]}/{match["repo"]}'
485+
462486
# We want to target the main branch
463-
branch = prep_git(None, repo, auth, username, git_url)
487+
orig_dir = os.getcwd()
488+
branch = prep_git(None, repo, auth, username, git_url, install=False)
464489
os.chdir(util.CHECKOUT_NAME)
465490

466491
# Bail if the tag has been merged to the branch
@@ -520,3 +545,7 @@ def forwardport_changelog(
520545
pr = make_changelog_pr(
521546
auth, branch, repo, title, commit_message, body, dry_run=dry_run
522547
)
548+
549+
# Clean up after ourselves
550+
os.chdir(orig_dir)
551+
shutil.rmtree(util.CHECKOUT_NAME)

jupyter_releaser/tests/test_cli.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,23 +464,29 @@ def helper(path, **kwargs):
464464
assert len(get_mock.mock_calls) == len(dist_names) == 3
465465

466466

467-
def test_publish_release_py(py_dist, runner, mocker, open_mock):
467+
@pytest.mark.skipif(
468+
os.name == "nt", reason="pypiserver does not start properly on Windows"
469+
)
470+
def test_publish_release_py(py_package, runner, mocker, open_mock, git_prep):
468471
open_mock.side_effect = [MockHTTPResponse([REPO_DATA]), MockHTTPResponse()]
469472

473+
# Create the dist files
474+
changelog_entry = mock_changelog_entry(py_package, runner, mocker)
475+
run("python -m build .", cwd=util.CHECKOUT_NAME)
476+
470477
orig_run = util.run
471478
called = 0
472479

473480
def wrapped(cmd, **kwargs):
474481
nonlocal called
475482
if cmd.startswith("twine upload"):
476483
called += 1
477-
return ""
478484
return orig_run(cmd, **kwargs)
479485

480486
mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)
481487

482-
dist_dir = py_dist / util.CHECKOUT_NAME / "dist"
483-
runner(["publish-release", HTML_URL, "--dist-dir", dist_dir])
488+
dist_dir = py_package / util.CHECKOUT_NAME / "dist"
489+
runner(["publish-release", HTML_URL, "--dist-dir", dist_dir, "--dry-run"])
484490
assert len(open_mock.call_args) == 2
485491
assert called == 2, called
486492

0 commit comments

Comments
 (0)