-
Notifications
You must be signed in to change notification settings - Fork 13
67 lines (67 loc) · 2.19 KB
/
push-build-test-on-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
on: push
name: Build & test
jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: set up qemu virt with platforms
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,arm
- name: set up docker buildx builder with platforms
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: create metadata (tags and labels)
uses: docker/metadata-action@v5
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@v6
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- 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@v3
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: push to registry (unless pull request)
uses: docker/build-push-action@v6
if: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
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@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
- run: go test ./...