Skip to content

Commit

Permalink
Add silent option
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Sep 14, 2023
1 parent a4de95e commit 49f7071
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .github/actions/prep-release/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description: "If set, do not make a PR"
default: "false"
required: false
silent:
description: "Set a placeholder in the changelog and don't publish the release."
required: false
type: boolean
since:
description: "Use PRs with activity since this date or git reference"
required: false
Expand Down Expand Up @@ -55,6 +59,7 @@ runs:
export RH_VERSION_SPEC=${{ inputs.version_spec }}
export RH_POST_VERSION_SPEC=${{ inputs.post_version_spec }}
export RH_DRY_RUN=${{ inputs.dry_run }}
export RH_SILENT=${{ inputs.silent }}
export RH_SINCE=${{ inputs.since }}
export RH_SINCE_LAST_STABLE=${{ inputs.since_last_stable }}
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/prep-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ on:
post_version_spec:
description: "Post Version Specifier"
required: false
silent:
description: "Set a placeholder in the changelog and don't publish the release."
required: false
type: boolean
since:
description: "Use PRs with activity since this date or git reference"
required: false
Expand All @@ -41,6 +45,7 @@ jobs:
post_version_spec: ${{ github.event.inputs.post_version_spec }}
target: ${{ github.event.inputs.target }}
branch: ${{ github.event.inputs.branch }}
silent: ${{ github.event.inputs.silent }}
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.inputs.since_last_stable }}

Expand Down
5 changes: 5 additions & 0 deletions example-workflows/full-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
post_version_spec:
description: "Post Version Specifier"
required: false
silent:
description: "Set a placeholder in the changelog and don't publish the release."
required: false
type: boolean
since:
description: "Use PRs with activity since this date or git reference"
required: false
Expand Down Expand Up @@ -40,6 +44,7 @@ jobs:
version_spec: ${{ github.event.inputs.version_spec }}
post_version_spec: ${{ github.event.inputs.post_version_spec }}
branch: ${{ github.event.inputs.branch }}
silent: ${{ github.event.inputs.silent }}
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.inputs.since_last_stable }}

Expand Down
5 changes: 5 additions & 0 deletions example-workflows/prep-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ on:
post_version_spec:
description: "Post Version Specifier"
required: false
silent:
description: "Set a placeholder in the changelog and don't publish the release."
required: false
type: boolean
since:
description: "Use PRs with activity since this date or git reference"
required: false
Expand All @@ -33,6 +37,7 @@ jobs:
version_spec: ${{ github.event.inputs.version_spec }}
post_version_spec: ${{ github.event.inputs.post_version_spec }}
branch: ${{ github.event.inputs.branch }}
silent: ${{ github.event.inputs.silent }}
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.inputs.since_last_stable }}

Expand Down
15 changes: 10 additions & 5 deletions jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

START_MARKER = "<!-- <START NEW CHANGELOG ENTRY> -->"
END_MARKER = "<!-- <END NEW CHANGELOG ENTRY> -->"
START_SILENT_MARKER = "<!-- START SILENT CHANGELOG ENTRY -->"
END_SILENT_MARKER = "<!-- END SILENT CHANGELOG ENTRY -->"
PR_PREFIX = "Automated Changelog Entry"
PRECOMMIT_PREFIX = "[pre-commit.ci] pre-commit autoupdate"

Expand Down Expand Up @@ -148,7 +150,7 @@ def get_version_entry(


def build_entry(
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports, silent=False
):
"""Build a python version entry"""
branch = branch or util.get_branch()
Expand All @@ -168,10 +170,10 @@ def build_entry(
auth=auth,
resolve_backports=resolve_backports,
)
update_changelog(changelog_path, entry)
update_changelog(changelog_path, entry, silent=silent)


def update_changelog(changelog_path, entry):
def update_changelog(changelog_path, entry, silent=False):
"""Update a changelog with a new entry."""
# Get the new version
version = util.get_version()
Expand All @@ -187,14 +189,17 @@ def update_changelog(changelog_path, entry):
msg = "Insert marker appears more than once in changelog"
raise ValueError(msg)

changelog = insert_entry(changelog, entry, version=version)
changelog = insert_entry(changelog, entry, version=version, silent=silent)
Path(changelog_path).write_text(changelog, encoding="utf-8")


def insert_entry(changelog, entry, version=None):
def insert_entry(changelog, entry, version=None, silent=False):
"""Insert the entry into the existing changelog."""
# Test if we are augmenting an existing changelog entry (for new PRs)
# Preserve existing PR entries since we may have formatted them
if silent:
entry = f"{START_SILENT_MARKER}\n\n## {version}\n\n{END_SILENT_MARKER}"

new_entry = f"{START_MARKER}\n\n{entry}\n\n{END_MARKER}"
prev_entry = changelog[
changelog.index(START_MARKER) : changelog.index(END_MARKER) + len(END_MARKER)
Expand Down
21 changes: 18 additions & 3 deletions jupyter_releaser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ def main(force):
),
]

silent_option: t.Any = [
click.option(
"--silent",
envvar="RH_SILENT",
default=False,
help="Set a placeholder in the changelog."
)
]

since_options: t.Any = [
click.option(
"--since",
Expand All @@ -268,6 +277,7 @@ def main(force):
branch_options
+ auth_options
+ changelog_path_options
+ silent_option
+ since_options
+ [
click.option(
Expand Down Expand Up @@ -383,7 +393,7 @@ def extract_changelog(dry_run, auth, changelog_path, release_url):
@add_options(changelog_options)
@use_checkout_dir()
def build_changelog(
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports, silent
):
"""Build changelog entry"""
changelog.build_entry(
Expand All @@ -395,6 +405,7 @@ def build_changelog(
since,
since_last_stable,
resolve_backports,
silent
)


Expand All @@ -406,6 +417,7 @@ def build_changelog(
@add_options(changelog_path_options)
@add_options(dry_run_options)
@add_options(post_version_spec_options)
@add_options(silent_option)
@use_checkout_dir()
def draft_changelog(
version_spec,
Expand All @@ -419,6 +431,7 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
silent
):
"""Create a changelog entry PR"""
lib.draft_changelog(
Expand All @@ -433,6 +446,7 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
silent
)


Expand Down Expand Up @@ -673,10 +687,11 @@ def publish_assets(
@add_options(auth_options)
@add_options(dry_run_options)
@add_options(release_url_options)
@add_options(silent_option)
@use_checkout_dir()
def publish_release(auth, dry_run, release_url):
def publish_release(auth, dry_run, release_url, silent):
"""Publish GitHub release"""
lib.publish_release(auth, dry_run, release_url)
lib.publish_release(auth, dry_run, release_url, silent)


@main.command()
Expand Down
6 changes: 4 additions & 2 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def draft_changelog(
dry_run,
post_version_spec,
post_version_message,
silent
):
"""Create a changelog entry PR"""
repo = repo or util.get_repo()
Expand Down Expand Up @@ -103,6 +104,7 @@ def draft_changelog(
"post_version_spec": post_version_spec,
"post_version_message": post_version_message,
"expected_sha": current_sha,
"silent": silent
}
with tempfile.TemporaryDirectory() as d:
metadata_path = Path(d) / util.METADATA_JSON
Expand Down Expand Up @@ -410,7 +412,7 @@ def publish_assets( # noqa
util.log("No files to upload")


def publish_release(auth, dry_run, release_url):
def publish_release(auth, dry_run, release_url, silent):
"""Publish GitHub release"""
util.log(f"Publishing {release_url}")

Expand All @@ -426,7 +428,7 @@ def publish_release(auth, dry_run, release_url):
release.target_commitish,
release.name,
release.body,
False,
silent, # In silent mode the release will stay in draft mode
release.prerelease,
)

Expand Down

0 comments on commit 49f7071

Please sign in to comment.