Skip to content

Commit dfef9a2

Browse files
committed
feat: adds branch parameter (closes #62)
1 parent b1c5a41 commit dfef9a2

8 files changed

Lines changed: 46 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next Release
44

55
- Adds `custom_tarball` parameter, allowing you to bundle your distributable assets however you'd like (closes #63)
6+
- Adds `branch` parameter, allowing you to push the formula file to any branch you'd like (closes #62)
67
- Homebrew Releaser now warns instead of raising an exception and exiting with a failure if the `git commit` operation is unsuccessful due to "nothing to commit". This is useful if you want to test back to back releases or need to recreate a release but the underlying assets have not changed (closes #69)
78
- Optimizes how asset URL selection occurs when downloading assets to generate checksums for
89
- Makes `formula_folder` optional as we always had a default of `Formula`, now allows users to omit its inclusion in their yaml

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ jobs:
9494
# Default is shown - string
9595
formula_folder: Formula
9696

97+
# The branch to push your formula file to (if not used, the branch will be your repo's default branch).
98+
# Optional - string
99+
branch: bump_foo_to_v2
100+
97101
# The Personal Access Token (saved as a repo secret) that has `repo` permissions for the repo running the action AND Homebrew tap you want to release to.
98102
# Required - string
99103
github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
formula_folder:
1414
description: 'The name of the folder in your homebrew tap where formula will be committed to.'
1515
required: false
16+
branch:
17+
description: The branch to push your formula file to (if not present, the branch used will be your repo default branch).
18+
required: false
1619
github_token:
1720
description: 'The GitHub Token (saved as a repo secret) that has `repo` permissions for the homebrew tap you want to release to.'
1821
required: true

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ services:
77
environment:
88
# Env vars that should be `false` should be left empty
99
- GITHUB_REPOSITORY=justintime50/github-actions-test
10-
- INPUT_SKIP_COMMIT=
11-
- INPUT_UPDATE_README_TABLE=
12-
- INPUT_DEBUG=true
1310
- INPUT_HOMEBREW_OWNER=justintime50
1411
- INPUT_HOMEBREW_TAP=homebrew-test
1512
- INPUT_FORMULA_FOLDER=Formula
13+
- INPUT_BRANCH=
1614
- INPUT_GITHUB_TOKEN=
1715
- INPUT_COMMIT_OWNER=justintime50
1816
- INPUT_COMMIT_EMAIL=39606064+Justintime50@users.noreply.github.com
@@ -23,9 +21,13 @@ services:
2321
- INPUT_CUSTOM_REQUIRE=
2422
- INPUT_FORMULA_INCLUDES='include Language::Python::Virtualenv'
2523
- INPUT_UPDATE_PYTHON_RESOURCES=true
24+
- INPUT_VERSION=
2625
- INPUT_TARGET_DARWIN_AMD64=
2726
- INPUT_TARGET_DARWIN_ARM64=
2827
- INPUT_TARGET_LINUX_AMD64=
2928
- INPUT_TARGET_LINUX_ARM64=
3029
- INPUT_CUSTOM_TARBALL=
30+
- INPUT_UPDATE_README_TABLE=
31+
- INPUT_SKIP_COMMIT=
3132
- INPUT_SKIP_CHECKSUM=
33+
- INPUT_DEBUG=true

homebrew_releaser/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
upload_checksum_file,
1010
)
1111
from homebrew_releaser.constants import (
12+
BRANCH,
1213
CHECKSUM_FILE,
1314
COMMIT_EMAIL,
1415
COMMIT_OWNER,
@@ -228,7 +229,7 @@ def run_github_action():
228229
logger.info(f"Skipping upload of checksum.txt to {HOMEBREW_TAP}.")
229230
else:
230231
logger.info(f"Attempting to release {version} of {GITHUB_REPO} to {HOMEBREW_TAP}...")
231-
push_git(HOMEBREW_TAP, HOMEBREW_OWNER)
232+
push_git(HOMEBREW_TAP, HOMEBREW_OWNER, BRANCH)
232233
if SKIP_CHECKSUM:
233234
logger.info(f"Skipping upload of checksum.txt to {HOMEBREW_TAP}.")
234235
else:

homebrew_releaser/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
HOMEBREW_OWNER = os.getenv("INPUT_HOMEBREW_OWNER", "").lower()
66
HOMEBREW_TAP = os.getenv("INPUT_HOMEBREW_TAP", "").lower()
77
FORMULA_FOLDER = os.getenv("INPUT_FORMULA_FOLDER", "Formula")
8+
BRANCH = os.getenv("INPUT_BRANCH")
89
GITHUB_TOKEN = os.getenv("INPUT_GITHUB_TOKEN")
910
COMMIT_OWNER = os.getenv("INPUT_COMMIT_OWNER", "homebrew-releaser")
1011
COMMIT_EMAIL = os.getenv("INPUT_COMMIT_EMAIL", "homebrew-releaser@example.com")

homebrew_releaser/git.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ def commit_git(homebrew_tap: str, repo_name: str, version: str):
7676
raise
7777

7878

79-
def push_git(homebrew_tap: str, homebrew_owner: str):
79+
def push_git(homebrew_tap: str, homebrew_owner: str, branch: Optional[str] = None):
8080
"""Pushes git assets to the remote Homebrew tap repo."""
8181
# fmt: off
82-
command = ['git', '-C', build_dir_path(homebrew_tap), 'push', f'https://x-access-token:{GITHUB_TOKEN}@github.com/{homebrew_owner}/{homebrew_tap}.git'] # noqa
82+
if branch:
83+
command = ['git', '-C', build_dir_path(homebrew_tap), 'push', f'https://x-access-token:{GITHUB_TOKEN}@github.com/{homebrew_owner}/{homebrew_tap}.git', f"HEAD:{branch}"] # noqa
84+
else:
85+
command = ['git', '-C', build_dir_path(homebrew_tap), 'push', f'https://x-access-token:{GITHUB_TOKEN}@github.com/{homebrew_owner}/{homebrew_tap}.git'] # noqa
8386
# fmt: on
8487
_run_git_subprocess(command, f"Assets pushed successfully to {homebrew_tap}.")
8588

test/unit/test_git.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,31 @@ def test_push(mock_subprocess):
154154
)
155155

156156

157+
@patch("homebrew_releaser.utils.WORKING_DIR", "")
158+
@patch("homebrew_releaser.git.GITHUB_TOKEN", "123")
159+
@patch("subprocess.check_output")
160+
def test_push_with_branch(mock_subprocess):
161+
"""Tests that we call the correct git push command."""
162+
homebrew_tap = "homebrew-formulas"
163+
homebrew_owner = "Justintime50"
164+
165+
push_git(homebrew_tap, homebrew_owner, "test")
166+
167+
mock_subprocess.assert_called_once_with(
168+
[
169+
"git",
170+
"-C",
171+
homebrew_tap,
172+
"push",
173+
f"https://x-access-token:123@github.com/{homebrew_owner}/{homebrew_tap}.git",
174+
"HEAD:test",
175+
],
176+
stderr=-2,
177+
text=True,
178+
timeout=TIMEOUT,
179+
)
180+
181+
157182
@patch("logging.Logger.debug")
158183
@patch(
159184
"subprocess.check_output",

0 commit comments

Comments
 (0)