-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (85 loc) · 2.7 KB
/
ci.yml
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
name: CI
on:
push:
branches:
- main
paths:
- '**.go'
- '**.bazel'
- '.bazelversion'
- '.bazelrc'
- 'go.mod'
- 'go.sum'
- 'MODULE.bazel'
- 'MODULE.bazel.lock'
pull_request:
branches:
- main
paths:
- '**.go'
- '**.bazel'
- '.bazelversion'
- '.bazelrc'
- 'go.mod'
- 'go.sum'
- 'MODULE.bazel'
- 'MODULE.bazel.lock'
permissions:
contents: write
packages: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4
- name: Generate build version
id: info
run: |
formatted_date=$(date +'%Y.%m.%d')
time=$(date +'%H%M%S')
short_commit_id=$(git rev-parse --short HEAD)
echo "build_version=${formatted_date}.${time}.${short_commit_id}" >> $GITHUB_OUTPUT
- name: Mount Bazel cache
uses: actions/cache@3624ceb22c1c5a301c8db4169662070a689d9ea8 # v4
with:
path: |
~/.cache/bazel
key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-
- name: Fetch dependencies
run: bazel fetch //...
- name: Build
run: bazel build //...
- name: Test
run: bazel test //...
- name: Tag repo with build version
run: |
tag=${{ steps.info.outputs.build_version }}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag "${tag}"
git push origin --tags
- name: Login to GitHub Container Registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish images
run: |
tarballTargets=$(bazel query "kind(filegroup, //...)" | grep ".tar$")
while IFS=';' read -ra tarballs; do
for tarball in "${tarballs[@]}"; do
bazel build $tarball
tarFiles=$(bazel cquery --noshow_progress --ui_event_filters=-info,-stderr --output=files $tarball)
img=$(docker load -q --input $tarFiles)
imgWithTag=${img#"Loaded image: "}
imgAndTag=(${imgWithTag//:/ })
img=${imgAndTag[0]}
tag=${imgAndTag[1]}
docker tag $imgWithTag "$img:${{ steps.info.outputs.build_version }}"
docker push -a $img
done
done <<< "$tarballTargets"