diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index da9e086..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,50 +0,0 @@ -version: 2 -jobs: - lint: - docker: - - image: golangci/golangci-lint:v1.30 - steps: - - checkout - - run: golangci-lint run -v - build: - docker: - - image: circleci/golang:1.14 - steps: - - checkout - - run: go build main.go - release: - executor: - - name: go/default - - tag: '1.15' - steps: - - checkout - - go/load-cache - - go/mod-download - - go/save-cache - - run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - - run: curl -sL https://git.io/goreleaser | bash - - run: docker logout -orbs: - go: circleci/go@1.3.1 -workflows: - version: 2 - build-workflow: - jobs: - - lint: - filters: - tags: - only: /.*/ - - build: - filters: - tags: - only: /.*/ - - release: - context: deploy - requires: - - build - - lint - filters: - tags: - only: /^v.*/ - branches: - ignore: /.*/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0307a77 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +# Used as inspiration: https://github.com/mvdan/github-actions-golang + +name: Tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + strategy: + # Default is true, cancels jobs for other platforms in the matrix if one fails + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + go: [ '1.15' ] + + runs-on: ${{ matrix.os }} + + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Print Go version and environment + id: vars + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env + echo "::set-output name=go_cache::$(go env GOCACHE)" + + - name: Cache the build cache + uses: actions/cache@v2 + with: + path: ${{ steps.vars.outputs.go_cache }} + key: ${{ runner.os }}-${{ matrix.go }}-go-ci-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-${{ matrix.go }}-go-ci + + - name: Get dependencies + run: go get -v -t -d ./... + + # To ensure the project compiles, and not just its tests are passing + - name: Build webdav + working-directory: . + env: + CGO_ENABLED: 0 + run: go build -trimpath -ldflags="-w -s" -v + + - name: Run tests + run: go test -v -race ./... + + golangci-lint: + name: runner / golangci-lint + runs-on: ubuntu-latest + steps: + - name: Checkout code into the Go module directory + uses: actions/checkout@v2 + + - name: Run golangci-lint + uses: reviewdog/action-golangci-lint@v1 + with: + github_token: ${{ secrets.github_token }} + + goreleaser-check: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + - uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: check + env: + TAG: ${{ steps.vars.outputs.version_tag }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fcb56ec --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,78 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + +jobs: + release: + name: Release + strategy: + matrix: + os: [ ubuntu-latest ] + go: [ '1.15' ] + runs-on: ${{ matrix.os }} + + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} + + - name: Checkout code + uses: actions/checkout@v2 + + # So GoReleaser can generate the changelog properly + - name: Unshallowify the repo clone + run: git fetch --prune --unshallow + + # https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 + - name: Print Go version and environment + id: vars + run: | + printf "Using go at: $(which go)\n" + printf "Go version: $(go version)\n" + printf "\n\nGo environment:\n\n" + go env + printf "\n\nSystem environment:\n\n" + env + echo "::set-output name=short_sha::$(git rev-parse --short HEAD)" + echo "::set-output name=go_cache::$(go env GOCACHE)" + + # Parse semver + TAG=${GITHUB_REF/refs\/tags\//} + SEMVER_RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z\.-]*\)' + TAG_MAJOR=`echo ${TAG#v} | sed -e "s#$SEMVER_RE#\1#"` + TAG_MINOR=`echo ${TAG#v} | sed -e "s#$SEMVER_RE#\2#"` + TAG_PATCH=`echo ${TAG#v} | sed -e "s#$SEMVER_RE#\3#"` + TAG_SPECIAL=`echo ${TAG#v} | sed -e "s#$SEMVER_RE#\4#"` + echo "::set-output name=tag_major::${TAG_MAJOR}" + echo "::set-output name=tag_minor::${TAG_MINOR}" + echo "::set-output name=tag_patch::${TAG_PATCH}" + echo "::set-output name=tag_special::${TAG_SPECIAL}" + + - name: Cache the build cache + uses: actions/cache@v2 + with: + path: ${{ steps.vars.outputs.go_cache }} + key: ${{ runner.os }}-go${{ matrix.go }}-release-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go${{ matrix.go }}-release + + - name: Docker Login + if: success() && startsWith(github.ref, 'refs/tags/v') + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin + + # GoReleaser will take care of publishing those artifacts into the release + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 669222e..de21ac0 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,6 +9,8 @@ before: build: main: main.go binary: webdav + flags: + - -trimpath ldflags: - -s -w -X github.com/hacdias/webdav/cmd.version={{.Version}} goos: diff --git a/README.md b/README.md index e72a328..e4b934d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # webdav -[![Build](https://img.shields.io/circleci/project/github/hacdias/webdav/master.svg?style=flat-square)](https://circleci.com/gh/hacdias/webdav) +![Build](https://github.com/hacdias/webdav/workflows/Tests/badge.svg) [![Go Report Card](https://goreportcard.com/badge/github.com/hacdias/webdav?style=flat-square)](https://goreportcard.com/report/hacdias/webdav) [![Version](https://img.shields.io/github/release/hacdias/webdav.svg?style=flat-square)](https://github.com/hacdias/webdav/releases/latest) [![Docker Pulls](https://img.shields.io/docker/pulls/hacdias/webdav)](https://hub.docker.com/r/hacdias/webdav)