chore: use circle ci (#725)

Former-commit-id: 3f2b9bf4d651e626e7658849fd0f1caefa4cbe1b [formerly 978d6c75dab9f724c7aff2a31cc3d3d0bb5e84d0] [formerly 4df409b8627f55ec6fee20f0698e7a2b06380f6d [formerly d60b3ebb28179b2d928e695bec7ccbd7494ef4e1]]
Former-commit-id: 24fec7fe931aaecf3fa91d9e9050c16c49909cd9 [formerly dbfae033cad45b7139de0238ea656e74e727f3e5]
Former-commit-id: a3fddbb4692b968e481ed7ffe3065b635aca2df7
pull/726/head
Henrique Dias 2019-05-11 22:40:11 +01:00 committed by GitHub
parent 3ab225a101
commit cc6689ac3a
5 changed files with 135 additions and 252 deletions

86
.circleci/config.yml Normal file
View File

@ -0,0 +1,86 @@
version: 2
jobs:
lint:
docker:
- image: golangci/golangci-lint:v1.16
steps:
- checkout
- run: golangci-lint run -v -D errcheck
build-node:
docker:
- image: circleci/node
steps:
- checkout
- run:
name: "Pull Submodules"
command: |
git submodule init
git submodule update --remote
- run:
name: "Build"
command: ./wizard.sh -a
- persist_to_workspace:
root: .
paths:
- '*'
build-go:
docker:
- image: circleci/golang
steps:
- attach_workspace:
at: '~/project'
- run:
name: "Compile"
command: ./wizard.sh -c
- persist_to_workspace:
root: .
paths:
- '*'
docker-latest:
docker:
- image: docker
steps:
- attach_workspace:
at: '~/project'
- setup_remote_docker
- run: docker build -t filebrowser/filebrowser .
- run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- run: docker push filebrowser/filebrowser
- run: docker logout
- persist_to_workspace:
root: .
paths:
- '*'
release:
docker:
- image: circleci/golang:1.10
steps:
- attach_workspace:
at: '~/project'
- run: curl -sL https://git.io/goreleaser | bash
workflows:
version: 2
build-workflow:
jobs:
- lint
- build-node
- build-go:
requires:
- build-node
- lint
- docker-latest:
context: deploy
requires:
- build-go
filters:
branches:
only: master
- release:
context: deploy
requires:
- build-go
filters:
branches:
ignore: /.*/
tags:
only: /v[0-9]+(\.[0-9]+)*(-.*)*/

View File

@ -1,20 +0,0 @@
run:
deadline: 5m
linters:
enable:
- deadcode
- govet
- ineffassign
- interfacer
- maligned
- megacheck
- structcheck
- unconvert
- varcheck
enable-all: false
disable-all: true
# presets:
# - bugs
# - unused
fast: false

View File

@ -35,16 +35,14 @@ build:
- goos: solaris - goos: solaris
goarch: arm goarch: arm
archive: archives:
-
name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}"
format: tar.gz format: tar.gz
format_overrides: format_overrides:
- goos: windows - goos: windows
format: zip format: zip
release:
disable: true
dockers: dockers:
- -
goos: linux goos: linux
@ -53,6 +51,5 @@ dockers:
image_templates: image_templates:
- "filebrowser/filebrowser:latest" - "filebrowser/filebrowser:latest"
- "filebrowser/filebrowser:{{ .Tag }}" - "filebrowser/filebrowser:{{ .Tag }}"
skip_push: true
extra_files: extra_files:
- .docker.json - .docker.json

View File

@ -1,49 +0,0 @@
os: linux
services: docker
language: go
go:
- 1.12.x
install: skip
addons:
apt:
packages:
- pass
env:
global:
- USE_DOCKER="true"
- GO111MODULE=on
stages:
- lint
- build
- release
cache:
directories:
- http/rice-box.go
jobs:
include:
- stage: lint
script: ./wizard.sh -l
- stage: build
script: ./wizard.sh -b
deploy:
provider: script
skip_cleanup: true
script: ./wizard.sh -p
on:
tags: false
repo: filebrowser/filebrowser
branch: master
- stage: release
script: ./wizard.sh -r "$TRAVIS_TAG"
if: tag IS present
deploy:
provider: releases
skip_cleanup: true
api_key:
secure: GCURbl9xmjOmeNc7cYSvfSwbEp46cacWmJRczcsU6rQa0aWqzjELYdyIsl6HWW+o0dzuZvbWRD6muxYqIud92oPLYDuXSnra9tM3mCjswrjiPCJ57bksWkSPBfFQcxIyB6c3o+A/FMnX3nnSE/2r5HYZnPNFbEcBbC7WSgwx9ejXUuyWn1PUFK9YQWANdl6J7b7EKsk+9MxS9Pmw6M2ycBwX8ScUQdofkUPvR/nqlXISm+3hs30VubqQi9Ha6DM9Bw3aFK3/Ts/ujCOxP1ZoMCBZ6tfnaQOElIG96WTwnt77eDYlZezBOLym3Z18iif+Qny+XndFKDbexaiUT06VlWFXCKtt3iLs6HJwRcjmiHmB0Z3v+W4cKPl3cEyxxrU2aal54k1PBhU+5L0Xc8ileKbDMYg5tps88zWHNefeZVfaxYSVrmUHkuygMe481oaBLacDXTxs4t6XEpStREuLmvx9NLTwTFAbWjMNM0PqlueDMxO4bdwNvzXg/TcKLWV9FezqAlre8lFNZK5wX6lKFVSZ3hFjxCfwrJL2cPwg5A8Yd5EOC4Nh81WdgYuFGOxZzMAoSJlaVRvQS1trCUP/++ONnDep3ExSxvw4B7vijGZWeXUhrOMiPQHXu+t6BnrlnDjQ4gi44QTW0y/iM2WC2DBKfgYjAKwyHx13hFrmOCg=
file: "dist/*.*"
file_glob: true
on:
repo: filebrowser/filebrowser
all_branches: true
tags: true

205
wizard.sh
View File

@ -1,95 +1,19 @@
#!/bin/sh #!/usr/bin/env sh
set -e set -e
untracked="(untracked)" untracked="(untracked)"
REPO=$(cd $(dirname $0); pwd) REPO=$(cd $(dirname $0); pwd)
LINT="false" COMMIT_SHA=$(git rev-parse --short HEAD)
BUILD="false" ASSETS="false"
PUSH_LATEST="false" BINARY="false"
RELEASE="" RELEASE=""
debugInfo () { debugInfo () {
echo "Repo: $REPO" echo "Repo: $REPO"
echo "Will lint: $LINT" echo "Build assets: $ASSETS"
echo "Will build: $BUILD" echo "Build binary: $BINARY"
echo "Will release: $RELEASE" echo "Release: $RELEASE"
echo "Will push latest docker: $PUSH_LATEST"
echo "Use Docker: $USE_DOCKER"
echo "Is CI: $CI"
}
dockerLogin () {
if [ "$CI" = "true" ]; then
gpg --batch --gen-key <<-EOF
%echo Generating a standard key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Meshuggah Rocks
Name-Email: meshuggah@example.com
Expire-Date: 0
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
key=$(gpg --no-auto-check-trustdb --list-secret-keys | grep ^sec | cut -d/ -f2 | cut -d" " -f1)
pass init $key
if [ "$(command -v docker-credential-pass)" = "" ]; then
docker run --rm -itv /usr/local/bin:/src filebrowser/dev sh -c "cp /go/bin/docker-credential-pass /src"
fi
echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin
fi
}
dockerLogout () {
if [ "$CI" = "true" ]; then
docker logout
fi
}
dockerPushLatest () {
docker build -t filebrowser/filebrowser .
dockerLogin
docker push filebrowser/filebrowser
dockerLogout
}
dockerPushTag () {
dockerLogin
for tag in `echo $(docker images filebrowser/filebrowser* | awk -F ' ' '{print $1 ":" $2}') | cut -d ' ' -f2-`; do
if [ "$tag" = "REPOSITORY:TAG" ]; then break; fi
docker push $tag
done
dockerLogout
}
installRice () {
if ! [ -x "$(command -v rice)" ]; then
go get github.com/GeertJohan/go.rice/rice
fi
}
buildAssets () {
installRice
cd $REPO/frontend
if [ -d "dist" ]; then
rm -rf dist/*
fi;
yarn install
yarn build
echo "Run rice"
cd $REPO/http
rice embed-go
} }
updateVersion () { updateVersion () {
@ -100,77 +24,29 @@ updateVersion () {
sed -i.bak "s|$from|$to|g" $REPO/version/version.go sed -i.bak "s|$from|$to|g" $REPO/version/version.go
} }
buildBinary () { buildAssets () {
cd $REPO cd $REPO
go get -v ./...
updateVersion $untracked "($COMMIT_SHA)"
echo "Build CLI"
CGO_ENABLED=0 go build -a -o filebrowser
updateVersion "($COMMIT_SHA)" $untracked
}
lint () {
cd $REPO
if [ "$USE_DOCKER" != "" ]; then
$(command -v winpty) docker run --rm -itv "/$(pwd)://src" -w "//src" filebrowser/dev sh -c "\
go get -v ./... && \
golangci-lint run -v"
else
golangci-lint run -v
fi
}
ciRelease () {
docker run --rm -t \
-v $(pwd):/src \
-w /src \
-v /var/run/docker.sock:/var/run/docker.sock \
filebrowser/dev \
sh -c "\
go get ./... && \
goreleaser \
"
dockerPushTag
}
build () {
cd $REPO
if [ -d http/"rice-box.go" ]; then
rm -rf http/rice-box.go
fi
if [ "$USE_DOCKER" != "" ]; then
if [ -d "frontend/dist" ]; then
rm -rf frontend/dist rm -rf frontend/dist
fi;
if [ -f "http/rice-box.go" ]; then
rm -f http/rice-box.go rm -f http/rice-box.go
fi;
if [ "$(command -v git)" != "" ]; then cd $REPO/frontend
COMMIT_SHA="$(git rev-parse HEAD | cut -c1-8)" npm install
else npm run build
COMMIT_SHA="untracked" }
buildBinary () {
if ! [ -x "$(command -v rice)" ]; then
go install github.com/GeertJohan/go.rice/rice
fi fi
$(command -v winpty) docker run --rm -it \ cd $REPO/http
-u "$(id -u)" \ rm -rf rice-box.go
-v /$(pwd):/src:z \ rice embed-go
-w //src \
-e COMMIT_SHA=$COMMIT_SHA \
-e HOME="//tmp" \
-e GOPATH=//tmp/gopath \
filebrowser/dev \
sh -c "./wizard.sh -b"
else cd $REPO
buildAssets updateVersion $untracked "($COMMIT_SHA)"
buildBinary go build -a -o filebrowser
fi updateVersion "($COMMIT_SHA)" $untracked
} }
release () { release () {
@ -229,26 +105,27 @@ release () {
} }
usage() { usage() {
echo "Usage: $0 [-l] [-b] [-p] [-r <string>]" 1>&2; echo "Usage: $0 [-a] [-c] [-b] [-r <string>]" 1>&2;
exit 1; exit 1;
} }
DEBUG="false" DEBUG="false"
while getopts "pdlbr:" o; do while getopts "bacr:d" o; do
case "${o}" in case "${o}" in
l)
LINT="true"
;;
b) b)
BUILD="true" ASSETS="true"
BINARY="true"
;;
a)
ASSETS="true"
;;
c)
BINARY="true"
;; ;;
r) r)
RELEASE=${OPTARG} RELEASE=${OPTARG}
;; ;;
p)
PUSH_LATEST="true"
;;
d) d)
DEBUG="true" DEBUG="true"
;; ;;
@ -263,22 +140,14 @@ if [ "$DEBUG" = "true" ]; then
debugInfo debugInfo
fi fi
if [ "$LINT" = "true" ]; then if [ "$ASSETS" = "true" ]; then
lint buildAssets
fi fi
if [ "$BUILD" = "true" ]; then if [ "$BINARY" = "true" ]; then
build buildBinary
fi
if [ "$PUSH_LATEST" = "true" ]; then
dockerPushLatest
fi fi
if [ "$RELEASE" != "" ]; then if [ "$RELEASE" != "" ]; then
if [ "$CI" = "true" ]; then
ciRelease
else
release $RELEASE release $RELEASE
fi fi
fi