Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from goreleaser/29
Browse files Browse the repository at this point in the history
fixes master
  • Loading branch information
caarlos0 committed Aug 11, 2017
2 parents f6d146f + ab24454 commit 83fb9c4
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -14,3 +14,6 @@ addons:

script:
- make ci

notifications:
email: false
24 changes: 18 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 16 additions & 50 deletions Gopkg.toml
@@ -1,56 +1,22 @@

## Gopkg.toml example (these lines may be deleted)

## "required" lists a set of packages (not projects) that must be included in
## Gopkg.lock. This list is merged with the set of packages imported by the current
## project. Use it when your project needs a package it doesn't explicitly import -
## including "main" packages.
# required = ["github.com/user/thing/cmd/thing"]

## "ignored" lists a set of packages (not projects) that are ignored when
## dep statically analyzes source code. Ignored packages can be in this project,
## or in a dependency.
# ignored = ["github.com/user/project/badpkg"]

## Dependencies define constraints on dependent projects. They are respected by
## dep whether coming from the Gopkg.toml of the current project or a dependency.
# [[dependencies]]
## Required: the root import path of the project being constrained.
# name = "github.com/user/project"
# Gopkg.toml example
#
## Recommended: the version constraint to enforce for the project.
## Only one of "branch", "version" or "revision" can be specified.
# version = "1.0.0"
# branch = "master"
# revision = "abc123"
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
## Optional: an alternate location (URL or import path) for the project's source.
# source = "https://github.com/myfork/package.git"

## Overrides have the same structure as [[dependencies]], but supercede all
## [[dependencies]] declarations from all projects. Only the current project's
## [[overrides]] are applied.
##
## Overrides are a sledgehammer. Use them only as a last resort.
# [[overrides]]
## Required: the root import path of the project being constrained.
# name = "github.com/user/project"
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
## Optional: specifying a version constraint override will cause all other
## constraints on this project to be ignored; only the overriden constraint
## need be satisfied.
## Again, only one of "branch", "version" or "revision" can be specified.
# version = "1.0.0"
# branch = "master"
# revision = "abc123"
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
## Optional: specifying an alternate source location as an override will
## enforce that the alternate location is used for that project, regardless of
## what source location any dependent projects specify.
# source = "https://github.com/myfork/package.git"


# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"

[[dependencies]]
branch = "master"
name = "github.com/goreleaser/goreleaser"
10 changes: 4 additions & 6 deletions goreleaser.yml
@@ -1,5 +1,3 @@
homepage: &homepage https://github.com/goreleaser/godownloader
description: &description Download Go binaries as fast and easily as possible
build:
goos:
- linux
Expand All @@ -25,13 +23,13 @@ brew:
owner: godownloader
name: homebrew-tap
folder: Formula
homepage: *homepage
description: *description
homepage: https://github.com/goreleaser/godownloader
description: Download Go binaries as fast and easily as possible
dependencies:
- git
fpm:
homepage: *homepage
description: *description
homepage: https://github.com/goreleaser/godownloader
description: Download Go binaries as fast and easily as possible
maintainer: Nick Galbreath <nickg@client9.com>
vendor: GoDownloader
formats:
Expand Down
47 changes: 34 additions & 13 deletions main.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"errors"
"flag"
"fmt"
"log"
Expand All @@ -11,6 +12,7 @@ import (
"text/template"

"github.com/goreleaser/goreleaser/config"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/pipeline/defaults"
)

Expand Down Expand Up @@ -65,11 +67,28 @@ func makeName(target string) (string, error) {
return out.String(), err
}

func loadURLs(path string) (*config.Project, error) {
for _, file := range []string{"goreleaser.yml", ".goreleaser.yml"} {
var url = fmt.Sprintf("%s/%s", path, file)
log.Printf("Reading %s", url)
project, err := loadURL(url)
if err == nil {
return project, err
}
}
return nil, fmt.Errorf("goreleaser.yml file not found")
}

var errNotFound = errors.New("404: not found")

func loadURL(file string) (*config.Project, error) {
resp, err := http.Get(file)
if err != nil {
return nil, err
}
if resp.StatusCode == 404 {
return nil, errNotFound
}
p, err := config.LoadReader(resp.Body)

// to make errcheck happy
Expand All @@ -91,13 +110,11 @@ func Load(repo string, file string) (project *config.Project, err error) {
return nil, fmt.Errorf("Need a repo or file")
}
if file == "" {
file = "https://raw.githubusercontent.com/" + repo + "/master/goreleaser.yml"
}

log.Printf("Reading %s", file)
if strings.HasPrefix(file, "http") {
project, err = loadURL(file)
project, err = loadURLs(
fmt.Sprintf("https://raw.githubusercontent.com/%s/master", repo),
)
} else {
log.Printf("Reading %s", file)
project, err = loadFile(file)
}
if err != nil {
Expand All @@ -113,17 +130,21 @@ func Load(repo string, file string) (project *config.Project, err error) {
project.Release.GitHub.Name = path.Base(repo)
}

// set default archive format
if project.Archive.Format == "" {
project.Archive.Format = "tar.gz"
}
var ctx = context.New(*project)
err = defaults.Pipe{}.Run(ctx)
project = &ctx.Config

// set default binary name
if project.Build.Binary == "" {
project.Build.Binary = path.Base(repo)
if len(project.Builds) == 0 {
project.Builds = []config.Build{
{Binary: path.Base(repo)},
}
}
if project.Builds[0].Binary == "" {
project.Builds[0].Binary = path.Base(repo)
}

return project, nil
return project, err
}

func main() {
Expand Down
3 changes: 3 additions & 0 deletions samples/godownloader-goreleaser.sh
Expand Up @@ -69,6 +69,9 @@ is_supported_platform() {
windows/amd64) found=0 ;;

windows/arm64) found=0 ;;
linux/armv6) found=0 ;;
darwin/armv6) found=0 ;;
windows/armv6) found=0 ;;
esac
return $found
}
Expand Down
16 changes: 13 additions & 3 deletions samples/godownloader-hugo.sh
Expand Up @@ -6,12 +6,12 @@ set -e
usage() {
this=$1
cat <<EOF
$this: download go binaries for spf13/hugo
$this: download go binaries for gohugoio/hugo
Usage: $this [-b] bindir [version]
-b sets bindir or installation directory, default "./bin"
[version] is a version number from
https://github.com/spf13/hugo/releases
https://github.com/gohugoio/hugo/releases
If version is missing, then an attempt to find the latest will be found.
Generated by godownloader
Expand Down Expand Up @@ -85,6 +85,16 @@ is_supported_platform() {
dragonfly/386) found=0 ;;

dragonfly/arm64) found=0 ;;
darwin/armv6) found=0 ;;
linux/armv6) found=0 ;;
windows/armv6) found=0 ;;
freebsd/armv6) found=0 ;;
netbsd/armv6) found=0 ;;
openbsd/armv6) found=0 ;;
dragonfly/armv6) found=0 ;;
esac
case "$platform" in
openbsd/armv6) found=1 ;;
esac
return $found
}
Expand Down Expand Up @@ -319,7 +329,7 @@ End of functions from https://github.com/client9/shlib
------------------------------------------------------------------------
EOF

OWNER=spf13
OWNER=gohugoio
REPO=hugo
BINARY=hugo
FORMAT=tar.gz
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_samples.sh
@@ -1,6 +1,6 @@
#!/bin/sh -ex

./godownloader -repo spf13/hugo > samples/godownloader-hugo.sh
./godownloader -repo gohugoio/hugo > samples/godownloader-hugo.sh
./godownloader -repo goreleaser/goreleaser > samples/godownloader-goreleaser.sh
./godownloader -repo client9/misspell > samples/godownloader-misspell.sh
./godownloader -source equinoxio -repo tdewolff/minify > samples/godownloader-minify.sh
Expand Down
7 changes: 4 additions & 3 deletions shell_equinoxio.go
Expand Up @@ -16,9 +16,10 @@ func processEquinoxio(repo string) (string, error) {
project := config.Project{}
project.Release.GitHub.Owner = path.Dir(repo)
project.Release.GitHub.Name = path.Base(repo)
project.Build.Binary = path.Base(repo)
project.Builds = []config.Build{
{Binary: path.Base(repo)},
}
project.Archive.Format = "tgz"

return makeShell(shellEquinoxio, &project)
}

Expand Down Expand Up @@ -78,7 +79,7 @@ execute() {
echo "$PREFIX: installed ${BINDIR}/${BINARY}"
}` + shellfn + `OWNER={{ .Release.GitHub.Owner }}
REPO={{ .Release.GitHub.Name }}
BINARY={{ .Build.Binary }}
BINARY={{ (index .Builds 0).Binary }}
FORMAT={{ .Archive.Format }}
BINDIR=${BINDIR:-./bin}
CHANNEL=stable
Expand Down
19 changes: 10 additions & 9 deletions shell_godownloader.go
Expand Up @@ -78,19 +78,20 @@ is_supported_platform() {
platform=$1
found=1
case "$platform" in
{{- range $goos := $.Build.Goos }}{{ range $goarch := $.Build.Goarch }}
{{- range $goos := (index $.Builds 0).Goos }}{{ range $goarch := (index $.Builds 0).Goarch }}
{{ if not (eq $goarch "arm") }} {{ $goos }}/{{ $goarch }}) found=0 ;;{{ end }}
{{- end }}{{ end }}
{{- if $.Build.Goarm }}
{{- range $goos := $.Build.Goos }}{{ range $goarch := $.Build.Goarch }}{{ range $goarm := $.Build.Goarm }}
{{- if eq $goarch "arm" }} {{ $goos }}/armv{{ $goarm }}) found=0 ;;
{{ end }}
{{- if (index $.Builds 0).Goarm }}
{{- range $goos := (index $.Builds 0).Goos }}{{ range $goarch := (index $.Builds 0).Goarch }}{{ range $goarm := (index $.Builds 0).Goarm }}
{{- if eq $goarch "arm" }}
{{ $goos }}/armv{{ $goarm }}) found=0 ;;
{{- end }}
{{- end }}{{ end }}{{ end }}
{{- end }}
esac
{{- if $.Build.Ignore }}
case "$platform" in
{{- range $ignore := $.Build.Ignore }}
{{- if (index $.Builds 0).Ignore }}
case "$platform" in
{{- range $ignore := (index $.Builds 0).Ignore }}
{{ $ignore.Goos }}/{{ $ignore.Goarch }}{{ if $ignore.Goarm }}v{{ $ignore.Goarm }}{{ end }}) found=1 ;;{{ end }}
esac
{{- end }}
Expand Down Expand Up @@ -149,7 +150,7 @@ adjust_arch() {
` + shellfn + `
OWNER={{ $.Release.GitHub.Owner }}
REPO={{ $.Release.GitHub.Name }}
BINARY={{ .Build.Binary }}
BINARY={{ (index .Builds 0).Binary }}
FORMAT={{ .Archive.Format }}
OS=$(uname_os)
ARCH=$(uname_arch)
Expand Down
7 changes: 4 additions & 3 deletions shell_raw.go
Expand Up @@ -29,9 +29,10 @@ func processRaw(repo string, exe string, nametpl string) (string, error) {
project := config.Project{}
project.Release.GitHub.Owner = path.Dir(repo)
project.Release.GitHub.Name = path.Base(repo)
project.Build.Binary = exe
project.Builds = []config.Build{
{Binary: exe},
}
project.Archive.NameTemplate = name

return makeShell(shellRaw, &project)
}

Expand Down Expand Up @@ -102,7 +103,7 @@ execute() {
` + shellfn + `
OWNER={{ .Release.GitHub.Owner }}
REPO={{ .Release.GitHub.Name }}
BINARY={{ .Build.Binary }}
BINARY={{ (index .Builds 0).Binary }}
BINDIR=${BINDIR:-./bin}
PREFIX="$OWNER/$REPO"
OS=$(uname_os)
Expand Down

0 comments on commit 83fb9c4

Please sign in to comment.