Repository navigation
134 lines (127 loc) · 4.13 KB
/
Copy pathci.yml
File metadata and controls
134 lines (127 loc) · 4.13 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
name: CI
on:
push:
branches: [main]
tags: ['v*']
pull_request:
branches: [main]
permissions:
contents: write
packages: write
attestations: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v6
with:
go-version: '1.26'
- run: go test -race -coverprofile=coverage.out ./...
- run: go vet ./...
# Build inside the official golang:1.26 image (GitHub mounts the runner's
# Node into the container, so JS actions like checkout/upload-artifact work).
build:
runs-on: ubuntu-latest
container: golang:1.26
needs: [test]
steps:
- uses: actions/checkout@v7
- id: date
run: echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
- name: Build (inject version metadata)
env:
VERSION: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
DATE: ${{ steps.date.outputs.date }}
CGO_ENABLED: "0"
run: |
go build -trimpath -buildvcs=false \
-ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \
-o diskcli ./cmd/diskcli
# Cross-compile release binaries for every OS/CPU combo on tag pushes.
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: [test]
runs-on: ubuntu-latest
container: golang:1.26
strategy:
fail-fast: false
matrix:
include:
- { goos: linux, goarch: amd64 }
- { goos: linux, goarch: arm64 }
- { goos: linux, goarch: arm }
- { goos: darwin, goarch: amd64 }
- { goos: darwin, goarch: arm64 }
- { goos: windows, goarch: amd64 }
- { goos: windows, goarch: arm64 }
steps:
- uses: actions/checkout@v7
- id: date
run: echo "date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_OUTPUT"
- name: Build ${{ matrix.goos }}/${{ matrix.goarch }}
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ github.ref_name }}
COMMIT: ${{ github.sha }}
DATE: ${{ steps.date.outputs.date }}
CGO_ENABLED: "0"
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
go build -trimpath -buildvcs=false \
-ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \
-o "dist/diskcli-${GOOS}-${GOARCH}${EXT}" ./cmd/diskcli
- uses: actions/upload-artifact@v7
with:
name: diskcli-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/diskcli-${{ matrix.goos }}-${{ matrix.goarch }}*
if-no-files-found: error
# Collect all binaries, generate sha256 checksums, and publish the release.
publish:
if: startsWith(github.ref, 'refs/tags/v')
needs: [release]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Generate checksums
working-directory: dist
run: sha256sum * > checksums.txt
- uses: softprops/action-gh-release@v3
with:
files: dist/*
generate_release_notes: true
docker:
if: startsWith(github.ref, 'refs/tags/v')
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/metadata-action@v6
id: meta
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha,prefix=
- uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}