Skip to content

Commit d9296b3

Browse files
authored
Merge pull request #10 from jtpio/forks
Allow Check Release to be Run on Fork PRs
2 parents 2bfcbc8 + b9dd000 commit d9296b3

File tree

10 files changed

+166
-120
lines changed

10 files changed

+166
-120
lines changed

.github/actions/check-release/action.yml

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ runs:
2323
export RH_POST_VERSION_SPEC=0.1.0.dev0
2424
export RH_CHANGELOG=${{ inputs.changelog }}
2525
export RH_DRY_RUN=true
26-
if [ ! -z ${GITHUB_HEAD_REF} ]; then
27-
echo "Using GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
28-
export RH_BRANCH=${GITHUB_HEAD_REF}
26+
export RH_REF=${GITHUB_REF}
27+
28+
if [ ! -z ${GITHUB_BASE_REF} ]; then
29+
echo "Using GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
30+
export RH_BRANCH=${GITHUB_BASE_REF}
2931
else
3032
# e.g refs/head/foo or refs/tag/bar
3133
echo "Using GITHUB_REF: ${GITHUB_REF}"
@@ -35,36 +37,12 @@ runs:
3537
# Install Jupyter Releaser from git unless we are testing Releaser itself
3638
export repo_name=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f 2)
3739
echo "repo name: ${repo_name}"
38-
if [ ${repo_name} != "jupyter_releaser" ]; then
39-
pip install git+https://github.com/jupyter-server/jupyter_releaser.git
40-
fi
4140
4241
# Draft Changelog
4342
python -m jupyter_releaser.actions.draft_changelog
4443
4544
# Draft Release
4645
python -m jupyter_releaser.actions.draft_release
4746
48-
- shell: bash
49-
id: publish-release
50-
run: |
51-
set -eux
52-
53-
# Set up env variables
54-
export release_url=${{ steps.draft-release.outputs.release_url }}
55-
export GITHUB_ACCESS_TOKEN=${{ inputs.token }}
56-
export RH_DRY_RUN=true
57-
58-
# Publish Release
59-
python -m jupyter_releaser.actions.publish_release ${release_url}
60-
61-
- shell: bash
62-
run: |
63-
set -eux
64-
65-
# Set up env variables
66-
export GITHUB_ACCESS_TOKEN=${{ inputs.token }}
67-
export release_url=${{ steps.publish-release.outputs.release_url }}
68-
69-
# Delete Draft Release
70-
jupyter-releaser delete-release ${release_url}
47+
# Publish Assets
48+
jupyter-releaser publish-assets --use-checkout-dir

.github/actions/draft-changelog/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ runs:
4242
export RH_VERSION_SPEC=${{ inputs.version_spec }}
4343
export RH_CHANGELOG=${{ inputs.changelog }}
4444
export RH_DRY_RUN=${{ inputs.dry_run }}
45+
export RH_REF=${GITHUB_REF}
4546
4647
# Draft Changelog
4748
pip install -q jupyter-releaser

.github/actions/draft-release/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ runs:
4242
if [ ! -z ${{ inputs.branch }} ]; then
4343
export RH_BRANCH=${{ inputs.branch }}
4444
fi
45+
export RH_REF=${GITHUB_REF}
4546
export RH_VERSION_SPEC=${{ inputs.version_spec }}
4647
export RH_CHANGELOG=${{ inputs.changelog }}
4748
export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }}

.github/workflows/check-release.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ name: Check Release
22
on:
33
push:
44
branches: ["*"]
5+
pull_request:
6+
branches: ["*"]
57

68
jobs:
79
check_release:
810
runs-on: ubuntu-latest
9-
permissions:
10-
contents: write
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v2
@@ -35,6 +35,8 @@ jobs:
3535
key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/.md') }}-md-links
3636
restore-keys: |
3737
${{ runner.os }}-linkcheck-
38+
- name: Print env
39+
run: env
3840
- name: Upgrade packaging dependencies
3941
run: |
4042
pip install --upgrade pip setuptools wheel --user
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
3-
import atexit
43
import os
5-
from subprocess import Popen
6-
from tempfile import TemporaryDirectory
74

8-
from jupyter_releaser.util import CHECKOUT_NAME
95
from jupyter_releaser.util import run
106

11-
os.environ.setdefault("TWINE_USERNAME", "__token__")
127
release_url = os.environ["release_url"]
138
run(f"jupyter-releaser extract-release {release_url}")
149
run(f"jupyter-releaser forwardport-changelog {release_url}")
10+
run("jupyter-releaser publish-assets")
1511
run(f"jupyter-releaser publish-release {release_url}")

jupyter_releaser/changelog.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ def get_version_entry(branch, repo, version, *, auth=None, resolve_backports=Fal
6969
branch = branch.split("/")[-1]
7070
util.log(f"Getting changes to {repo} since {since} on branch {branch}...")
7171

72+
until = util.run(f'git --no-pager log -n 1 origin/{branch} --pretty=format:"%H"')
73+
until = until.replace("%", "")
74+
7275
md = generate_activity_md(
73-
repo, since=since, kind="pr", heading_level=2, auth=auth, branch=branch
76+
repo,
77+
since=since,
78+
until=until,
79+
kind="pr",
80+
heading_level=2,
81+
auth=auth,
82+
branch=branch,
7483
)
7584

7685
if not md:
@@ -113,8 +122,8 @@ def get_version_entry(branch, repo, version, *, auth=None, resolve_backports=Fal
113122

114123
def build_entry(branch, repo, auth, changelog_path, resolve_backports):
115124
"""Build a python version entry"""
116-
repo = repo or util.get_repo()
117125
branch = branch or util.get_branch()
126+
repo = repo or util.get_repo()
118127

119128
# Get the new version
120129
version = util.get_version()
@@ -129,7 +138,6 @@ def build_entry(branch, repo, auth, changelog_path, resolve_backports):
129138
raise ValueError("Insert marker appears more than once in changelog")
130139

131140
# Get changelog entry
132-
133141
entry = get_version_entry(
134142
f"origin/{branch}",
135143
repo,
@@ -200,6 +208,7 @@ def check_entry(branch, repo, auth, changelog_path, resolve_backports, output):
200208
final_entry = changelog[start + len(START_MARKER) : end]
201209

202210
repo = repo or util.get_repo()
211+
203212
raw_entry = get_version_entry(
204213
f"origin/{branch}",
205214
repo,

jupyter_releaser/cli.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ def main():
125125
)
126126
]
127127

128+
128129
branch_options = [
130+
click.option("--ref", envvar="RH_REF", help="The source reference"),
129131
click.option("--branch", envvar="RH_BRANCH", help="The target branch"),
130132
click.option("--repo", envvar="RH_REPOSITORY", help="The git repo"),
131133
]
@@ -216,9 +218,9 @@ def list_envvars():
216218
@add_options(auth_options)
217219
@add_options(username_options)
218220
@add_options(git_url_options)
219-
def prep_git(branch, repo, auth, username, git_url):
221+
def prep_git(ref, branch, repo, auth, username, git_url):
220222
"""Prep git and env variables and bump version"""
221-
lib.prep_git(branch, repo, auth, username, git_url)
223+
lib.prep_git(ref, branch, repo, auth, username, git_url)
222224

223225

224226
@main.command()
@@ -233,7 +235,7 @@ def bump_version(version_spec, version_cmd):
233235
@main.command()
234236
@add_options(changelog_options)
235237
@use_checkout_dir()
236-
def build_changelog(branch, repo, auth, changelog_path, resolve_backports):
238+
def build_changelog(ref, branch, repo, auth, changelog_path, resolve_backports):
237239
"""Build changelog entry"""
238240
changelog.build_entry(branch, repo, auth, changelog_path, resolve_backports)
239241

@@ -244,7 +246,7 @@ def build_changelog(branch, repo, auth, changelog_path, resolve_backports):
244246
@add_options(auth_options)
245247
@add_options(dry_run_options)
246248
@use_checkout_dir()
247-
def draft_changelog(version_spec, branch, repo, auth, dry_run):
249+
def draft_changelog(version_spec, ref, branch, repo, auth, dry_run):
248250
"""Create a changelog entry PR"""
249251
lib.draft_changelog(version_spec, branch, repo, auth, dry_run)
250252

@@ -255,7 +257,7 @@ def draft_changelog(version_spec, branch, repo, auth, dry_run):
255257
"--output", envvar="RH_CHANGELOG_OUTPUT", help="The output file for changelog entry"
256258
)
257259
@use_checkout_dir()
258-
def check_changelog(branch, repo, auth, changelog_path, resolve_backports, output):
260+
def check_changelog(ref, branch, repo, auth, changelog_path, resolve_backports, output):
259261
"""Check changelog entry"""
260262
changelog.check_entry(branch, repo, auth, changelog_path, resolve_backports, output)
261263

@@ -357,17 +359,16 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire):
357359

358360

359361
@main.command()
360-
@add_options(branch_options)
361362
@add_options(dist_dir_options)
362363
@click.option(
363364
"--no-git-tag-workspace",
364365
is_flag=True,
365366
help="Whether to skip tagging npm workspace packages",
366367
)
367368
@use_checkout_dir()
368-
def tag_release(branch, repo, dist_dir, no_git_tag_workspace):
369+
def tag_release(dist_dir, no_git_tag_workspace):
369370
"""Create release commit and tag"""
370-
lib.tag_release(branch, repo, dist_dir, no_git_tag_workspace)
371+
lib.tag_release(dist_dir, no_git_tag_workspace)
371372

372373

373374
@main.command()
@@ -385,6 +386,7 @@ def tag_release(branch, repo, dist_dir, no_git_tag_workspace):
385386
@click.argument("assets", nargs=-1)
386387
@use_checkout_dir()
387388
def draft_release(
389+
ref,
388390
branch,
389391
repo,
390392
auth,
@@ -397,6 +399,7 @@ def draft_release(
397399
):
398400
"""Publish Draft GitHub release"""
399401
lib.draft_release(
402+
ref,
400403
branch,
401404
repo,
402405
auth,
@@ -421,53 +424,58 @@ def delete_release(auth, release_url):
421424
@add_options(auth_options)
422425
@add_options(dist_dir_options)
423426
@add_options(dry_run_options)
424-
@click.argument("release_url", nargs=1)
427+
@click.argument("release-url", nargs=1)
425428
def extract_release(auth, dist_dir, dry_run, release_url):
426429
"""Download and verify assets from a draft GitHub release"""
427430
lib.extract_release(auth, dist_dir, dry_run, release_url)
428431

429432

430433
@main.command()
431-
@add_options(auth_options)
432434
@add_options(dist_dir_options)
433-
@click.option("--npm_token", help="A token for the npm release", envvar="NPM_TOKEN")
435+
@click.option("--npm-token", help="A token for the npm release", envvar="NPM_TOKEN")
434436
@click.option(
435-
"--npm_cmd",
437+
"--npm-cmd",
436438
help="The command to run for npm release",
437439
envvar="RH_NPM_COMMAND",
438440
default="npm publish",
439441
)
440442
@click.option(
441-
"--twine_cmd",
443+
"--twine-cmd",
442444
help="The twine to run for Python release",
443445
envvar="TWINE_COMMAND",
444446
default="twine upload",
445447
)
448+
@click.option("--use-checkout-dir", help="Use the checkout directory", is_flag=True)
446449
@add_options(dry_run_options)
447-
@click.argument("release_url", nargs=1)
448-
def publish_release(
449-
auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url
450-
):
451-
"""Publish release asset(s) and finalize GitHub release"""
452-
lib.publish_release(
453-
auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url
450+
def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir):
451+
"""Publish release asset(s)"""
452+
lib.publish_assets(
453+
dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir
454454
)
455455

456456

457+
@main.command()
458+
@add_options(auth_options)
459+
@click.argument("release-url", nargs=1)
460+
def publish_release(auth, release_url):
461+
"""Publish GitHub release"""
462+
lib.publish_release(auth, release_url)
463+
464+
457465
@main.command()
458466
@add_options(auth_options)
459467
@add_options(branch_options)
460468
@add_options(username_options)
461469
@add_options(changelog_path_options)
462470
@add_options(dry_run_options)
463471
@add_options(git_url_options)
464-
@click.argument("release_url")
472+
@click.argument("release-url")
465473
def forwardport_changelog(
466-
auth, branch, repo, username, changelog_path, dry_run, git_url, release_url
474+
auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url
467475
):
468476
"""Forwardport Changelog Entries to the Default Branch"""
469477
lib.forwardport_changelog(
470-
auth, branch, repo, username, changelog_path, dry_run, git_url, release_url
478+
auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url
471479
)
472480

473481

0 commit comments

Comments
 (0)