-
Notifications
You must be signed in to change notification settings - Fork 1
163 lines (147 loc) · 5.44 KB
/
ci.yml
File metadata and controls
163 lines (147 loc) · 5.44 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
name: CI
on:
push:
branches: [main]
schedule:
- cron: '0 16 * * *'
jobs:
setup-env:
# Prepare common variables: date, timestamp, repo, and short SHA
runs-on: ubuntu-24.04
if: github.event_name == 'schedule' || github.event_name == 'push'
outputs:
date: ${{ steps.vars.outputs.date }}
date_time: ${{ steps.vars.outputs.date_time }}
source_date_epoch: ${{ steps.vars.outputs.source_date_epoch }}
repo: ${{ steps.vars.outputs.repo }}
short_sha: ${{ steps.vars.outputs.short_sha }}
steps:
- name: Generate common variables
id: vars
run: |
now=$(date +%s)
date=$(date -u -d "@$now" '+%Y-%m-%d')
date_time=$(date -u -d "@$now" '+%Y-%m-%d.%H-%M-%S')
year_month=$(date -u -d "@$now" '+%Y-%m')
source_date_epoch=$(date -u -d "${year_month}-01 00:00:00" '+%s')
echo "date=$date" >> $GITHUB_OUTPUT
echo "date_time=$date_time" >> $GITHUB_OUTPUT
echo "source_date_epoch=$source_date_epoch" >> $GITHUB_OUTPUT
echo "repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
echo "short_sha=${GITHUB_SHA:0:8}" >> $GITHUB_OUTPUT
build-matrix:
needs: setup-env
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
- platform: amd64
runner: ubuntu-24.04
- platform: arm64
runner: ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
check-latest: true
- name: Install dependencies
run: go mod download
- name: Run tests
run: go test ./...
- name: Build static binary
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: ${{ matrix.platform }}
SOURCE_DATE_EPOCH: ${{ needs.setup-env.outputs.source_date_epoch }}
run: |
mkdir -p build
go build -ldflags="-s -w -buildid= " -o build/promptpipe-${{ matrix.platform }} ./cmd/PromptPipe
- name: Upload built binary
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.platform }}
path: build/promptpipe-${{ matrix.platform }}
docker-build:
needs: [setup-env, build-matrix]
runs-on: ubuntu-24.04
if: github.event_name == 'schedule' || (github.event_name == 'push' && contains(github.event.head_commit.message, 'run-ci'))
permissions:
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download amd64 binary
uses: actions/download-artifact@v4
with:
name: binaries-amd64
path: docker/artifacts
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: binaries-arm64
path: docker/artifacts
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
env:
SOURCE_DATE_EPOCH: ${{ needs.setup-env.outputs.source_date_epoch }}
with:
context: docker
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
ghcr.io/${{ needs.setup-env.outputs.repo }}:latest
ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date }}
ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date }}.${{ needs.setup-env.outputs.short_sha }}
ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date_time }}
ghcr.io/${{ needs.setup-env.outputs.repo }}:${{ needs.setup-env.outputs.date_time }}.${{ needs.setup-env.outputs.short_sha }}
outputs: "type=registry,compression=zstd,force-compression=true,compression-level=3,rewrite-timestamp=true,oci-mediatypes=true"
release:
needs: [setup-env, build-matrix]
runs-on: ubuntu-24.04
if: github.event_name == 'schedule' || (github.event_name == 'push' && contains(github.event.head_commit.message, 'run-ci'))
permissions:
contents: write
steps:
- name: Download amd64 binary
uses: actions/download-artifact@v4
with:
name: binaries-amd64
path: release/artifacts
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: binaries-arm64
path: release/artifacts
- name: Set release version
id: version
run: |
ver="${{ needs.setup-env.outputs.date_time }}.${{ needs.setup-env.outputs.short_sha }}"
echo "version=$ver" >> $GITHUB_OUTPUT
- name: Create or update GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
target_commitish: ${{ github.sha }}
files: |
release/artifacts/*