Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
groups:
github-actions:
patterns:
- "*"

- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
groups:
go-dependencies:
patterns:
- "*"
2 changes: 1 addition & 1 deletion .github/workflows/container-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT

- name: Run Trivy
uses: aquasecurity/trivy-action@master
uses: aquasecurity/trivy-action@8f28faec26515256b6d22074d1d2a8986f4cbd87 # master
env:
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db
with:
Expand Down
76 changes: 74 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -18,10 +28,72 @@ jobs:
go-version-file: 'go.mod'

- name: Install dependencies
run: go get .
run: go mod download

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
run: go test -v -race ./...

lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: 'go.mod'

- name: Check go.mod and go.sum are tidy
run: go mod tidy -diff

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.15.0

image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v7

- name: Setup Go
uses: actions/setup-go@v7
with:
go-version-file: 'go.mod'
cache: false

# Matches the Go version selected by release-version.sh
- name: Get Go Version
id: get-go-version
run: |
echo "version=$(go mod edit -json | jq -r '.Toolchain // .Go' | sed 's/go//')" >> $GITHUB_OUTPUT

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Build image
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
load: true
tags: github-exporter:ci
build-args: |
GOLANG_VERSION=${{ steps.get-go-version.outputs.version }}

- name: Run Trivy
uses: aquasecurity/trivy-action@8f28faec26515256b6d22074d1d2a8986f4cbd87 # master
env:
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db
with:
scan-type: image
image-ref: github-exporter:ci
format: table
exit-code: '1'
ignore-unfixed: true
severity: CRITICAL,HIGH
14 changes: 5 additions & 9 deletions exporter/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"encoding/pem"
"os"
"path/filepath"
"testing"

"github.com/githubexporter/github-exporter/config"
Expand All @@ -22,19 +23,14 @@ func writeTempRSAKey(t *testing.T) string {
key, err := rsa.GenerateKey(rand.Reader, 2048)
require.NoError(t, err)

f, err := os.CreateTemp("", "test-github-app-key-*.pem")
require.NoError(t, err)
defer f.Close()

err = pem.Encode(f, &pem.Block{
path := filepath.Join(t.TempDir(), "test-github-app-key.pem")
keyPEM := pem.EncodeToMemory(&pem.Block{
Type: "RSA PRIVATE KEY",
Bytes: x509.MarshalPKCS1PrivateKey(key),
})
require.NoError(t, err)

t.Cleanup(func() { os.Remove(f.Name()) })
require.NoError(t, os.WriteFile(path, keyPEM, 0o600))

return f.Name()
return path
}

func newTestExporter(cfg config.Config) *Exporter {
Expand Down
Loading