bitrise-io / bitrise-plugins-io

A Terminal / Command Line interface for bitrise.io, to manage your apps on bitrise.io right from your terminal / command line.
6 stars 4 forks source link

Installation does not work properly (missing go.mod) #55

Open ddmytrenko opened 1 month ago

ddmytrenko commented 1 month ago

Hi!

After installing the plugin using (lets call it installation step)

bitrise plugin install https://github.com/bitrise-io/bitrise-plugins-io.git

I cannot basically use it because of missing go.mod. Example command:

bitrise :io auth whoami

Output:

go: go.mod file not found in current directory or any parent directory; see 'go help modules'
/Users/username/.bitrise/plugins/io/src/bitrise-plugin.sh: line 4: /Users/username/.bitrise/plugins/io/src/_tmp/plugin: No such file or directory
Failed to run plugin (io), error: exit status 127

When I run the command from any git repository, I receive a bit different error:

go: cannot find main module, but found .git/config in /Users/username/Development/projects/android-app
    to create a module there, run:
    go mod init
/Users/Dmytro.Dmytrenko@ig.com/.bitrise/plugins/io/src/bitrise-plugin.sh: line 4: /Users/username/.bitrise/plugins/io/src/_tmp/plugin: No such file or directory

So, I tried to run go mod init in plugin directory:

cd /Users/username/.bitrise/plugins/io/src
go mod init

Output:

go: cannot determine module path for source directory /Users/username/.bitrise/plugins/io (outside GOPATH, module path must be specified)

Example usage:
    'go mod init example.com/m' to initialize a v0 or v1 module
    'go mod init example.com/m/v2' to initialize a v2 module

A strange thing. There were no go.mod files in /Users/username/.bitrise/plugins/io/src directory after installation step.

That's why I have also tried to clone the plugin repo manually to /Users/username/.bitrise/plugins/io/src. And if I run any bitrise :io command from that particular directory - it works. If I switch back to the project directory it does not work:

go: cannot find main module, but found .git/config in /Users/username/Development/projects/android-app
    to create a module there, run:
    go mod init

I have both bitrise-cli and go properly installed and set up.

Any ideas on how to fix it?

Thanks in advance! Best regards!

ddmytrenko commented 1 month ago

Ok!

I have found the reason and fixed it locally. Plugin's shell script is wrong.

Current version:

#!/usr/bin/env bash
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
go build -o "$THIS_SCRIPT_DIR/_tmp/plugin"
"$THIS_SCRIPT_DIR/_tmp/plugin" $*

So, in the line 3 we are not in $THIS_SCRIPT_DIR directory. Because the cd command was local for the first $() block. We have to change it explicitely:

#!/usr/bin/env bash
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
go build -C "$THIS_SCRIPT_DIR" -o "./_tmp/plugin"
"$THIS_SCRIPT_DIR/_tmp/plugin" $*

Documentation:

go help build
-C dir
    Change to dir before running the command.
    Any files named on the command line are interpreted after
    changing directories.
    If used, this flag must be the first one in the command line.