forked from livegrep/livegrep
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (83 loc) · 3.55 KB
/
ci.yaml
File metadata and controls
91 lines (83 loc) · 3.55 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
on:
pull_request:
branches:
- main
push:
branches:
- main
name: Continuous integration
env:
BASE_IMAGE_NAME: livegrep/base
INDEXER_IMAGE_NAME: livegrep/indexer
NGINX_IMAGE_NAME: livegrep/nginx
jobs:
ci:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- name: Switch to CI bazelrc
run: cp .bazelrc.ci .bazelrc
- name: Cache Bazel disk cache
uses: actions/cache@v4
with:
path: ~/.cache/bazel-disk
key: bazel-disk-${{ runner.os }}-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock') }}-${{ github.sha }}
restore-keys: |
bazel-disk-${{ runner.os }}-${{ hashFiles('MODULE.bazel', 'MODULE.bazel.lock') }}-
bazel-disk-${{ runner.os }}-
- name: bazel build
id: build
run: |
bazel build //...
echo "build_output_file_name=$(./package.sh)" >> $GITHUB_ENV
- name: bazel test
run: bazel test --test_arg=-test.v //...
# Run after building so we can use BuildBuddys fetch cache rather than
# first calling bazel fetch ourselves. If a Go file ins't formatted
# corectly it will only take an additional minute or so for CI to fail.
- name: gofmt
run: |
format_errors=$(bazel run @rules_go//go -- fmt ./...)
if [ "$format_errors" ]; then
echo "=== misformatted files (run gofmt) ==="
echo "$format_errors"
exit 1
fi
- name: upload build output
if: ${{ github.event_name == 'push' }}
uses: actions/upload-artifact@v4
with:
name: "${{ env.build_output_file_name }}"
path: "builds/${{ env.build_output_file_name }}.tgz"
retention-days: 1
- name: Build images
if: ${{ github.event_name == 'push' }}
run: |
docker build -t $BASE_IMAGE_NAME --file docker/base/Dockerfile --build-arg "livegrep_version=$build_output_file_name" .
docker build -t $INDEXER_IMAGE_NAME . --file docker/indexer/Dockerfile
docker build -t $NGINX_IMAGE_NAME . --file docker/nginx/Dockerfile
- name: Push images
if: ${{ github.event_name == 'push' }}
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
BASE_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$BASE_IMAGE_NAME
INDEXER_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$INDEXER_IMAGE_NAME
NGINX_IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$NGINX_IMAGE_NAME
# tag each image with GHCRID:VERSION
VERSION=$(git rev-parse HEAD | head -c10)
docker tag $BASE_IMAGE_NAME $BASE_IMAGE_ID:$VERSION
docker tag $INDEXER_IMAGE_NAME $INDEXER_IMAGE_ID:$VERSION
docker tag $NGINX_IMAGE_NAME $NGINX_IMAGE_ID:$VERSION
# this workflow is running on "main" atm so always tag latest
docker tag $BASE_IMAGE_NAME $BASE_IMAGE_ID:latest
docker tag $INDEXER_IMAGE_NAME $INDEXER_IMAGE_ID:latest
docker tag $NGINX_IMAGE_NAME $NGINX_IMAGE_ID:latest
docker push $NGINX_IMAGE_ID:$VERSION
docker push $BASE_IMAGE_ID:$VERSION
docker push $INDEXER_IMAGE_ID:$VERSION
# it seems like docker doesn't push all tags for an image, you need to
# push each tag as if it were a seperate image -__-
echo "Pushing latest images to test"
docker push $NGINX_IMAGE_ID:latest
docker push $BASE_IMAGE_ID:latest
docker push $INDEXER_IMAGE_ID:latest