Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 4519da6

Browse files
authored
ci(): publish docker to ghcr (#9)
1 parent aca1581 commit 4519da6

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

.github/workflows/docker-publish.yaml

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Docker publish
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
tags: [ 'v*.*.*' ]
7+
8+
env:
9+
# Use docker.io for Docker Hub if empty
10+
REGISTRY: ghcr.io
11+
# github.repository as <account>/<repo>
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v3
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: '1.21'
26+
27+
- name: Build
28+
run: go build -v ./...
29+
30+
- name: Test
31+
run: go test -v ./...
32+
33+
34+
build:
35+
needs: test
36+
runs-on: ubuntu-latest
37+
permissions:
38+
contents: read
39+
packages: write
40+
# This is used to complete the identity challenge
41+
# with sigstore/fulcio when running outside of PRs.
42+
id-token: write
43+
44+
steps:
45+
- name: Checkout repository
46+
uses: actions/checkout@v3
47+
48+
- name: Setup Docker buildx
49+
uses: docker/setup-buildx-action@v2
50+
51+
# Login against a Docker registry except on PR
52+
# https://github.com/docker/login-action
53+
- name: Log into registry ${{ env.REGISTRY }}
54+
if: github.event_name != 'pull_request'
55+
uses: docker/login-action@v2
56+
with:
57+
registry: ${{ env.REGISTRY }}
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
# Extract metadata (tags, labels) for Docker
62+
# https://github.com/docker/metadata-action
63+
- name: Extract Docker metadata
64+
id: meta
65+
uses: docker/metadata-action@v4
66+
with:
67+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
68+
tags: |
69+
type=ref,event=branch
70+
type=ref,event=tag
71+
72+
# Build and push Docker image with Buildx (don't push on PR)
73+
# https://github.com/docker/build-push-action
74+
- name: Build and push Docker image
75+
id: build-and-push
76+
uses: docker/build-push-action@v4
77+
with:
78+
context: .
79+
push: ${{ github.event_name != 'pull_request' }}
80+
tags: ${{ steps.meta.outputs.tags }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
cache-from: type=gha
83+
cache-to: type=gha,mode=max

.github/workflows/go.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
name: Go
55

66
on:
7-
push:
8-
branches: [ "main" ]
7+
#push:
8+
# branches: [ "main" ]
99
pull_request:
1010
branches: [ "main" ]
1111

@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v4
2121
with:
22-
go-version: '1.20'
22+
go-version: '1.21
2323
2424
- name: Build
2525
run: go build -v ./...

0 commit comments

Comments
 (0)