Skip to content

Update push-build-test-on-push.yml #67

Update push-build-test-on-push.yml

Update push-build-test-on-push.yml #67

on: push
name: Build & test
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: set up qemu virt with platforms
uses: docker/setup-qemu-action@v2
with:
platforms: arm64,arm
- name: set up docker buildx builder with platforms
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: create metadata (tags and labels)
uses: docker/metadata-action@v4
id: meta
with:
images: parkr/ping
flavor: |
latest=false
tags: |
type=raw,value=${{ github.sha }}
labels: |
org.opencontainers.image.documentation=https://github.com/${{github.repository}}#readme
org.opencontainers.image.licenses=MIT
- name: build test image
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: test image executable will run
run: |
docker run --rm ${{ steps.meta.outputs.tags }} -h
- name: login to the Docker registry
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: push to registry (unless pull request)
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64,linux/arm/v7
test:
name: Run Go Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.20"
- run: go test ./...