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: 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.17 - name: go info run: | go version go env # cache - name: cache uses: actions/cache@v1 with: path: vendor key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: | ${{ runner.os }}-go- # vendor - name: vendor run: | make vendor # test - name: tests run: | make test # git status - name: git status run: git status # build - name: build if: startsWith(github.ref, 'refs/tags/') == false run: | make snapshot # publish - name: publish if: startsWith(github.ref, 'refs/tags/') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REF: ${{ github.ref }} run: | make 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 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 tags: | cloudb0x/nabarr:${{ steps.dockertag.outputs.replaced }} # cleanup - name: cleanup run: | rm -f ${HOME}/.docker/config.json