diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1b0534..f7d6925 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ name: Go -on: [push, pull_request] +on: [ push, pull_request ] jobs: build: @@ -17,6 +17,10 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v2 + - name: Unshallow + if: success() && startsWith(github.ref, 'refs/tags/v') + run: git fetch --prune --unshallow + - name: Cache go module uses: actions/cache@v2 with: @@ -34,24 +38,27 @@ jobs: name: Docker Build, Tag, Push steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Docker Login Github - if: github.ref == 'refs/heads/master' - run: >- - echo "${{ secrets.GITHUB_TOKEN }}" - | docker login -u ${GITHUB_ACTOR} --password-stdin docker.pkg.github.com - - - name: Build - if: github.ref == 'refs/heads/master' - run: docker build -t docker.pkg.github.com/${GITHUB_REPOSITORY}/${GITHUB_REPOSITORY#*/}:latest . - - - name: Publish Latest to GitHub Package Registry - if: github.ref == 'refs/heads/master' - run: docker push docker.pkg.github.com/${GITHUB_REPOSITORY}/${GITHUB_REPOSITORY#*/}:latest - - - name: Clear - if: always() && github.ref == 'refs/heads/master' - run: | - rm -f ${HOME}/.docker/config.json + - name: Checkout + uses: actions/checkout@v1 + + - 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 + + - name: GoReleaser + uses: goreleaser/goreleaser-action@v2.4.1 + if: success() + env: + GITHUB_TOKEN: ${{ secrets.GH_PAT }} + with: + version: latest + args: release --rm-dist + + - name: Clear + if: always() + run: | + rm -f ${HOME}/.docker/config.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index efa66ef..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: goreleaser - -on: - push: - tags: - - 'v*.*.*' - -# Pushes a new release on tag -jobs: - goreleaser: - runs-on: ubuntu-latest - name: goreleaser - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Unshallow - run: git fetch --prune --unshallow - - - name: Set up Go - uses: actions/setup-go@v2 - with: - # Version here has to match one returned via https://golang.org/dl/?mode=json&include=all - go-version: '1.14' - - - name: Cache go module - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Docker Login Github - run: >- - echo "${{ secrets.GPR_TOKEN }}" - | docker login -u jimschubert --password-stdin docker.pkg.github.com - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v1 - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Clear - if: always() && startsWith(github.ref, 'refs/tags/') - run: | - rm -f ${HOME}/.docker/config.json