Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test and release workflows using GitHub Actions #13

Merged
merged 4 commits into from
Nov 20, 2024
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
50 changes: 50 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: release

on:
push:
tags:
- "[0-9].[0-9]+.[0-9]+"

jobs:
github-release:
runs-on: ubuntu-latest
steps:
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Version ${{ github.ref_name }}
draft: false
prerelease: false

release-binaries:
runs-on: ubuntu-latest
needs: github-release
strategy:
matrix:
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
exclude:
- goarch: arm64
goos: windows
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Publish Go Binaries
uses: wangyoucao577/go-release-action@v1.52
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
ldflags: -X "main.tagVersion=${{ github.ref_name }}"
extra_files: LICENSE README.md
md5sum: true
sha256sum: true
asset_name: resque-exporter-${{ github.ref_name }}-${{ matrix.goos }}-${{ matrix.goarch }}
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: tests

on:
pull_request:
branches:
- '*'
push:
branches:
- master

jobs:
linting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
go-version-file: go.mod
- name: Run Linter
uses: golangci/golangci-lint-action@v6
with:
version: v1.62.0

unit-testing:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
cache: true
cache-dependency-path: go.sum
go-version-file: go.mod
- name: Build
run: go build -v ./...
- name: Run Tests
run: go test -json ./... > test-results.json
- name: Annotate Tests
if: always()
uses: guyarb/golang-test-annotations@v0.8.0
with:
test-results: test-results.json
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
linters:
disable-all: true
enable:
- govet
- revive
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Resque Exporter

[![tests](https://github.com/Intellection/resque-exporter/actions/workflows/test.yml/badge.svg)](https://github.com/Intellection/resque-exporter/actions/workflows/test.yml) [![release](https://github.com/Intellection/resque-exporter/actions/workflows/release.yml/badge.svg)](https://github.com/Intellection/resque-exporter/actions/workflows/release.yml)

Prometheus exporter for Resque metrics.

## Usage
Expand Down
8 changes: 6 additions & 2 deletions resque_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,19 @@ func main() {
reg.MustRegister(exporter)

http.Handle(*metricPath, promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
http.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
_, err := w.Write([]byte(`<html>
<head><title>Resque Exporter</title></head>
<body>
<h1>Resque Exporter</h1>
<p><a href='` + *metricPath + `'>Metrics</a></p>
</body>
</html>
`))

if err != nil {
log.Error(err)
}
})

log.Infoln("Listening on", *listenAddress)
Expand Down