fleet/.github/workflows/goreleaser-snapshot-fleet.yaml

78 lines
2.4 KiB
YAML

name: Docker publish
on:
push:
branches:
- main
- patch-*
pull_request:
jobs:
# This check-secrets job is used to gate execution of the main job. External PRs will not have
# access to the necessary secrets for pushing an image, so we want to skip that job if the secret
# is unavailable.
check-secrets:
environment: Docker Hub
runs-on: ubuntu-latest
outputs:
available: ${{ steps.check-secrets.outputs.available }}
steps:
- name: Check Secrets availability
id: check-secrets
run: |
if [ ! -z "${{ secrets.DOCKERHUB_USERNAME }}" ]; then
echo "::set-output name=available::true"
fi
# If the secrets are available, build and publish a Docker image.
publish:
needs:
- check-secrets
if: ${{ needs.check-secrets.outputs.available == 'true' }}
runs-on: ubuntu-latest
environment: Docker Hub
steps:
- name: Checkout (PR)
if: ${{ github.event.pull_request.head.sha }}
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout (main)
if: ${{ !github.event.pull_request.head.sha }}
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 # v1.10.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16.5
- name: Install JS Dependencies
run: make deps-js
- name: Install Go Dependencies
run: make deps-go
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@ac067437f516133269923265894e77920c3dce18 # v2.6.1
with:
distribution: goreleaser-pro
version: latest
args: release --snapshot --rm-dist -f .goreleaser-snapshot.yml
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: Tag image with branch name
if: ${{ !github.event.pull_request.head.sha }}
run: docker tag fleetdm/fleet:$(git rev-parse --short HEAD) fleetdm/fleet:$(git rev-parse --abbrev-ref HEAD)
# Explicitly push the docker images as GoReleaser will not do so in snapshot mode
- name: Publish Docker images
run: docker push fleetdm/fleet --all-tags