-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gergely Bekesi
committed
Jun 7, 2019
1 parent
f549c69
commit 0d6d660
Showing
3 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
|
||
"github.com/bitrise-io/go-utils/fileutil" | ||
) | ||
|
||
var ( | ||
pluginSrcURL = "" | ||
version = "" | ||
osxExecutableName = "" | ||
linuxExecutableName = "" | ||
) | ||
|
||
// PluginDefinition ... | ||
type PluginDefinition struct { | ||
Name string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
Executable struct { | ||
OSX string `yaml:"osx"` | ||
Linux string `yaml:"linux"` | ||
} | ||
TriggerEvent string `yaml:"trigger"` | ||
Requirements []Requirement `yaml:"requirements"` | ||
} | ||
|
||
// Requirement ... | ||
type Requirement struct { | ||
Tool string `yaml:"tool"` | ||
MinVersion string `yaml:"min_version"` | ||
MaxVersion string `yaml:"max_version"` | ||
} | ||
|
||
func fatalf(format string, v ...interface{}) { | ||
fmt.Printf(format, v...) | ||
os.Exit(1) | ||
} | ||
|
||
func init() { | ||
flag.StringVar(&pluginSrcURL, "src", "", "plugin git source url") | ||
flag.StringVar(&version, "version", "", "plugin version") | ||
flag.StringVar(&osxExecutableName, "osx_bin", "", "osx binary name") | ||
flag.StringVar(&linuxExecutableName, "linux_bin", "", "linux binary name") | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
fmt.Printf("Inputs:\n") | ||
fmt.Printf(" src: %s\n", pluginSrcURL) | ||
fmt.Printf(" version: %s\n", version) | ||
fmt.Printf(" osx_bin: %s\n", osxExecutableName) | ||
fmt.Printf(" linux_bin: %s\n", linuxExecutableName) | ||
|
||
if pluginSrcURL == "" { | ||
fatalf("plugin git source url (src) not provided") | ||
} | ||
if version == "" { | ||
fatalf("plugin version (version) not provided") | ||
} | ||
if osxExecutableName == "" { | ||
fatalf("osx binary name (osx_bin) not provided") | ||
} | ||
if linuxExecutableName == "" { | ||
fatalf("linux binary name (linux_bin) not provided") | ||
} | ||
|
||
pluginDefinitionPth := "bitrise-plugin.yml" | ||
|
||
bytes, err := fileutil.ReadBytesFromFile(pluginDefinitionPth) | ||
if err != nil { | ||
fatalf("failed to read: %s, error: %s", pluginDefinitionPth, err) | ||
} | ||
|
||
var definition PluginDefinition | ||
|
||
if err := yaml.Unmarshal(bytes, &definition); err != nil { | ||
fatalf("failed to unmarshal plugin definition, error: %s", err) | ||
} | ||
|
||
osxExecutableInstallURL := pluginSrcURL + filepath.Join("/releases/download", version, osxExecutableName) | ||
linuxExecutableInstallURL := pluginSrcURL + filepath.Join("/releases/download", version, linuxExecutableName) | ||
|
||
definition.Executable.OSX = osxExecutableInstallURL | ||
definition.Executable.Linux = linuxExecutableInstallURL | ||
|
||
bytes, err = yaml.Marshal(definition) | ||
if err != nil { | ||
fatalf("failed to marshal plugin definition, error: %s", err) | ||
} | ||
|
||
fmt.Printf("\nPlugin definition:\n") | ||
fmt.Printf("%s\n", string(bytes)) | ||
|
||
if err := fileutil.WriteBytesToFile(pluginDefinitionPth, bytes); err != nil { | ||
fatalf("failed to write plugin definition, error: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
set -x | ||
|
||
version_file_path="$1" | ||
if [ ! -f "$version_file_path" ] ; then | ||
echo " [!] version_file_path not provided, or file doesn't exist at path: $version_file_path" | ||
exit 1 | ||
fi | ||
versionNumber=$next_version | ||
if [[ "$versionNumber" == "" ]] ; then | ||
echo " [!] versionNumber not provided" | ||
exit 1 | ||
fi | ||
|
||
cat >"${version_file_path}" <<EOL | ||
package version | ||
// VERSION ... | ||
const VERSION = "${versionNumber}" | ||
EOL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters