Skip to content

Commit

Permalink
chore: update build GHA (#44)
Browse files Browse the repository at this point in the history
* chore: update build GHA

* Update .github/workflows/build.yaml

Co-authored-by: Luke Tucker <[email protected]>

---------

Co-authored-by: Luke Tucker <[email protected]>
  • Loading branch information
leoparente and ltucker authored Jan 27, 2025
1 parent b3abb4b commit b22ab12
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 238 deletions.
40 changes: 40 additions & 0 deletions .github/golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
run:
timeout: 5m
modules-download-mode: readonly

output:
formats: colored-line-number

linters:
enable:
- revive
- errcheck
- unused
- staticcheck
- ineffassign
- govet
- gosimple
- bodyclose
- gci
- gofumpt

issues:
exclude-use-default: false
exclude-rules:
- path: /*.go
text: "package-comments: should have a package comment"
linters:
- revive

severity:
default-severity: error

linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/netboxlabs/orb-discovery)
custom-order: true
go-fumpt:
extra-rules: true
100 changes: 100 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: otlpinf-build

on:
workflow_dispatch:

pull_request:
branches: [ main ]
push:
branches: [ main ]

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

permissions:
contents: write
pull-requests: write

jobs:

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'

- name: get otelcol-contrib
run: make getotelcol

- name: Build binary (go build only)
run: make build

- name: Install additional dependencies
run: go install github.com/mfridman/[email protected]

- name: Run go test
id: go-test
run: |
make test-coverage
echo 'coverage-report<<EOF' >> $GITHUB_OUTPUT
cat .coverage/test-report.md >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
echo "coverage-total=$(cat .coverage/coverage.txt)" >> $GITHUB_OUTPUT
- name: Output Result
if: always()
run: cat .coverage/test-report.md
- name: Find comment
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e #v3.1.0
id: existing-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Go test coverage

- name: Post comment
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 #v4.0.0
with:
comment-id: ${{ steps.existing-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Go test coverage
${{ steps.go-test.outputs.coverage-report }}
Total coverage: ${{ steps.go-test.outputs.coverage-total }}%
edit-mode: replace

package:
if: ${{ github.event_name != 'pull_request' }}
needs: [ test ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf #v3.2.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 #v3.8.0

- name: Login to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 #v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build image and push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 #v6.10.0
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64, linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: netboxlabs/opentelemetry-infinity:develop

68 changes: 0 additions & 68 deletions .github/workflows/main.yaml

This file was deleted.

65 changes: 45 additions & 20 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ on:
branches: [ "main" ]
schedule:
- cron: '0 0 * * 1'

permissions:
packages: write
contents: write

jobs:
check:
outputs:
Expand All @@ -27,33 +32,30 @@ jobs:
release:
runs-on: ubuntu-latest
needs: check
permissions:
packages: write
contents: write
if: needs.check.outputs.release != ''
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Download Version
env:
RELEASE: ${{needs.check.outputs.release}}
run: |
echo "LAST_TAG=`git tag --sort=committerdate | tail -1`" >> $GITHUB_ENV
echo "TAG=$RELEASE" >> $GITHUB_ENV
ARTIFACT_VERSION=${RELEASE:1}
echo "ARTIFACT_VERSION=${RELEASE:1}" >> $GITHUB_ENV
ARTIFACT="otelcol-contrib_${ARTIFACT_VERSION}_linux_amd64.tar.gz"
ARTIFACT_URL="https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/$RELEASE/$ARTIFACT"
mkdir .temp/
wget -O .temp/otelcol-contrib.tar.gz $ARTIFACT_URL
tar -xvzf .temp/otelcol-contrib.tar.gz -C .temp/
mv .temp/otelcol-contrib runner/
rm -rf .temp/
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.20'
go-version: '1.23'

- name: Build Binary
run: make build
Expand All @@ -66,6 +68,17 @@ jobs:
zip -j otlpinf-amd64.zip build/otlpinf
zip -j otelcol-contrib-amd64.zip runner/otelcol-contrib
- name: Download and zip arm64
run: |
ARTIFACT="otelcol-contrib_${{ env.ARTIFACT_VERSION }}_linux_arm64.tar.gz"
ARTIFACT_URL="https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/$RELEASE/$ARTIFACT"
mkdir .temp/
wget -O .temp/otelcol-contrib.tar.gz $ARTIFACT_URL
tar -xvzf .temp/otelcol-contrib.tar.gz -C .temp/
zip -j otelcol-contrib-arm64.zip .temp/otelcol-contrib
rm -rf .temp/
- name: Generate release changelog
run: |
echo "# What's new" > changelog.md
Expand All @@ -80,17 +93,29 @@ jobs:
files: |
otlpinf-amd64.zip
otelcol-contrib-amd64.zip
otelcol-contrib-arm64.zip
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf #v3.2.0

- name: Docker release
run: make release
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 #v3.8.0

- name: Push opentelemetry-infinity container
run: |
docker push -a netboxlabs/opentelemetry-infinity
- name: Login to Docker Hub
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 #v3.3.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build image and push
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 #v6.10.0
with:
context: .
file: docker/Dockerfile
platforms: linux/amd64, linux/arm64
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
netboxlabs/opentelemetry-infinity:latest
netboxlabs/opentelemetry-infinity:${{ env.TAG }}
23 changes: 0 additions & 23 deletions .github/workflows/security.yaml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.vscode/
build/
runner/otelcol-contrib
.coverage/
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ build:
test:
go test -v ./...

testcov:
go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
.PHONY: test-coverage
test-coverage:
@mkdir -p .coverage
@go test -race -cover -json -coverprofile=.coverage/cover.out.tmp ./... | grep -Ev "cmd" | tparse -format=markdown > .coverage/test-report.md
@cat .coverage/cover.out.tmp | grep -Ev "cmd" > .coverage/cover.out
@go tool cover -func=.coverage/cover.out | grep total | awk '{print substr($$3, 1, length($$3)-1)}' > .coverage/coverage.txt

.PHONY: lint
lint:
@golangci-lint run ./... --config .github/golangci.yaml

.PHONY: fix-lint
fix-lint:
@golangci-lint run ./... --config .github/golangci.yaml --fix

container:
docker build --no-cache \
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

<br clear="left"/>

[![Build status](https://github.com/netboxlabs/opentelemetry-infinity/workflows/otel-main/badge.svg)](https://github.com/netboxlabs/opentelemetry-infinity/actions)
[![Build status](https://github.com/netboxlabs/opentelemetry-infinity/actions/workflows/build.yaml/badge.svg)](https://github.com/netboxlabs/opentelemetry-infinity/actions)
[![CodeQL](https://github.com/netboxlabs/opentelemetry-infinity/workflows/CodeQL/badge.svg)](https://github.com/netboxlabs/opentelemetry-infinity/security/code-scanning)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=leoparente_opentelemetry-infinity&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=leoparente_opentelemetry-infinity)
[![CodeCov](https://codecov.io/gh/netboxlabs/opentelemetry-infinity/branch/main/graph/badge.svg)](https://app.codecov.io/gh/netboxlabs/opentelemetry-infinity/tree/main)
[![Go Report Card](https://goreportcard.com/badge/github.com/netboxlabs/opentelemetry-infinity)](https://goreportcard.com/report/github.com/netboxlabs/opentelemetry-infinity)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/netboxlabs/opentelemetry-infinity)

Expand Down
Loading

0 comments on commit b22ab12

Please sign in to comment.