-
Notifications
You must be signed in to change notification settings - Fork 2
176 lines (158 loc) · 5.32 KB
/
Copy pathci.yml
File metadata and controls
176 lines (158 loc) · 5.32 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: CI/CD Pipeline
on:
push:
branches:
- main
- develop
- 'feature/**'
- 'renovate/**'
tags:
- 'v*'
pull_request:
branches:
- main
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.26'
cache: true
cache-dependency-path: "**/go.sum"
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build
run: go build -v ./...
env:
DATA_DIR: ./data
- name: Run tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
env:
DATA_DIR: ./data
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: ./coverage.txt
fail_ci_if_error: false
prepare-docker:
name: Prepare Docker Build
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
outputs:
version: ${{ steps.version.outputs.version }}
tags: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set version
id: version
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# For tags, use the tag name without the 'v' prefix
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Using version from tag: $VERSION"
else
# For non-tag pushes, use a development version with commit SHA
SHORT_SHA=$(git rev-parse --short HEAD)
VERSION="dev-$SHORT_SHA"
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Using development version: $VERSION"
fi
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
type=semver,pattern={{version}},value=${{ env.VERSION }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.VERSION }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}},value=${{ env.VERSION }},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=raw,value=${{ env.VERSION }}
type=sha,format=short
docker-build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: prepare-docker
strategy:
matrix:
platform: [ linux/amd64, linux/arm64 ]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: ${{ matrix.platform }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
with:
buildkitd-flags: --debug
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract platform info
id: platform
run: |
# Extract OS and architecture from platform
OS=$(echo ${{ matrix.platform }} | cut -d/ -f1)
ARCH=$(echo ${{ matrix.platform }} | cut -d/ -f2)
echo "os=$OS" >> $GITHUB_OUTPUT
echo "arch=$ARCH" >> $GITHUB_OUTPUT
echo "Building for $OS/$ARCH"
- name: Build and push by digest
id: build
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
push: true
build-args: |
APP_VERSION=${{ needs.prepare-docker.outputs.version }}
outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.title=komodo-op
org.opencontainers.image.description=Komodo 1Password Sync
org.opencontainers.image.url=https://github.com/${{ github.repository }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ needs.prepare-docker.outputs.version }}
org.opencontainers.image.created=${{ github.event.repository.updated_at }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=MIT
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
echo "Digest: $digest"
- name: Upload digest
uses: actions/upload-artifact@v7
with:
name: digests-${{ steps.platform.outputs.os }}-${{ steps.platform.outputs.arch }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1