Skip to content

Commit

Permalink
Add version scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Gergely Bekesi committed Jun 7, 2019
1 parent f549c69 commit 0d6d660
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
104 changes: 104 additions & 0 deletions _scripts/set_version.go
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)
}
}
20 changes: 20 additions & 0 deletions _scripts/set_version.sh
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
4 changes: 3 additions & 1 deletion bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ app:
envs:
- RELEASE_VERSION: 0.0.1
- BIN_NAME: bitrise-plugins-service
- OSX_BIN_NAME: bitrise-plugins-service-Darwin-x86_64
- LINUX_BIN_NAME: bitrise-plugins-service-Linux-x86_64

workflows:
# ----------------------------------------------------------------
Expand Down Expand Up @@ -169,7 +171,7 @@ workflows:
go get github.com/bitrise-io/go-utils/fileutil
go run _scripts/set_version.go \
--src "https://github.com/bitrise-core/bitrise-plugins-service" \
--src "https://github.com/bitrise-io/bitrise-plugins-service" \
--version "$RELEASE_VERSION" \
--osx_bin "$OSX_BIN_NAME" \
--linux_bin "$LINUX_BIN_NAME"

0 comments on commit 0d6d660

Please sign in to comment.