From cc6689ac3a112227689fd97f2385854a0d39b12d Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Sat, 11 May 2019 22:40:11 +0100 Subject: [PATCH] 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 --- .circleci/config.yml | 86 +++++++++++++++++ .golangci.yml | 20 ---- .goreleaser.yml | 17 ++-- .travis.yml | 49 ---------- wizard.sh | 215 +++++++++---------------------------------- 5 files changed, 135 insertions(+), 252 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 .golangci.yml delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..93c6eba4 --- /dev/null +++ b/.circleci/config.yml @@ -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]+)*(-.*)*/ diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 20ad14f9..00000000 --- a/.golangci.yml +++ /dev/null @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml index 6ac6663a..44dcb83b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -35,15 +35,13 @@ build: - goos: solaris goarch: arm -archive: - name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" - format: tar.gz - format_overrides: - - goos: windows - format: zip - -release: - disable: true +archives: + - + name_template: "{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}-{{ .ProjectName }}" + format: tar.gz + format_overrides: + - goos: windows + format: zip dockers: - @@ -53,6 +51,5 @@ dockers: image_templates: - "filebrowser/filebrowser:latest" - "filebrowser/filebrowser:{{ .Tag }}" - skip_push: true extra_files: - .docker.json diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 16b4d3c4..00000000 --- a/.travis.yml +++ /dev/null @@ -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 diff --git a/wizard.sh b/wizard.sh index 21dc0662..c3641917 100755 --- a/wizard.sh +++ b/wizard.sh @@ -1,95 +1,19 @@ -#!/bin/sh +#!/usr/bin/env sh set -e untracked="(untracked)" REPO=$(cd $(dirname $0); pwd) -LINT="false" -BUILD="false" -PUSH_LATEST="false" +COMMIT_SHA=$(git rev-parse --short HEAD) +ASSETS="false" +BINARY="false" RELEASE="" debugInfo () { - echo "Repo: $REPO" - echo "Will lint: $LINT" - echo "Will build: $BUILD" - echo "Will 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 + echo "Repo: $REPO" + echo "Build assets: $ASSETS" + echo "Build binary: $BINARY" + echo "Release: $RELEASE" } updateVersion () { @@ -100,79 +24,31 @@ updateVersion () { sed -i.bak "s|$from|$to|g" $REPO/version/version.go } +buildAssets () { + cd $REPO + rm -rf frontend/dist + rm -f http/rice-box.go + + cd $REPO/frontend + npm install + npm run build +} + buildBinary () { + if ! [ -x "$(command -v rice)" ]; then + go install github.com/GeertJohan/go.rice/rice + fi + + cd $REPO/http + rm -rf rice-box.go + rice embed-go + cd $REPO - go get -v ./... updateVersion $untracked "($COMMIT_SHA)" - echo "Build CLI" - CGO_ENABLED=0 go build -a -o filebrowser + 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 - fi; - - if [ -f "http/rice-box.go" ]; then - rm -f http/rice-box.go - fi; - - if [ "$(command -v git)" != "" ]; then - COMMIT_SHA="$(git rev-parse HEAD | cut -c1-8)" - else - COMMIT_SHA="untracked" - fi - - $(command -v winpty) docker run --rm -it \ - -u "$(id -u)" \ - -v /$(pwd):/src:z \ - -w //src \ - -e COMMIT_SHA=$COMMIT_SHA \ - -e HOME="//tmp" \ - -e GOPATH=//tmp/gopath \ - filebrowser/dev \ - sh -c "./wizard.sh -b" - - else - buildAssets - buildBinary - fi -} - release () { cd $REPO @@ -229,26 +105,27 @@ release () { } usage() { - echo "Usage: $0 [-l] [-b] [-p] [-r ]" 1>&2; + echo "Usage: $0 [-a] [-c] [-b] [-r ]" 1>&2; exit 1; } DEBUG="false" -while getopts "pdlbr:" o; do +while getopts "bacr:d" o; do case "${o}" in - l) - LINT="true" - ;; b) - BUILD="true" + ASSETS="true" + BINARY="true" + ;; + a) + ASSETS="true" + ;; + c) + BINARY="true" ;; r) RELEASE=${OPTARG} ;; - p) - PUSH_LATEST="true" - ;; d) DEBUG="true" ;; @@ -263,22 +140,14 @@ if [ "$DEBUG" = "true" ]; then debugInfo fi -if [ "$LINT" = "true" ]; then - lint +if [ "$ASSETS" = "true" ]; then + buildAssets fi -if [ "$BUILD" = "true" ]; then - build -fi - -if [ "$PUSH_LATEST" = "true" ]; then - dockerPushLatest +if [ "$BINARY" = "true" ]; then + buildBinary fi if [ "$RELEASE" != "" ]; then - if [ "$CI" = "true" ]; then - ciRelease - else - release $RELEASE - fi + release $RELEASE fi