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

packs.get assumes branch master #6225

Open
jpavlav opened this issue Jul 25, 2024 · 0 comments
Open

packs.get assumes branch master #6225

jpavlav opened this issue Jul 25, 2024 · 0 comments

Comments

@jpavlav
Copy link
Contributor

jpavlav commented Jul 25, 2024

SUMMARY

When running packs.get against a pack that uses main as the main branch, the action errors out on:

git rev-list --left-right --count HEAD...origin/master

STACKSTORM VERSION

st2 3.7.0, on Python 3.8.10
st2 3.8.1, on Python 3.8.10
OS, environment, install method

This is happening in the st2-docker environment and on Ubuntu Focal 20.04.6 LTS.

Steps to reproduce the problem

You can verify this with st2-docker most easily. Create a new pack as a git repository that has main as the main branch. export ST2_PACKS_DEV to point to the folder where you create the new pack before starting up docker-compose. Then run:

st2 run packs.get pack=test_pack

Expected Results

I would expect something like this as output:

st2 run packs.get pack=test_pack
.
id: 66a285f3d8efba08aebc802b
action.ref: packs.get
context.user: st2admin
parameters:
  pack: test_pack
status: succeeded
start_timestamp: Thu, 25 Jul 2024 17:05:55 UTC
end_timestamp: Thu, 25 Jul 2024 17:05:55 UTC
result:
  exit_code: 0
  result:
    git_status: null
    pack:
      author: jpavlav
      contributors:
      - Justin Palmer
      dependencies:
      - core
      description: Pack for testing cuz
      email: [email protected]
      keywords:
      - testing
      name: test_pack
      python_versions:
      - '3'
      ref: test_pack
      version: 0.0.1
  stderr: ''
  stdout: ''

Actual Results

.
id: 66a285e4d8efba08aebc8028
action.ref: packs.get
context.user: st2admin
parameters:
  pack: test_pack
status: failed
start_timestamp: Thu, 25 Jul 2024 17:05:40 UTC
end_timestamp: Thu, 25 Jul 2024 17:05:41 UTC
result:
  exit_code: 1
  result: None
  stderr: "Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/python_runner/python_action_wrapper.py", line 395, in <module>
    obj.run()
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/python_runner/python_action_wrapper.py", line 214, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/packs/actions/pack_mgmt/get_installed.py", line 73, in run
    ahead_behind = repo.git.rev_list(
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/git/cmd.py", line 739, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/git/cmd.py", line 1315, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/opt/stackstorm/st2/lib/python3.8/site-packages/git/cmd.py", line 1110, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git rev-list --left-right --count HEAD...origin/master
  stderr: 'fatal: ambiguous argument 'HEAD...origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]''
"
  stdout: ''

This is caused by this line. There is an assumption that the main branch is master, but this is likely to become less and less common over time.

It should be easy enough to fix, but just updating the action to include a branch_name or main_branch parameter and then turning the argument into a format string that includes the input from the user. Plus, it might be nice to actually catch this error and provide some better feedback about why it failed.

jpavlav added a commit to jpavlav/st2 that referenced this issue Jul 25, 2024
Addresses StackStorm#6225. This should allow users to specify a branch when using
the `packs.get` command. This addresses the assumption in the code that
the primary branch of a git repository corresponding to an action is
`master`.

* Add `branch` parameter to `get.yaml`. Default to `master` to maintain
current functionality/expectations.
* Update `run` in `pack_mgmt.get_install.py`. Now accepts `branch` param
and uses an `fstring` to represent the in `git rev list`.
nzlosh pushed a commit that referenced this issue Sep 9, 2024
* Fix `packs.get` action

Addresses #6225. This should allow users to specify a branch when using
the `packs.get` command. This addresses the assumption in the code that
the primary branch of a git repository corresponding to an action is
`master`.

* Add `branch` parameter to `get.yaml`. Default to `master` to maintain
current functionality/expectations.
* Update `run` in `pack_mgmt.get_install.py`. Now accepts `branch` param
and uses an `fstring` to represent the in `git rev list`.

* Update Changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant