github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/.circleci/config.yml (about)

     1  version: 2.1
     2  commands:
     3    download_dependencies:
     4      description: "download dependencies including test dependencies"
     5      parameters:
     6        test:
     7          type: boolean
     8          default: false
     9      steps:
    10        - run:
    11            name: download dependencies
    12            command: |
    13              n=0
    14              until [ $n -ge 5 ]
    15              do
    16                  go mod download && break
    17                  n=$[$n+1]
    18                  sleep 1
    19              done
    20              <<# parameters.test >>
    21              # test dependencies
    22              go get -u gotest.tools/gotestsum gotest.tools/icmd github.com/logrusorgru/aurora
    23              <</ parameters.test >>
    24  
    25    prepare_directory_layout:
    26      description: "prepare directory layout to run tests"
    27      parameters:
    28        dir:
    29          type: string
    30          default: "/usr/share/testresults"
    31      steps:
    32        - run:
    33            name: Prepare directory layout
    34            command: |
    35               mkdir -p <<parameters.dir>>
    36  
    37    build_statically_linked_binary:
    38      description: "builds a statically linked binary"
    39      parameters:
    40        target:
    41          type: string
    42          default: "./dist/swagger-musl"
    43      steps:
    44        - run:
    45            name: Build statically linked binary
    46            command: |
    47              rm -rf dist
    48              mkdir -p dist
    49              LDFLAGS="-s -w -linkmode external -extldflags \"-static\""
    50              LDFLAGS="$LDFLAGS -X github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/cmd/swagger/commands.Commit=${CIRCLE_SHA1}"
    51              LDFLAGS="$LDFLAGS -X github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/cmd/swagger/commands.Version=${CIRCLE_TAG-dev}"
    52              go build -o <<parameters.target>> -ldflags "$LDFLAGS" -a  ./cmd/swagger
    53  
    54  workflows:
    55    version: 2
    56    weekly:
    57      triggers:
    58        - schedule:
    59            cron: "0 0 * * 6"
    60            filters:
    61              branches:
    62                only:
    63                  - master
    64      jobs:
    65        - debian_builder
    66        - alpine_builder
    67  
    68    build_and_test:
    69      jobs:
    70        - lint
    71        - build
    72  
    73        - test:
    74            requires:
    75              - lint
    76              - build
    77            filters:
    78              tags:
    79                only: /^v.*/
    80  
    81        - codegen_tests:
    82            requires:
    83              - lint
    84              - build
    85            filters:
    86              tags:
    87                only: /^v.*/
    88  
    89        - canary_tests:
    90            filters:
    91              tags:
    92                only: /^v.*/
    93            requires:
    94              - lint
    95              - build
    96  
    97        - publish_dev:
    98            requires:
    99              - test
   100              - codegen_tests
   101              - canary_tests
   102            filters:
   103              branches:
   104                only:
   105                  - master
   106  
   107        - publish_release:
   108            requires:
   109              - test
   110              - codegen_tests
   111              - canary_tests
   112            filters:
   113              tags:
   114                only: /^v.*/
   115              branches:
   116                ignore: /.*/
   117  
   118        - publish_release_docker:
   119            requires:
   120              - test
   121              - codegen_tests
   122              - canary_tests
   123            filters:
   124              tags:
   125                only: /^v.*/
   126              branches:
   127                ignore: /.*/
   128  
   129  jobs:
   130    lint:
   131      docker:
   132        - image: goswagger/builder:debian
   133      steps:
   134        - checkout
   135        - restore_cache:
   136            keys:
   137              - go-mod-v1-{{ checksum "go.sum" }}
   138        - run:
   139            name: Install golangci-lint
   140            command: go get github.com/golangci/golangci-lint/cmd/golangci-lint@latest
   141        - run:
   142            name: Run linting
   143            command: golangci-lint run --timeout 2m --new-from-rev master
   144            no_output_timeout: 2m
   145  
   146    build:
   147      docker:
   148        - image: goswagger/builder:debian
   149      steps:
   150        - checkout
   151  
   152        - restore_cache:
   153            keys:
   154              - go-mod-v1-{{ checksum "go.sum" }}
   155  
   156        - download_dependencies:
   157            test: true
   158  
   159        - save_cache:
   160            key: go-mod-v1-{{ checksum "go.sum" }}
   161            paths:
   162              - "/go/pkg/mod"
   163  
   164        - prepare_directory_layout
   165  
   166        - run:
   167            name: Build binary
   168            command: ./hack/build-docker.sh --circleci
   169  
   170    test:
   171      docker:
   172        - image: goswagger/builder:debian
   173      steps:
   174        - checkout
   175        - restore_cache:
   176            keys:
   177              - go-mod-v1-{{ checksum "go.sum" }}
   178  
   179        - download_dependencies:
   180            test: true
   181  
   182        - save_cache:
   183            key: go-mod-v1-{{ checksum "go.sum" }}
   184            paths:
   185              - "/go/pkg/mod"
   186  
   187        - prepare_directory_layout:
   188            dir: /usr/share/coverage
   189  
   190        - prepare_directory_layout:
   191            dir: /usr/share/testresults
   192  
   193        # - run:
   194        #     name: Run tests with race detection
   195        #     command: go test -race -p 1 -timeout=20m ./...
   196        #     no_output_timeout: 30m
   197  
   198        - run:
   199            name: Run unit tests with code coverage
   200            command: gotestsum --junitfile /usr/share/testresults/go-test-report.xml -f short-verbose -- -p 1 -timeout=20m -coverprofile=coverage.txt -covermode=atomic ./...
   201            no_output_timeout: 30m
   202  
   203        - run:
   204            name: Submit coverage results
   205            command: bash <(curl -s https://codecov.io/bash)
   206  
   207        - run:
   208            name: Save coverage html report
   209            command: |
   210              gocov convert coverage.txt | gocov-html > /usr/share/coverage/coverage-${CIRCLE_BUILD_NUM-"0"}.html
   211  
   212        - store_test_results:
   213            path: /usr/share/testresults
   214  
   215    codegen_tests:
   216      docker:
   217        - image: goswagger/builder:debian
   218      steps:
   219        - checkout
   220  
   221        - restore_cache:
   222            keys:
   223              - go-mod-v1-{{ checksum "go.sum" }}
   224  
   225        - download_dependencies:
   226            test: true
   227  
   228        - save_cache:
   229            key: go-mod-v1-{{ checksum "go.sum" }}
   230            paths:
   231              - "/go/pkg/mod"
   232  
   233        - run: go install ./cmd/swagger
   234  
   235        - run:
   236            name: Test codegen builds
   237            command: go test -v -timeout 30m -parallel 3 hack/codegen_nonreg_test.go -args -fixture-file codegen-fixtures.yaml -skip-models -skip-full-flatten
   238            no_output_timeout: 30m
   239  
   240    canary_tests:
   241      docker:
   242        - image: goswagger/builder:debian
   243      steps:
   244        - checkout
   245  
   246        - restore_cache:
   247            keys:
   248              - go-mod-v1-{{ checksum "go.sum" }}
   249  
   250        - download_dependencies:
   251            test: true
   252  
   253        - save_cache:
   254            key: go-mod-v1-{{ checksum "go.sum" }}
   255            paths:
   256              - "/go/pkg/mod"
   257        - run: go install ./cmd/swagger
   258  
   259        - run:
   260            name: Test canary builds
   261            command: go test -v -timeout 30m hack/codegen_nonreg_test.go -args -fixture-file canary-fixtures.yaml -skip-models -skip-full-flatten -skip-expand
   262            no_output_timeout: 30m
   263  
   264    publish_release:
   265      docker:
   266        - image: goswagger/builder:debian
   267      steps:
   268        - checkout
   269        - run:
   270            name: Prepare environment
   271            command: |
   272              rm -rf dist
   273              mkdir -p dist/bin
   274              mkdir -p dist/build
   275              mkdir -p dist/linux/amd64/usr/bin
   276  
   277        - restore_cache:
   278            keys:
   279              - go-mod-v1-{{ checksum "go.sum" }}
   280  
   281        - download_dependencies
   282  
   283        - save_cache:
   284            key: go-mod-v1-{{ checksum "go.sum" }}
   285            paths:
   286              - "/go/pkg/mod"
   287  
   288        - run:
   289            name: Build binaries
   290            command: |
   291              build_binary() {
   292                LDFLAGS="-s -w -X github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/cmd/swagger/commands.Commit=${CIRCLE_SHA1}"
   293                LDFLAGS="$LDFLAGS -X github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/cmd/swagger/commands.Version=${CIRCLE_TAG-dev}"
   294                gox -ldflags "$LDFLAGS" -tags netgo -output "./dist/bin/{{.Dir}}_{{.OS}}_{{.Arch}}" "$@" ./cmd/swagger
   295              }
   296              build_binary -os="linux darwin windows" -arch="amd64 386"
   297              build_binary -os="linux" -arch="arm64 arm"
   298              build_binary -os="linux" -arch="ppc64le"
   299              cp dist/bin/swagger_linux_amd64 dist/linux/amd64/usr/bin/swagger
   300  
   301        - run:
   302            name: Build packages
   303            command: |
   304              fpm -t deb -p ./dist/build -s dir -C ./dist/linux/amd64 -v ${CIRCLE_TAG:1} -n swagger --license "ASL 2.0" -a x86_64 -m $API_EMAIL --url "https://goswagger.io" usr
   305              fpm -t rpm -p ./dist/build -s dir -C ./dist/linux/amd64 -v ${CIRCLE_TAG:1} -n swagger --license "ASL 2.0" -a x86_64 -m $API_EMAIL --url "https://goswagger.io" usr
   306  
   307        - run:
   308            name: Upload to bintray
   309            command: |
   310              nver="${CIRCLE_TAG:1}"
   311              opts="--retry 10 --retry-delay 5 -u ${API_USERNAME}:${BINTRAY_TOKEN}"
   312              curl ${opts} \
   313                -T ./dist/build/swagger-${nver//-/_}-1.x86_64.rpm \
   314                https://api.bintray.com/content/go-swagger/goswagger-rpm/swagger/${nver}/swagger-${nver//-/_}-1.x86_64.rpm
   315  
   316              curl ${opts} \
   317                -XPOST \
   318                https://api.bintray.com/content/go-swagger/goswagger-rpm/swagger/${nver}/publish
   319  
   320              curl ${opts} \
   321                -T ./dist/build/swagger_${nver}_amd64.deb \
   322                "https://api.bintray.com/content/go-swagger/goswagger-debian/swagger/${nver}/swagger_${nver}_amd64.deb;deb_distribution=ubuntu;deb_component=main;deb_architecture=amd64"
   323  
   324              curl ${opts} \
   325                -XPOST \
   326                https://api.bintray.com/content/go-swagger/goswagger-debian/swagger/${nver}/publish
   327  
   328        - run:
   329            name: Upload to github
   330            command: |
   331              notes="$(cat notes/${CIRCLE_TAG}.md)"
   332              pushd dist/bin
   333              sha1sum * > sha1sum.txt
   334              sha256sum * > sha256sum.txt
   335  
   336              github-release release -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -t $CIRCLE_TAG -d "$notes"
   337              for f in *; do
   338                github-release upload -u $CIRCLE_PROJECT_USERNAME -r $CIRCLE_PROJECT_REPONAME -t $CIRCLE_TAG -n $f -f $f
   339              done
   340  
   341              popd
   342  
   343        - store_artifacts:
   344            path: /usr/share/dist
   345  
   346    publish_release_docker:
   347      docker:
   348        - image: goswagger/builder:alpine
   349      steps:
   350        - checkout
   351        - setup_remote_docker
   352        - restore_cache:
   353            keys:
   354              - go-mod-v1-{{ checksum "go.sum" }}
   355  
   356        - download_dependencies
   357  
   358        - save_cache:
   359            key: go-mod-v1-{{ checksum "go.sum" }}
   360            paths:
   361              - "/go/pkg/mod"
   362  
   363        - build_statically_linked_binary
   364  
   365        - run:
   366            name: Build container
   367            command: |
   368              docker build --pull --build-arg commit_hash="$CIRCLE_SHA1" --build-arg tag_name="${CIRCLE_TAG-dev}" -t quay.io/goswagger/swagger:latest -t quay.io/goswagger/swagger:${CIRCLE_TAG-dev} ./deploybuild
   369  
   370        - run:
   371            name: Publish container
   372            command: |
   373              echo $QUAY_PASS | docker login -u $API_USERNAME --password-stdin https://quay.io
   374              docker push quay.io/goswagger/swagger:${CIRCLE_TAG-dev}
   375              docker push quay.io/goswagger/swagger:latest
   376  
   377        - store_artifacts:
   378            path: /usr/share/dist
   379  
   380    publish_dev:
   381      docker:
   382        - image: goswagger/builder:alpine
   383      steps:
   384        - checkout
   385        - restore_cache:
   386            keys:
   387              - go-mod-v1-{{ checksum "go.sum" }}
   388  
   389        - download_dependencies
   390  
   391        - save_cache:
   392            key: go-mod-v1-{{ checksum "go.sum" }}
   393            paths:
   394              - "/go/pkg/mod"
   395  
   396        - setup_remote_docker
   397  
   398        - build_statically_linked_binary
   399  
   400        - run:
   401            name: Build container
   402            command: |
   403              docker build --pull --build-arg commit_hash="$CIRCLE_SHA1" --build-arg tag_name="dev" -t quay.io/goswagger/swagger:dev .
   404  
   405        - run:
   406            name: Publish container
   407            command: |
   408              echo $QUAY_PASS | docker login -u $API_USERNAME --password-stdin https://quay.io
   409              docker push quay.io/goswagger/swagger:dev
   410  
   411    debian_builder:
   412      docker:
   413        - image: circleci/python
   414      steps:
   415        - checkout
   416        - setup_remote_docker
   417        - run:
   418            name: Build debian builder image
   419            command: |
   420              docker build --pull -t goswagger/builder:debian -f Dockerfile.ci .
   421              echo $DOCKER_PASS | docker login -u $API_USERNAME --password-stdin
   422              docker push goswagger/builder:debian
   423  
   424    alpine_builder:
   425      docker:
   426        - image: circleci/python
   427      steps:
   428        - checkout
   429        - setup_remote_docker
   430        - run:
   431            name: Build alpine builder image
   432            command: |
   433              docker build --pull -t goswagger/builder:alpine -f Dockerfile.alpine.ci .
   434              echo $DOCKER_PASS | docker login -u $API_USERNAME --password-stdin
   435              docker push goswagger/builder:alpine