erlef / rebar3_hex

Rebar3 Hex library
Apache License 2.0
101 stars 49 forks source link

failing $ rebar3 hex repo auth <repo> generate #157

Closed fenollp closed 4 years ago

fenollp commented 4 years ago

I'm trying to generate a key (to use in CI) but following the readme I get

===> Repo authenticate command requires key I am correctly logged in:

$ rebar3 hex user whoami
hexpm : fenollp (pierrefenoll@gmail.com)
$ DEBUG=1 rebar3 hex repo auth otp_vsn generate
===> Evaluating config script "rebar.config.script"
===> Load global config file /home/pete/.config/rebar3/rebar.config
===> 22.0.1 satisfies the requirement for minimum OTP version 18
===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: [{hex,repo}]
===> Provider: {hex,repo}
===> Repo authenticate command requires key
$ rebar3 plugins list |\grep hex
rebar3_hex (6.9.3)
$ rebar3 version
rebar 3.13.1 on Erlang/OTP 22 Erts 10.4

Note: on https://www.rebar3.org/docs/hex-package-management the first command doesn't seem to exist:

$ DEBUG=1 rebar3 hex config username
===> Evaluating config script "rebar.config.script"
===> Load global config file /home/pete/.config/rebar3/rebar.config
===> 22.0.1 satisfies the requirement for minimum OTP version 18
===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: []
===> Command config not found in namespace hex

Also when cut-ting a release I have a crash:

DEBUG=1 rebar3 hex cut -i minor
===> Evaluating config script "rebar.config.script"
===> Load global config file /home/pete/.config/rebar3/rebar.config
===> 22.0.1 satisfies the requirement for minimum OTP version 18
===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: [{default,app_discovery},
                                                  {default,install_deps},
                                                  {default,lock},
                                                  {hex,cut}]
===> Provider: {default,app_discovery}
===> Provider: {default,install_deps}
===> Verifying dependencies...
===> Provider: {default,lock}
===> Provider: {hex,cut}
===> Using deprecated rebar_utils:vcs_vsn/3. Please upgrade your plugins.
===> sh info:
    cwd: "/home/pete/wefwefwef/otp_vsn.git"
    cmd: git log -n 1 --pretty=format:"%h
" 

===>    opts: [{use_stdout,false},
                       return_on_error,
                       {cd,"/home/pete/wefwefwef/otp_vsn.git"}]

===> Port Cmd: git log -n 1 --pretty=format:"%h
" 
Port Opts: [{cd,"/home/pete/wefwefwef/otp_vsn.git"},
            exit_status,
            {line,16384},
            use_stdio,stderr_to_stdout,hide,eof]

===> sh info:
    cwd: "/home/pete/wefwefwef/otp_vsn.git"
    cmd: git -c color.ui=false log --oneline --no-walk --tags --decorate

===>    opts: [{use_stdout,false},
                       return_on_error,
                       {cd,"/home/pete/wefwefwef/otp_vsn.git"}]

===> Port Cmd: git -c color.ui=false log --oneline --no-walk --tags --decorate
Port Opts: [{cd,"/home/pete/wefwefwef/otp_vsn.git"},
            exit_status,
            {line,16384},
            use_stdio,stderr_to_stdout,hide,eof]

===> sh info:
    cwd: "/home/pete/wefwefwef/otp_vsn.git"
    cmd: git describe --tags --abbrev=0

===>    opts: [{use_stdout,false},
                       return_on_error,
                       {cd,"/home/pete/wefwefwef/otp_vsn.git"}]

===> Port Cmd: git describe --tags --abbrev=0
Port Opts: [{cd,"/home/pete/wefwefwef/otp_vsn.git"},
            exit_status,
            {line,16384},
            use_stdio,stderr_to_stdout,hide,eof]

===> sh info:
    cwd: "/home/pete/wefwefwef/otp_vsn.git"
    cmd: git rev-list HEAD

===>    opts: [{use_stdout,false},
                       {cd,"/home/pete/wefwefwef/otp_vsn.git"},
                       {debug_abort_on_error,
                           "Getting rev-list of git depedency failed in /home/pete/wefwefwef/otp_vsn.git"}]

===> Port Cmd: git rev-list HEAD
Port Opts: [{cd,"/home/pete/wefwefwef/otp_vsn.git"},
            exit_status,
            {line,16384},
            use_stdio,stderr_to_stdout,hide,eof]

===> Creating new tag v2.4.0...
===> sh info:
    cwd: "/home/pete/wefwefwef/otp_vsn.git"
    cmd: git tag v2.4.0

===>    opts: []

===> Port Cmd: git tag v2.4.0
Port Opts: [exit_status,{line,16384},use_stdio,stderr_to_stdout,hide,eof]

===> Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump
===> Uncaught error: function_clause
===> Stack trace to the error location:
[{rebar_app_info,dir,
                 ["/home/pete/wefwefwef/otp_vsn.git"],
                 [{file,"/tmp/cirrus-ci-build/src/rebar_app_info.erl"},
                  {line,443}]},
 {rebar3_hex_publish,publish,8,
                     [{file,"/home/pete/.cache/rebar3/plugins/rebar3_hex/src/rebar3_hex_publish.erl"},
                      {line,154}]},
 {rebar3_hex_cut,do_,4,
                 [{file,"/home/pete/.cache/rebar3/plugins/rebar3_hex/src/rebar3_hex_cut.erl"},
                  {line,110}]},
 {lists,foldl,3,[{file,"lists.erl"},{line,1263}]},
 {rebar_core,do,2,
             [{file,"/tmp/cirrus-ci-build/src/rebar_core.erl"},{line,154}]},
 {rebar_prv_do,do_task,5,
               [{file,"/tmp/cirrus-ci-build/src/rebar_prv_do.erl"},{line,87}]},
 {rebar_core,do,2,
             [{file,"/tmp/cirrus-ci-build/src/rebar_core.erl"},{line,154}]},
 {rebar3,run_aux,2,[{file,"/tmp/cirrus-ci-build/src/rebar3.erl"},{line,182}]}]
===> When submitting a bug report, please include the output of `rebar3 report "your command"`

Report

Rebar3 report
 version 3.13.1
 generated at 2020-04-16T12:33:34+00:00
=================
Please submit this along with your issue at https://github.com/erlang/rebar3/issues (and feel free to edit out private information, if any)
-----------------
Task: rebar3
Entered as:
  rebar3 hex cut -i minor
-----------------
Operating System: x86_64-unknown-linux-gnu
ERTS: Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Root Directory: /home/pete/.bin/builds/otp/22.0.1
Library directory: /home/pete/.bin/builds/otp/22.0.1/lib
-----------------
Loaded Applications:
bbmustache: 1.8.0
certifi: 2.5.1
cf: 0.2.2
common_test: 1.17.3
compiler: 7.4
crypto: 4.5
cth_readable: 1.4.6
dialyzer: 4.0
edoc: 0.11
erlware_commons: 1.3.1
eunit: 2.3.7
eunit_formatters: 0.5.0
getopt: 1.0.1
hipe: 3.19
inets: 7.0.8
kernel: 6.4
providers: 1.8.1
public_key: 1.6.7
relx: 3.33.0
sasl: 3.4
snmp: 5.3
ssl_verify_fun: 1.1.5
stdlib: 3.9
syntax_tools: 2.2
tools: 3.2

-----------------
Escript path: /home/pete/.bin/builds/bin/rebar3
Providers:
  app_discovery as clean compile compile cover ct cut deps dialyzer do docs edoc escriptize eunit fmt get-deps help install install_deps key list lock new owner path pkgs publish release relup repo report repos retire revert search shell state tar tree unlock update upgrade upgrade upgrade user version xref 
fenollp commented 4 years ago

Actually other config commands also fail:

DEBUG=1 rebar3 hex config key
===> Evaluating config script "rebar.config.script"
===> Load global config file /home/pete/.config/rebar3/rebar.config
===> 22.0.1 satisfies the requirement for minimum OTP version 18
===> Expanded command sequence to be run: []
===> Provider: {default,do}
===> Expanded command sequence to be run: []
===> Command config not found in namespace hex

This is from https://github.com/zotonic/hexpub

fenollp commented 4 years ago

I tried clearing ~/.cache/rebar3 no to avail.

fenollp commented 4 years ago

All this seems related to a bad / corrupted install over the years.

My actual issue is publishing in CI. It seems the old trick of

        {
            echo '{username,<<"'${HEX_USERNAME}'">>}.'
            echo '{key,<<"'${HEX_KEY}'">>}.'
        } >~/.hex/hex.config

and rebar3 hex publish <<<y isn't cutting it anymore: it complains about a missing write key. Turns out if I add all the contents of a "working" hex.config file (including a tuple tagged '$write_key') it still doesn't work.

So I'm resorting to the call

rebar3 hex user auth

however I can't get that command to read username & passwords from STDIN:

[{binary,split,[eof,<<"\n">>],[]},
 {rebar3_hex_io,get_password,1,
                [{file,"/root/.cache/rebar3/plugins/rebar3_hex/src/rebar3_hex_io.erl"},
                 {line,69}]},
 {rebar3_hex_user,auth,2,
                  [{file,"/root/.cache/rebar3/plugins/rebar3_hex/src/rebar3_hex_user.erl"},
                   {line,134}]},
 {rebar_core,do,2,
             [{file,"/usr/src/rebar3-src/src/rebar_core.erl"},{line,154}]},
 {rebar_prv_do,do_task,5,
               [{file,"/usr/src/rebar3-src/src/rebar_prv_do.erl"},{line,87}]},
 {rebar_core,do,2,
             [{file,"/usr/src/rebar3-src/src/rebar_core.erl"},{line,154}]},
 {rebar3,run_aux,2,[{file,"/usr/src/rebar3-src/src/rebar3.erl"},{line,182}]},
 {rebar3,main,1,[{file,"/usr/src/rebar3-src/src/rebar3.erl"},{line,66}]}]
starbelly commented 4 years ago

@fenollp Hi, yeah AFAIK config was never implemented, but should be and will open an issue for that. However, let's see if we can't get you past your initial issue which is generating a key to so you can publish in CI. At the moment there's a few bug fixes that need to be released in regards to keys and we will get that out as soon as possible, for the moment I recommend logging into hex.pm (or your private instance) and generating a key there. Copy the key into your CI config (assuming you can pull in variables into your CI env). From there you can simply specify the key in an env var vs setting up a hex config file.

Example:

 env HEX_API_KEY=$MY_API_KEY_VAR rebar3 hex publish -r myrepo
===> Verifying dependencies...
Publishing truecoat 0.4.1 to hexpm
  Description: It gets installed at the factory
  Dependencies:

   ... 

===> Published truecoat 0.4.1
===> Published docs for truecoat 0.4.1

Note the -r switch is only needed if you have multiple repos. If it's only hexpm then the -r switch is not needed.

Does this help?

fenollp commented 4 years ago

Hi! Thanks for the thorough explanation. I'm using the public hex.pm repo. I generated a key by checking all the boxes at https://hex.pm/dashboard/keys and defining a CI secret HEX_API_KEY with the key. But this is still failing: https://github.com/fenollp/otp_vsn/runs/599296685?check_suite_focus=true

===> No write key found for user. Be sure to authenticate first with: rebar3 hex user auth

And I'm having issues running that command in CI.

But then again I should only be needing the generated key, right?

starbelly commented 4 years ago

That is correct, all you should need is the generated key. Makes me think the generated key is not in your env... if I do :

env HEX_API_KEY= rebar3 hex publish then I get the error you are encountering.

I know for myself with github ci I have to access set env vars in my workflow per https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets

fenollp commented 4 years ago

Hell I did not think of that. Thanks!

This is still somehow failing (with the same message): https://github.com/fenollp/otp_vsn/runs/599824172?check_suite_focus=true

This time I generated a key by checking only the "API" checkbox (which also checks Read & Write) and not the second checkbox.

Thank you for your patience :)

starbelly commented 4 years ago

@fenollp No worries :) Yeah, it still seems like the key is not defined. Can you try testing this outside of CI?

starbelly commented 4 years ago

@fenollp Also, as I mentioned to someone else in another issue... I would be remiss if I didn't say that publishing in this way is discouraged by both hex and rebar team. This has been available in hex for a while and recently added to rebar3_hex but this is mostly because people were automating publishing anyway. See #126 for more context. 🙇

starbelly commented 4 years ago

@fenollp Did you ever test this outside of CI?

starbelly commented 4 years ago

@fenollp Closing this issue as stale, but feel free to re-open if need be.