Skip to content

Commit ebe2aca

Browse files
authored
Add tools Ci cache (#1418)
* Add tools cache step * add cache in Check for changes * Update in build * Add separate job * update bulid * Simpify process lib * Update makefile * Update tests * Fix diff * Add sentence case * Fix typo * Add comment * revert name to make sure CI don't stuck
1 parent 693d710 commit ebe2aca

File tree

6 files changed

+101
-40
lines changed

6 files changed

+101
-40
lines changed

.github/workflows/build.yml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
---
22
name: Build
33

4+
permissions:
5+
contents: read
6+
47
on:
58
push:
69
branches:
@@ -9,32 +12,74 @@ on:
912
pull_request:
1013

1114
jobs:
12-
lint-fmt:
13-
name: Lint and Format
15+
setup:
16+
name: Setup tools
1417
runs-on: ubuntu-latest
18+
outputs:
19+
cache-hit: ${{ steps.tools-cache.outputs.cache-hit }}
1520
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
1825
- name: Setup Go
19-
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
26+
uses: actions/setup-go@v5
2027
with:
2128
go-version: 1.23
29+
- name: Tools cache
30+
id: tools-cache
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/go/bin
35+
/usr/local/bin/promtool
36+
key: ${{ runner.os }}-tools-${{ hashFiles('Makefile') }}
2237
- name: Install CI dependencies
38+
if: steps.tools-cache.outputs.cache-hit != 'true'
2339
run: make install-ci-deps
40+
41+
lint-fmt:
42+
name: Lint and Format
43+
needs: setup
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
- name: Setup Go
51+
uses: actions/setup-go@v5
52+
with:
53+
go-version: 1.23
54+
- name: Restore Tools cache
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/go/bin
59+
/usr/local/bin/promtool
60+
key: ${{ runner.os }}-tools-${{ hashFiles('Makefile') }}
2461
- name: Lint and Format
2562
run: make lint-fmt
2663

2764
tests:
2865
name: Run Tests
66+
needs: setup
2967
runs-on: ubuntu-latest
3068
steps:
31-
- name: Checkout code
32-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
69+
- name: Checkout
70+
uses: actions/checkout@v4
71+
with:
72+
fetch-depth: 0
3373
- name: Setup Go
34-
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
74+
uses: actions/setup-go@v5
3575
with:
3676
go-version: 1.23
37-
- name: Install CI dependencies
38-
run: make install-ci-deps
77+
- name: Restore Tools cache
78+
uses: actions/cache@v4
79+
with:
80+
path: |
81+
~/go/bin
82+
/usr/local/bin/promtool
83+
key: ${{ runner.os }}-tools-${{ hashFiles('Makefile') }}
3984
- name: Run Tests
4085
run: make tests

.github/workflows/test-mixins.yml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,43 @@ on:
1111
- master
1212

1313
jobs:
14-
check-for-changed-mixins:
15-
name: Check for changes
14+
setup:
15+
name: Setup tools
1616
runs-on: ubuntu-latest
1717
outputs:
18-
changed-mixins: ${{ steps.changed-mixins.outputs.all_changed_files }}
18+
cache-hit: ${{ steps.tools-cache.outputs.cache-hit }}
1919
steps:
2020
- name: Checkout
2121
uses: actions/checkout@v4
2222
with:
2323
fetch-depth: 0
24-
2524
- name: Setup Go
2625
uses: actions/setup-go@v5
2726
with:
2827
go-version: 1.23
29-
28+
- name: Tools cache
29+
id: tools-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
~/go/bin
34+
/usr/local/bin/promtool
35+
key: ${{ runner.os }}-tools-${{ hashFiles('Makefile') }}
3036
- name: Install CI dependencies
37+
if: steps.tools-cache.outputs.cache-hit != 'true'
3138
run: make install-ci-deps
32-
39+
40+
check-for-changed-mixins:
41+
name: Check for changes
42+
needs: setup
43+
runs-on: ubuntu-latest
44+
outputs:
45+
changed-mixins: ${{ steps.changed-mixins.outputs.all_changed_files }}
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
fetch-depth: 0
3351
- name: Get changed mixins
3452
id: changed-mixins
3553
uses: tj-actions/changed-files@v44
@@ -41,7 +59,6 @@ jobs:
4159
**-mixin/
4260
**-observ-lib/
4361
matrix: true
44-
4562
- name: List all changed mixins
4663
run: echo '${{ steps.changed-mixins.outputs.all_changed_files }}'
4764

@@ -54,7 +71,7 @@ jobs:
5471
pull-requests: write
5572
repository-projects: write
5673
timeout-minutes: 15
57-
needs: [check-for-changed-mixins]
74+
needs: [setup, check-for-changed-mixins]
5875
strategy:
5976
matrix:
6077
mixin: ${{ fromJSON(needs.check-for-changed-mixins.outputs.changed-mixins) }}
@@ -73,27 +90,26 @@ jobs:
7390
uses: actions/checkout@v4
7491
with:
7592
fetch-depth: 0
76-
7793
- name: Setup Go
7894
uses: actions/setup-go@v5
7995
with:
8096
go-version: 1.23
81-
82-
- name: Install CI dependencies
83-
run: make install-ci-deps
84-
97+
- name: Restore Tools cache
98+
uses: actions/cache@v4
99+
with:
100+
path: |
101+
~/go/bin
102+
/usr/local/bin/promtool
103+
key: ${{ runner.os }}-tools-${{ hashFiles('Makefile') }}
85104
- name: Install mixin dependencies
86105
working-directory: ./${{ matrix.mixin }}
87106
run: make build
88-
89107
- name: Lint mixin
90108
working-directory: ./${{ matrix.mixin }}
91109
run: make lint
92-
93110
- name: Check for unexpected changes in generated files
94111
working-directory: ./${{ matrix.mixin }}
95-
run: "make dashboards_out prometheus_alerts.yaml prometheus_rules.yaml && git diff --exit-code || ( echo 'Error: Generated files are not up to date. Run make and commit the local diff'; exit 1; )"
96-
112+
run: "make -B dashboards_out prometheus_alerts.yaml prometheus_rules.yaml && git diff --exit-code || ( echo 'Error: Generated files are not up to date. Run make and commit the local diff'; exit 1; )"
97113
- name: Wait for Grafana and validate dashboards
98114
working-directory: ./${{ matrix.mixin }}
99115
env:
@@ -104,7 +120,6 @@ jobs:
104120
105121
# Try to deploy dashboards
106122
make deploy_dashboards
107-
108123
- name: Run promtool test for rules
109124
working-directory: ./${{ matrix.mixin }}
110125
run: make test

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ else
1717
ARCH := $(UNAME_M)
1818
endif
1919

20+
# Check if .github/workflows/*.yml need to be updated
21+
# when changing the install-ci-deps target.
2022
install-ci-deps: install-promtool
2123
go install github.com/google/go-jsonnet/cmd/jsonnet@v0.20.0
2224
go install github.com/google/go-jsonnet/cmd/jsonnetfmt@v0.20.0

Makefile_mixin

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ dashboards_out: mixin.libsonnet $(wildcard **/*.libsonnet) $(wildcard **/*.jsonn
3333
@mkdir -p dashboards_out
3434
mixtool generate dashboards mixin.libsonnet -d dashboards_out
3535

36-
prometheus_alerts.yaml: $(wildcard vendor/**/alerts.yaml) $(wildcard vendor/**/alerts.libsonnet) mixin.libsonnet $(wildcard alerts.libsonnet) $(wildcard signals/*) $(wildcard alerts/*)
36+
prometheus_alerts.yaml: mixin.libsonnet $(wildcard vendor/**/alerts.yaml) $(wildcard alerts/*) $(wildcard vendor/**/alerts.libsonnet) $(wildcard alerts.libsonnet) $(wildcard signals/*)
3737
@mkdir -p prometheus_rules_out
3838
@if [ -f alerts.libsonnet -o -d alerts ]; then \
3939
mixtool generate alerts mixin.libsonnet -a prometheus_rules_out/prometheus_alerts.yaml; \
4040
else \
4141
touch prometheus_rules_out/prometheus_alerts.yaml; \
4242
fi
43-
prometheus_rules.yaml: $(wildcard vendor/**/rules.yaml) $(wildcard vendor/**/rules.libsonnet) mixin.libsonnet $(wildcard rules.libsonnet) $(wildcard signals/*) $(wildcard rules/*)
43+
prometheus_rules.yaml: mixin.libsonnet $(wildcard vendor/**/rules.yaml) $(wildcard rules/*) $(wildcard vendor/**/rules.libsonnet) $(wildcard rules.libsonnet) $(wildcard signals/*)
4444
@if [ -f rules.libsonnet -o -d rules ]; then \
4545
mixtool generate rules mixin.libsonnet -a prometheus_rules_out/prometheus_rules.yaml; \
4646
else \

process-observ-lib/dashboards_out/process-dashboard.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

process-observ-lib/mixin.libsonnet

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ local proc =
66
proclib.new()
77
+ proclib.withConfigMixin(
88
{
9-
filteringSelector: 'job!=""',
109
metricsSource: 'java_otel',
1110
}
1211
);

0 commit comments

Comments
 (0)