@@ -2,49 +2,95 @@ name: CI
2
2
3
3
on :
4
4
push :
5
- branches : [ "main" ]
5
+ branches :
6
+ - main
7
+ paths :
8
+ - ' **.go'
9
+ - ' **.bazel'
10
+ - ' .bazelversion'
11
+ - ' .bazelrc'
12
+ - ' go.mod'
13
+ - ' go.sum'
14
+ - ' MODULE.bazel'
15
+ - ' MODULE.bazel.lock'
6
16
pull_request :
7
- branches : [ "main" ]
17
+ branches :
18
+ - main
19
+ paths :
20
+ - ' **.go'
21
+ - ' **.bazel'
22
+ - ' .bazelversion'
23
+ - ' .bazelrc'
24
+ - ' go.mod'
25
+ - ' go.sum'
26
+ - ' MODULE.bazel'
27
+ - ' MODULE.bazel.lock'
28
+
29
+ permissions :
30
+ contents : write
31
+ packages : write
8
32
9
33
jobs :
10
34
build :
11
35
runs-on : ubuntu-latest
12
-
13
36
steps :
14
- - name : Checkout source
15
- uses : actions/checkout@v3
16
-
17
- - name : Setup bazelisk
18
- uses : bazelbuild/setup-bazelisk@v2
19
-
20
- - name : Mount bazel cache
21
- uses : actions/cache@v3
22
- with :
23
- path : " ~/.cache/bazel"
24
- key : bazel
37
+ - name : Checkout
38
+ uses : actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4
25
39
26
- - name : Setup useful build info
40
+ - name : Generate build version
27
41
id : info
28
42
run : |
29
- echo "::set-output name=date::$(date +'%Y.%m.%d')"
30
- echo "::set-output name=time::$(date +'%H%M%S')"
31
- echo "::set-output name=short_commit_id::$(git rev-parse --short HEAD)"
43
+ formatted_date=$(date +'%Y.%m.%d')
44
+ time=$(date +'%H%M%S')
45
+ short_commit_id=$(git rev-parse --short HEAD)
46
+ echo "build_version=${formatted_date}.${time}.${short_commit_id}" >> $GITHUB_OUTPUT
47
+
48
+ - name : Mount Bazel cache
49
+ uses : actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
50
+ with :
51
+ path : |
52
+ ~/.cache/bazel
53
+ key : ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'MODULE.bazel') }}
54
+ restore-keys : |
55
+ ${{ runner.os }}-bazel-
56
+
57
+ - name : Fetch dependencies
58
+ run : bazel fetch //...
32
59
33
60
- name : Build
34
61
run : bazel build //...
35
62
36
63
- name : Test
37
- run : bazel coverage //...
64
+ run : bazel test //...
65
+
66
+ - name : Tag repo with build version
67
+ run : |
68
+ tag=${{ steps.info.outputs.build_version }}
69
+ git config user.name "${GITHUB_ACTOR}"
70
+ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
71
+ git tag "${tag}"
72
+ git push origin --tags
38
73
39
74
- name : Login to GitHub Container Registry
40
- uses : docker/login-action@v2
75
+ uses : docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3
41
76
with :
42
77
registry : ghcr.io
43
78
username : ${{ github.actor }}
44
79
password : ${{ secrets.GITHUB_TOKEN }}
45
80
46
- - name : Deploy images
81
+ - name : Build and publish images
47
82
run : |
48
- version="${{ steps.info.outputs.date }}.${{ steps.info.outputs.time }}.${{ steps.info.outputs.short_commit_id }}"
49
- images=$(bazel query "kind(\"container_push\", //...)" --output=label)
50
- bazel run --define "version=$version" $images
83
+ tarballTargets=$(bazel query "kind(oci_tarball, //...)")
84
+ while IFS=';' read -ra tarballs; do
85
+ for tarball in "${tarballs[@]}"; do
86
+ bazel build $tarball
87
+ tarFiles=$(bazel cquery --noshow_progress --ui_event_filters=-info,-stderr --output=files $tarball)
88
+ img=$(docker load -q --input $tarFiles)
89
+ imgWithTag=${img#"Loaded image: "}
90
+ imgAndTag=(${imgWithTag//:/ })
91
+ img=${imgAndTag[0]}
92
+ tag=${imgAndTag[1]}
93
+ docker tag $imgWithTag "$img:${{ steps.info.outputs.build_version }}"
94
+ docker push -a $img
95
+ done
96
+ done <<< "$tarballTargets"
0 commit comments