From fa8749a9d82874e7b68b8ddd96aa1cd98061785f Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sat, 11 Dec 2021 21:05:54 -0600 Subject: [PATCH] make branch and version spec optional --- .github/workflows/draft-changelog.yml | 4 ---- .github/workflows/draft-release.yml | 6 ------ .github/workflows/full-release.yml | 6 ------ .github/workflows/generate-changelog.yml | 4 ---- .github/workflows/publish-release.yml | 3 +-- jupyter_releaser/actions/common.py | 3 ++- jupyter_releaser/actions/generate-changelog.py | 4 +++- jupyter_releaser/changelog.py | 1 + jupyter_releaser/lib.py | 1 + jupyter_releaser/util.py | 12 ++---------- 10 files changed, 10 insertions(+), 34 deletions(-) diff --git a/.github/workflows/draft-changelog.yml b/.github/workflows/draft-changelog.yml index 6f394060..362bf84f 100644 --- a/.github/workflows/draft-changelog.yml +++ b/.github/workflows/draft-changelog.yml @@ -7,16 +7,12 @@ on: required: true branch: description: "The branch to target" - required: true version_spec: description: "New Version Spec" - required: true since: description: Use PRs with activity since this date or git reference - required: false since_last_stable: description: Use PRs with activity since the last stable git tag - required: false jobs: draft_changelog: runs-on: ubuntu-latest diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index bb63b736..63fd4c19 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -7,22 +7,16 @@ on: required: true branch: description: "The branch to target" - required: true version_spec: description: "New Version Specifier" - required: true post_version_spec: description: "Post Version Specifier" - required: false since: description: Use PRs with activity since this date or git reference - required: false since_last_stable: description: Use PRs with activity since the last stable git tag - required: false steps_to_skip: description: Comma separated list of steps to skip - required: false jobs: draft_release: runs-on: ubuntu-latest diff --git a/.github/workflows/full-release.yml b/.github/workflows/full-release.yml index e6d70419..9f5d5e8d 100644 --- a/.github/workflows/full-release.yml +++ b/.github/workflows/full-release.yml @@ -7,22 +7,16 @@ on: required: true branch: description: "The branch to target" - required: true version_spec: description: "New Version Specifier" - required: true post_version_spec: description: "Post Version Specifier" - required: false since: description: Use PRs with activity since this date or git reference - required: false since_last_stable: description: Use PRs with activity since the last stable git tag - required: false steps_to_skip: description: Comma separated list of steps to skip - required: false jobs: full_release: diff --git a/.github/workflows/generate-changelog.yml b/.github/workflows/generate-changelog.yml index 4a9b6b5e..264a80de 100644 --- a/.github/workflows/generate-changelog.yml +++ b/.github/workflows/generate-changelog.yml @@ -7,16 +7,12 @@ on: required: true branch: description: The branch or reference name to filter pull requests by - required: true convert_to_rst: description: Whether to convert to RST - required: false since: description: Use PRs with activity since this date or git reference - required: false until: description: Use PRs with activity until this date or git reference - required: false jobs: generate_changelog: runs-on: ubuntu-latest diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 2f90a00b..754db843 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -6,8 +6,7 @@ on: description: "The URL of the draft GitHub release" required: true steps_to_skip: - description: comma-separated list of steps to steps_to_skip - required: false + description: comma-separated list of steps to skip jobs: publish_release: runs-on: ubuntu-latest diff --git a/jupyter_releaser/actions/common.py b/jupyter_releaser/actions/common.py index 8d47807b..f6e51c9a 100644 --- a/jupyter_releaser/actions/common.py +++ b/jupyter_releaser/actions/common.py @@ -6,7 +6,8 @@ def setup(): os.environ.setdefault("RH_REPOSITORY", os.environ["GITHUB_REPOSITORY"]) os.environ.setdefault("RH_REF", os.environ["GITHUB_REF"]) - if not os.environ.get("RH_BRANCH"): + check_release = os.environ.get("RH_IS_CHECK_RELEASE", "").lower() == "true" + if not os.environ.get("RH_BRANCH") and check_release: if os.environ.get("GITHUB_BASE_REF"): base_ref = os.environ.get("GITHUB_BASE_REF") print(f"Using GITHUB_BASE_REF: ${base_ref}") diff --git a/jupyter_releaser/actions/generate-changelog.py b/jupyter_releaser/actions/generate-changelog.py index 2d7d9434..b169a1b0 100644 --- a/jupyter_releaser/actions/generate-changelog.py +++ b/jupyter_releaser/actions/generate-changelog.py @@ -3,10 +3,11 @@ from jupyter_releaser.changelog import get_version_entry from jupyter_releaser.util import CHECKOUT_NAME +from jupyter_releaser.util import get_branch from jupyter_releaser.util import run target = os.environ.get("RH_REPOSITORY") -branch = os.environ.get("RH_BRANCH") +branch = os.environ.get("RH_BRANCH", "") ref = os.environ.get("RH_REF") since = os.environ.get("RH_SINCE") until = os.environ.get("RH_UNTIL") @@ -18,6 +19,7 @@ print("convert to rst:", convert_to_rst) run("jupyter-releaser prep-git") +branch = get_branch() orig_dir = os.getcwd() os.chdir(CHECKOUT_NAME) output = get_version_entry(ref, branch, target, "current", since=since, until=until) diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index 5b4cc40e..0ea95706 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -80,6 +80,7 @@ def get_version_entry( str A formatted changelog entry with markers """ + branch = branch or util.get_branch() since = since or util.get_latest_tag(ref or branch, since_last_stable) util.log(f"Getting changes to {repo} since {since} on branch {branch}...") diff --git a/jupyter_releaser/lib.py b/jupyter_releaser/lib.py index c055912e..9d77cc1a 100644 --- a/jupyter_releaser/lib.py +++ b/jupyter_releaser/lib.py @@ -139,6 +139,7 @@ def draft_changelog( def make_changelog_pr(auth, branch, repo, title, commit_message, body, dry_run=False): repo = repo or util.get_repo() + branch = branch or util.get_branch() # Make a new branch with a uuid suffix pr_branch = f"changelog-{uuid.uuid1().hex}" diff --git a/jupyter_releaser/util.py b/jupyter_releaser/util.py index 769d7f81..1b79affb 100644 --- a/jupyter_releaser/util.py +++ b/jupyter_releaser/util.py @@ -108,16 +108,7 @@ def log(*outputs, **kwargs): def get_branch(): """Get the appropriate git branch""" - if os.environ.get("GITHUB_HEAD_REF"): - # GitHub Action PR Event - branch = os.environ["GITHUB_HEAD_REF"] - elif os.environ.get("GITHUB_REF"): - # GitHub Action Push Event - # e.g. refs/heads/feature-branch-1 - branch = "/".join(os.environ["GITHUB_REF"].split("/")[2:]) - else: - branch = run("git branch --show-current") - return branch + return run("git branch --show-current") def get_default_branch(): @@ -267,6 +258,7 @@ def actions_output(name, value): def get_latest_tag(source, since_last_stable=False): """Get the default 'since' value for a branch""" + source = source or get_branch() tags = run(f"git --no-pager tag --sort=-creatordate --merged {source}", quiet=True) if not tags: return ""