Skip to content

Commit 6e5f853

Browse files
authored
ci: always release chart (#197)
1 parent 3531fc0 commit 6e5f853

File tree

20 files changed

+204
-165
lines changed

20 files changed

+204
-165
lines changed

.github/workflows/dependency-review.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
# Dependency Review Action
2-
#
3-
# This Action will scan dependency manifest files that change as part of a Pull Request,
4-
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5-
# Once installed, if the workflow run is marked as required,
6-
# PRs introducing known-vulnerable packages will be blocked from merging.
7-
#
8-
# Source repository: https://github.com/actions/dependency-review-action
9-
name: 'Dependency Review'
1+
name: dependency_review
102
on: [pull_request]
113

124
permissions:

.github/workflows/pr-build.yaml

Lines changed: 113 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,35 @@ on:
1010
permissions: {}
1111

1212
jobs:
13-
build:
13+
lint-chart:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Harden Runner
17+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
18+
with:
19+
egress-policy: audit
20+
21+
- name: Checkout
22+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Set up Helm
27+
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5
28+
with:
29+
version: v3.4.0
30+
31+
- uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
32+
with:
33+
python-version: 3.7
34+
35+
- name: Set up chart-testing
36+
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0
37+
38+
- name: Run chart-testing (lint)
39+
run: ct lint --target-branch=master --chart-dirs chart --check-version-increment=false
40+
41+
lint:
1442
runs-on: ubuntu-latest
1543
steps:
1644
- name: Harden Runner
@@ -37,6 +65,35 @@ jobs:
3765
run: make vet
3866
- name: lint
3967
run: make lint
68+
- name: Check if working tree is dirty
69+
run: |
70+
if [[ $(git diff --stat) != '' ]]; then
71+
git --no-pager diff
72+
echo 'run make test and commit changes'
73+
exit 1
74+
fi
75+
76+
build:
77+
runs-on: ubuntu-latest
78+
steps:
79+
- name: Harden Runner
80+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
81+
with:
82+
egress-policy: audit
83+
84+
- name: Checkout
85+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
86+
- name: Setup Go
87+
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
88+
with:
89+
go-version: 1.20.5
90+
- name: Restore Go cache
91+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
92+
with:
93+
path: ~/go/pkg/mod
94+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
95+
restore-keys: |
96+
${{ runner.os }}-go-
4097
- name: Run tests
4198
run: make test
4299
- name: Build binary
@@ -45,13 +102,6 @@ jobs:
45102
uses: shogo82148/actions-goveralls@df920a6a2468668dfcf71a0b43817f89eaa5ea04 # v1.7.0
46103
with:
47104
path-to-profile: coverage.out
48-
- name: Check if working tree is dirty
49-
run: |
50-
if [[ $(git diff --stat) != '' ]]; then
51-
git --no-pager diff
52-
echo 'run make test and commit changes'
53-
exit 1
54-
fi
55105
- name: Build container image
56106
run: |
57107
make docker-build
@@ -69,6 +119,61 @@ jobs:
69119
profiles=$(ls config/tests/cases | jq -R -s -c 'split("\n")[:-1]')
70120
echo $profiles
71121
echo "::set-output name=matrix::$profiles"
122+
123+
test-chart:
124+
runs-on: ubuntu-latest
125+
needs:
126+
- build
127+
- lint-chart
128+
steps:
129+
- name: Harden Runner
130+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
131+
with:
132+
egress-policy: audit
133+
134+
- name: Checkout
135+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
136+
with:
137+
fetch-depth: 0
138+
139+
- name: Set up Helm
140+
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5
141+
with:
142+
version: v3.4.0
143+
144+
- uses: actions/setup-python@bd6b4b6205c4dbad673328db7b31b7fab9e241c0 # v4.6.1
145+
with:
146+
python-version: 3.7
147+
148+
- name: Set up chart-testing
149+
uses: helm/chart-testing-action@e8788873172cb653a90ca2e819d79d65a66d4e76 # v2.4.0
150+
151+
- name: Run chart-testing (list-changed)
152+
id: list-changed
153+
run: |
154+
changed=$(ct list-changed --target-branch=master --chart-dirs chart)
155+
if [[ -n "$changed" ]]; then
156+
echo "::set-output name=changed::true"
157+
fi
158+
159+
- name: Create kind cluster
160+
uses: helm/kind-action@fa81e57adff234b2908110485695db0f181f3c67 # v1.7.0
161+
if: steps.list-changed.outputs.changed == 'true'
162+
163+
- name: Download exporter container
164+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
165+
with:
166+
name: exporter-container
167+
path: /tmp
168+
- name: Load image
169+
run: |
170+
docker load --input /tmp/exporter-container.tar
171+
docker tag ghcr.io/raffis/mongodb-query-exporter:latest ghcr.io/raffis/mongodb-query-exporter:0.0.0
172+
docker image ls -a
173+
kind load docker-image ghcr.io/raffis/mongodb-query-exporter:0.0.0 --name chart-testing
174+
175+
- name: Run chart-testing (install)
176+
run: ct install --target-branch=master --chart-dirs chart
72177

73178
e2e-tests:
74179
runs-on: ubuntu-latest

.github/workflows/pr-chart.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/release-chart.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ on:
77
permissions: {}
88

99
jobs:
10-
build:
11-
name: Build
10+
release:
1211
runs-on: ubuntu-latest
1312
permissions:
1413
contents: write # needed to write releases
@@ -44,3 +43,42 @@ jobs:
4443
args: release --rm-dist --skip-validate
4544
env:
4645
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
release-chart:
48+
runs-on: ubuntu-latest
49+
needs:
50+
- release
51+
permissions:
52+
packages: write # Needed to publish chart to ghcr.io
53+
id-token: write # Needed for keyless signing
54+
steps:
55+
- name: Harden Runner
56+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
57+
with:
58+
egress-policy: audit
59+
60+
- name: Checkout
61+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3
62+
with:
63+
fetch-depth: 0
64+
65+
- name: Install Helm
66+
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78 #v3.5
67+
68+
- name: Setup Cosign
69+
uses: sigstore/cosign-installer@6e04d228eb30da1757ee4e1dd75a0ec73a653e06 # v3.1.1
70+
71+
- name: Login to Github Container Registry using helm
72+
run: echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io --username ${{ github.actor }} --password-stdin
73+
74+
- name: Package helm charts
75+
run: |
76+
packVersion=$(echo "${{ github.ref_name }}" | sed 's/^v//g')
77+
helm package chart/mongodb-query-exporter -d chart --version=$packVersion --app-version=${{ github.ref_name }}
78+
79+
- name: Publish helm charts to Github Container Registry
80+
run: |
81+
repository=$(echo "${{ github.repository_owner }}" | tr [:upper:] [:lower:])
82+
helm push ${{ github.workspace }}/chart/mongodb-query-exporter-*.tgz oci://ghcr.io/$repository/charts |& tee .digest
83+
cosign login --username ${GITHUB_ACTOR} --password ${{ secrets.GITHUB_TOKEN }} ghcr.io
84+
cosign sign --yes ghcr.io/${{ github.repository_owner }}/charts/mongodb-query-exporter@$(cat .digest | awk -F "[, ]+" '/Digest/{print $NF}')

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prometheus MongoDB query exporter
22
[![release](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml/badge.svg)](https://github.com/raffis/mongodb-query-exporter/actions/workflows/release.yaml)
3-
[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v3)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v3)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/raffis/mongodb-query-exporter/v5)](https://goreportcard.com/report/github.com/raffis/mongodb-query-exporter/v5)
44
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/raffis/mongodb-query-exporter/badge)](https://api.securityscorecards.dev/projects/github.com/raffis/mongodb-query-exporter)
55
[![Coverage Status](https://coveralls.io/repos/github/raffis/mongodb-query-exporter/badge.svg?branch=master)](https://coveralls.io/github/raffis/mongodb-query-exporter?branch=master)
66
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/mongodb-query-exporter)](https://artifacthub.io/packages/search?repo=mongodb-query-exporter)
@@ -138,7 +138,8 @@ aggregations:
138138
overrideEmpty: true # if an empty result set is returned..
139139
emptyValue: 0 # create a metric with value 0
140140
labels: []
141-
constLabels: []
141+
constLabels:
142+
region: eu-central-1
142143
cache: 0
143144
mode: pull
144145
pipeline: |
@@ -153,7 +154,7 @@ aggregations:
153154
help: 'The total number of processes in a job queue'
154155
value: total
155156
labels: [type,status]
156-
constLabels: []
157+
constLabels: {}
157158
mode: pull
158159
pipeline: |
159160
[
@@ -188,7 +189,7 @@ aggregations:
188189
help: 'The total number of events (created 1h ago or newer)'
189190
value: count
190191
labels: [type]
191-
constLabels: []
192+
constLabels: {}
192193
mode: pull
193194
# Note $$NOW is only supported in MongoDB >= 4.2
194195
pipeline: |

chart/mongodb-query-exporter/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
apiVersion: v2
2-
appVersion: 2.0.3
2+
appVersion: 0.0.0
33
description: A Prometheus exporter for MongoDB custom aggregations
44
home: https://github.com/raffis/mongodb-query-exporter
55
maintainers:
@@ -15,4 +15,4 @@ keywords:
1515
name: mongodb-query-exporter
1616
sources:
1717
- https://github.com/raffis/mongodb-query-exporter
18-
version: 4.0.3
18+
version: 0.0.0

cmd/integration_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,13 @@ type integrationTest struct {
3333

3434
func TestMetricsConfigv2(t *testing.T) {
3535
expected := map[string]string{
36-
"myapp_example_simplevalue_total": `name:"myapp_example_simplevalue_total" help:"Simple gauge metric" type:GAUGE metric:<label:<name:"server" value:"main" > gauge:<value:2 > > `,
36+
"myapp_example_simplevalue_total": `name:"myapp_example_simplevalue_total" help:"Simple gauge metric" type:GAUGE metric:<label:<name:"region" value:"eu-central-1" > label:<name:"server" value:"main" > gauge:<value:2 > > `,
3737
"myapp_example_processes_total": `name:"myapp_example_processes_total" help:"The total number of processes in a job queue" type:GAUGE metric:<label:<name:"server" value:"main" > label:<name:"status" value:"postponed" > label:<name:"type" value:"foobar" > gauge:<value:2 > > metric:<label:<name:"server" value:"main" > label:<name:"status" value:"processing" > label:<name:"type" value:"bar" > gauge:<value:1 > > `,
3838
"myapp_events_total": `name:"myapp_events_total" help:"The total number of events (created 1h ago or newer)" type:GAUGE metric:<label:<name:"server" value:"main" > label:<name:"type" value:"bar" > gauge:<value:2 > > metric:<label:<name:"server" value:"main" > label:<name:"type" value:"foo" > gauge:<value:1 > > `,
3939
"mongodb_query_exporter_query_total": `name:"mongodb_query_exporter_query_total" help:"How many MongoDB queries have been processed, partitioned by metric, server and status" type:COUNTER metric:<label:<name:"aggregation" value:"aggregation_0" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > metric:<label:<name:"aggregation" value:"aggregation_1" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > metric:<label:<name:"aggregation" value:"aggregation_2" > label:<name:"result" value:"SUCCESS" > label:<name:"server" value:"main" > counter:<value:1 > > `,
4040
}
4141

4242
tests := []integrationTest{
43-
/*integrationTest{
44-
name: "integration test using config v1.0 and mongodb:5.0",
45-
configPath: "../example/configv1.yaml",
46-
mongodbImage: "mongo:5.0",
47-
expectedMetrics: expected,
48-
},*/
4943
{
5044
name: "integration test using config v2.0 and mongodb:5.0",
5145
configPath: "../example/configv2.yaml",

cmd/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"os/user"
99
"time"
1010

11-
"github.com/raffis/mongodb-query-exporter/v3/internal/collector"
12-
"github.com/raffis/mongodb-query-exporter/v3/internal/config"
13-
v1 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v1"
14-
v2 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v2"
15-
v3 "github.com/raffis/mongodb-query-exporter/v3/internal/config/v3"
11+
"github.com/raffis/mongodb-query-exporter/v5/internal/collector"
12+
"github.com/raffis/mongodb-query-exporter/v5/internal/config"
13+
v1 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v1"
14+
v2 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v2"
15+
v3 "github.com/raffis/mongodb-query-exporter/v5/internal/config/v3"
1616

1717
"github.com/prometheus/client_golang/prometheus"
1818
"github.com/prometheus/client_golang/prometheus/promhttp"

0 commit comments

Comments
 (0)