Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Check Release to be Run on Fork PRs #10

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions .github/actions/check-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ runs:
export RH_POST_VERSION_SPEC=0.1.0.dev0
export RH_CHANGELOG=${{ inputs.changelog }}
export RH_DRY_RUN=true
if [ ! -z ${GITHUB_HEAD_REF} ]; then
echo "Using GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
export RH_BRANCH=${GITHUB_HEAD_REF}
export RH_REF=${GITHUB_REF}

if [ ! -z ${GITHUB_BASE_REF} ]; then
echo "Using GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
export RH_BRANCH=${GITHUB_BASE_REF}
else
# e.g refs/head/foo or refs/tag/bar
echo "Using GITHUB_REF: ${GITHUB_REF}"
Expand All @@ -35,36 +37,12 @@ runs:
# Install Jupyter Releaser from git unless we are testing Releaser itself
export repo_name=$(echo ${GITHUB_REPOSITORY} | cut -d'/' -f 2)
echo "repo name: ${repo_name}"
if [ ${repo_name} != "jupyter_releaser" ]; then
pip install git+https://github.com/jupyter-server/jupyter_releaser.git
fi

# Draft Changelog
python -m jupyter_releaser.actions.draft_changelog

# Draft Release
python -m jupyter_releaser.actions.draft_release

- shell: bash
id: publish-release
run: |
set -eux

# Set up env variables
export release_url=${{ steps.draft-release.outputs.release_url }}
export GITHUB_ACCESS_TOKEN=${{ inputs.token }}
export RH_DRY_RUN=true

# Publish Release
python -m jupyter_releaser.actions.publish_release ${release_url}

- shell: bash
run: |
set -eux

# Set up env variables
export GITHUB_ACCESS_TOKEN=${{ inputs.token }}
export release_url=${{ steps.publish-release.outputs.release_url }}

# Delete Draft Release
jupyter-releaser delete-release ${release_url}
# Publish Assets
jupyter-releaser publish-assets --use-checkout-dir
1 change: 1 addition & 0 deletions .github/actions/draft-changelog/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ runs:
export RH_VERSION_SPEC=${{ inputs.version_spec }}
export RH_CHANGELOG=${{ inputs.changelog }}
export RH_DRY_RUN=${{ inputs.dry_run }}
export RH_REF=${GITHUB_REF}

# Draft Changelog
pip install -q jupyter-releaser
Expand Down
1 change: 1 addition & 0 deletions .github/actions/draft-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ runs:
if [ ! -z ${{ inputs.branch }} ]; then
export RH_BRANCH=${{ inputs.branch }}
fi
export RH_REF=${GITHUB_REF}
export RH_VERSION_SPEC=${{ inputs.version_spec }}
export RH_CHANGELOG=${{ inputs.changelog }}
export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }}
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Check Release
on:
push:
branches: ["*"]
pull_request:
branches: ["*"]

jobs:
check_release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -35,6 +35,8 @@ jobs:
key: ${{ runner.os }}-linkcheck-${{ hashFiles('**/.md') }}-md-links
restore-keys: |
${{ runner.os }}-linkcheck-
- name: Print env
run: env
- name: Upgrade packaging dependencies
run: |
pip install --upgrade pip setuptools wheel --user
Expand Down
6 changes: 1 addition & 5 deletions jupyter_releaser/actions/publish_release.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import atexit
import os
from subprocess import Popen
from tempfile import TemporaryDirectory

from jupyter_releaser.util import CHECKOUT_NAME
from jupyter_releaser.util import run

os.environ.setdefault("TWINE_USERNAME", "__token__")
release_url = os.environ["release_url"]
run(f"jupyter-releaser extract-release {release_url}")
run(f"jupyter-releaser forwardport-changelog {release_url}")
run("jupyter-releaser publish-assets")
run(f"jupyter-releaser publish-release {release_url}")
15 changes: 12 additions & 3 deletions jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,17 @@ def get_version_entry(branch, repo, version, *, auth=None, resolve_backports=Fal
branch = branch.split("/")[-1]
util.log(f"Getting changes to {repo} since {since} on branch {branch}...")

until = util.run(f'git --no-pager log -n 1 origin/{branch} --pretty=format:"%H"')
until = until.replace("%", "")

md = generate_activity_md(
repo, since=since, kind="pr", heading_level=2, auth=auth, branch=branch
repo,
since=since,
until=until,
kind="pr",
heading_level=2,
auth=auth,
branch=branch,
)

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

def build_entry(branch, repo, auth, changelog_path, resolve_backports):
"""Build a python version entry"""
repo = repo or util.get_repo()
branch = branch or util.get_branch()
repo = repo or util.get_repo()

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

# Get changelog entry

entry = get_version_entry(
f"origin/{branch}",
repo,
Expand Down Expand Up @@ -200,6 +208,7 @@ def check_entry(branch, repo, auth, changelog_path, resolve_backports, output):
final_entry = changelog[start + len(START_MARKER) : end]

repo = repo or util.get_repo()

raw_entry = get_version_entry(
f"origin/{branch}",
repo,
Expand Down
54 changes: 31 additions & 23 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def main():
)
]


branch_options = [
click.option("--ref", envvar="RH_REF", help="The source reference"),
click.option("--branch", envvar="RH_BRANCH", help="The target branch"),
click.option("--repo", envvar="RH_REPOSITORY", help="The git repo"),
]
Expand Down Expand Up @@ -216,9 +218,9 @@ def list_envvars():
@add_options(auth_options)
@add_options(username_options)
@add_options(git_url_options)
def prep_git(branch, repo, auth, username, git_url):
def prep_git(ref, branch, repo, auth, username, git_url):
"""Prep git and env variables and bump version"""
lib.prep_git(branch, repo, auth, username, git_url)
lib.prep_git(ref, branch, repo, auth, username, git_url)


@main.command()
Expand All @@ -233,7 +235,7 @@ def bump_version(version_spec, version_cmd):
@main.command()
@add_options(changelog_options)
@use_checkout_dir()
def build_changelog(branch, repo, auth, changelog_path, resolve_backports):
def build_changelog(ref, branch, repo, auth, changelog_path, resolve_backports):
"""Build changelog entry"""
changelog.build_entry(branch, repo, auth, changelog_path, resolve_backports)

Expand All @@ -244,7 +246,7 @@ def build_changelog(branch, repo, auth, changelog_path, resolve_backports):
@add_options(auth_options)
@add_options(dry_run_options)
@use_checkout_dir()
def draft_changelog(version_spec, branch, repo, auth, dry_run):
def draft_changelog(version_spec, ref, branch, repo, auth, dry_run):
"""Create a changelog entry PR"""
lib.draft_changelog(version_spec, branch, repo, auth, dry_run)

Expand All @@ -255,7 +257,7 @@ def draft_changelog(version_spec, branch, repo, auth, dry_run):
"--output", envvar="RH_CHANGELOG_OUTPUT", help="The output file for changelog entry"
)
@use_checkout_dir()
def check_changelog(branch, repo, auth, changelog_path, resolve_backports, output):
def check_changelog(ref, branch, repo, auth, changelog_path, resolve_backports, output):
"""Check changelog entry"""
changelog.check_entry(branch, repo, auth, changelog_path, resolve_backports, output)

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


@main.command()
@add_options(branch_options)
@add_options(dist_dir_options)
@click.option(
"--no-git-tag-workspace",
is_flag=True,
help="Whether to skip tagging npm workspace packages",
)
@use_checkout_dir()
def tag_release(branch, repo, dist_dir, no_git_tag_workspace):
def tag_release(dist_dir, no_git_tag_workspace):
"""Create release commit and tag"""
lib.tag_release(branch, repo, dist_dir, no_git_tag_workspace)
lib.tag_release(dist_dir, no_git_tag_workspace)


@main.command()
Expand All @@ -385,6 +386,7 @@ def tag_release(branch, repo, dist_dir, no_git_tag_workspace):
@click.argument("assets", nargs=-1)
@use_checkout_dir()
def draft_release(
ref,
branch,
repo,
auth,
Expand All @@ -397,6 +399,7 @@ def draft_release(
):
"""Publish Draft GitHub release"""
lib.draft_release(
ref,
branch,
repo,
auth,
Expand All @@ -421,53 +424,58 @@ def delete_release(auth, release_url):
@add_options(auth_options)
@add_options(dist_dir_options)
@add_options(dry_run_options)
@click.argument("release_url", nargs=1)
@click.argument("release-url", nargs=1)
def extract_release(auth, dist_dir, dry_run, release_url):
"""Download and verify assets from a draft GitHub release"""
lib.extract_release(auth, dist_dir, dry_run, release_url)


@main.command()
@add_options(auth_options)
@add_options(dist_dir_options)
@click.option("--npm_token", help="A token for the npm release", envvar="NPM_TOKEN")
@click.option("--npm-token", help="A token for the npm release", envvar="NPM_TOKEN")
@click.option(
"--npm_cmd",
"--npm-cmd",
help="The command to run for npm release",
envvar="RH_NPM_COMMAND",
default="npm publish",
)
@click.option(
"--twine_cmd",
"--twine-cmd",
help="The twine to run for Python release",
envvar="TWINE_COMMAND",
default="twine upload",
)
@click.option("--use-checkout-dir", help="Use the checkout directory", is_flag=True)
@add_options(dry_run_options)
@click.argument("release_url", nargs=1)
def publish_release(
auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url
):
"""Publish release asset(s) and finalize GitHub release"""
lib.publish_release(
auth, dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, release_url
def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir):
"""Publish release asset(s)"""
lib.publish_assets(
dist_dir, npm_token, npm_cmd, twine_cmd, dry_run, use_checkout_dir
)


@main.command()
@add_options(auth_options)
@click.argument("release-url", nargs=1)
def publish_release(auth, release_url):
"""Publish GitHub release"""
lib.publish_release(auth, release_url)


@main.command()
@add_options(auth_options)
@add_options(branch_options)
@add_options(username_options)
@add_options(changelog_path_options)
@add_options(dry_run_options)
@add_options(git_url_options)
@click.argument("release_url")
@click.argument("release-url")
def forwardport_changelog(
auth, branch, repo, username, changelog_path, dry_run, git_url, release_url
auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url
):
"""Forwardport Changelog Entries to the Default Branch"""
lib.forwardport_changelog(
auth, branch, repo, username, changelog_path, dry_run, git_url, release_url
auth, ref, branch, repo, username, changelog_path, dry_run, git_url, release_url
)


Expand Down
Loading