name: Build on: push: branches: - '*' tags: - 'v*' jobs: build: runs-on: ubuntu-latest steps: # dependencies - name: goreleaser uses: goreleaser/goreleaser-action@v2 with: install-only: true - name: goreleaser version run: goreleaser -v - name: task uses: arduino/setup-task@v1 - name: task info run: task --version - name: qemu uses: docker/setup-qemu-action@v1 - name: buildx uses: docker/setup-buildx-action@v1 # checkout - name: checkout uses: actions/checkout@v2 with: fetch-depth: 0 # setup go - name: go uses: actions/setup-go@v1 with: go-version: 1.18 - name: go info run: | go version go env # cache - name: cache-paths id: go-cache-paths run: | echo "::set-output name=go-build::$(go env GOCACHE)" echo "::set-output name=go-mod::$(go env GOMODCACHE)" - name: cache-build uses: actions/cache@v2 with: path: ${{ steps.go-cache-paths.outputs.go-build }} key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} - name: cache-mod uses: actions/cache@v2 with: path: ${{ steps.go-cache-paths.outputs.go-mod }} key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }} - name: cache-task uses: actions/cache@v2 with: path: .task/**/* key: ${{ runner.os }}-go-task # vendor - name: vendor run: | task vendor # test - name: tests run: | task test # git status - name: git status run: git status # build - name: build if: startsWith(github.ref, 'refs/tags/') == false run: | task snapshot # publish - name: publish if: startsWith(github.ref, 'refs/tags/') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} run: | task publish # artifacts - name: artifact_linux uses: actions/upload-artifact@v2-preview with: name: build_linux path: dist/*linux* - name: artifact_darwin uses: actions/upload-artifact@v2-preview with: name: build_darwin path: dist/*darwin* - name: artifact_windows uses: actions/upload-artifact@v2-preview with: name: build_windows path: dist/*windows* # docker login - name: docker login env: DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} run: | echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin # docker build (latest & tag) - name: release tag if: startsWith(github.ref, 'refs/tags/') == true uses: little-core-labs/get-git-tag@v3.0.2 id: releasetag with: tagRegex: "v?(.+)" - name: docker - build release if: startsWith(github.ref, 'refs/tags/') == true uses: docker/build-push-action@v2 with: context: . file: ./docker/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 pull: true push: true cache-from: type=gha cache-to: type=gha,mode=max tags: | cloudb0x/nabarr:${{ steps.releasetag.outputs.tag }} cloudb0x/nabarr:latest # docker build (branch) - name: branch name if: startsWith(github.ref, 'refs/tags/') == false id: branch-name uses: tj-actions/branch-names@v2.2 - name: docker tag if: startsWith(github.ref, 'refs/tags/') == false uses: frabert/replace-string-action@master id: dockertag with: pattern: '[:\.\/]+' string: "${{ steps.branch-name.outputs.current_branch }}" replace-with: '-' flags: 'g' - name: docker - build branch if: startsWith(github.ref, 'refs/tags/') == false uses: docker/build-push-action@v2 with: context: . file: ./docker/Dockerfile platforms: linux/amd64,linux/arm64,linux/arm/v7 pull: true push: true cache-from: type=gha cache-to: type=gha,mode=max tags: | cloudb0x/nabarr:${{ steps.dockertag.outputs.replaced }} # cleanup - name: cleanup run: | rm -f ${HOME}/.docker/config.json