-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (144 loc) · 3.58 KB
/
golang-ci.yaml
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Golang CI
on:
push:
branches:
- main
- dev
pull_request:
jobs:
test-unit:
name: Run Unit Tests
runs-on: ubuntu-22.04
steps:
-
uses: actions/checkout@v4
-
name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
-
name: Install dependencies
run: go get .
-
name: Build
run: go build -v ./...
-
name: Test with the Go CLI
run: go test ./...
format:
runs-on: ubuntu-22.04
name: Format Golang
permissions:
contents: write
pull-requests: write
steps:
-
uses: actions/checkout@v4
-
name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20.x'
-
name: Install dependencies
run: go get .
-
name: Build
run: go build -v ./...
-
name: Run go fmt
run: go fmt ./...
-
name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: "🔨 Run `go fmt`"
title: 🔨 Reformat Golang Files
body: Update Golang files to canonical format using `go fmt ./...`
branch: refactor/go-fmt
# Delete PR branch if diff is resolved anyhow
delete-branch: true
labels: |
bot
kind/cleanup
test-container:
name: Run Container Structure Tests
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and export to Docker
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: |
image:testing
-
name: Test image functionality
uses: plexsystems/container-structure-test-action@cc689017bbb16a3c98e6e87b0e07f92ad35a9df1
with:
image: image:testing
config: container-structure-test.yaml
build:
name: Build and Push Docker Image
runs-on: ubuntu-22.04
needs: [ test-unit, test-container ]
permissions:
contents: read
packages: write
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Prepare Docker metadata
id: image-metadata
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository }}
flavor: |
latest=true
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
labels: |
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.label-schema.schema-version=1.0
org.label-schema.vcs-url=https://github.com/${{ github.repository }}.git
org.label-schema.docker.cmd.help=docker run --rm -it $CONTAINER help
-
name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.image-metadata.outputs.tags }}
labels: ${{ steps.image-metadata.outputs.labels }}