forked from cloudflare/pint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
exec bash -x ./webserver.sh & | ||
exec bash -c 'while [ ! -f server.pid ]; do sleep 1 ; done' | ||
|
||
mkdir testrepo | ||
cd testrepo | ||
exec git init --initial-branch=main . | ||
|
||
cp ../src/v1.yml rules.yml | ||
cp ../src/.pint.hcl . | ||
env GIT_AUTHOR_NAME=pint | ||
env GIT_AUTHOR_EMAIL=pint@example.com | ||
env GIT_COMMITTER_NAME=pint | ||
env GIT_COMMITTER_EMAIL=pint@example.com | ||
exec git add . | ||
exec git commit -am 'import rules and config' | ||
|
||
exec git checkout -b v2 | ||
cp ../src/v2.yml rules.yml | ||
exec git commit -am 'v2' | ||
|
||
env BITBUCKET_AUTH_TOKEN="12345" | ||
pint.ok -l debug --no-color ci | ||
! stdout . | ||
stderr 'level=debug msg="Sending a request to BitBucket" method=PUT' | ||
stderr 'level=debug msg="BitBucket request completed" status=200' | ||
stderr 'level=debug msg="Sending a request to BitBucket" method=DELETE' | ||
stderr 'level=debug msg="BitBucket request completed" status=200' | ||
exec sh -c 'cat ../server.pid | xargs kill' | ||
|
||
-- src/v1.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/v2.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
repository { | ||
bitbucket { | ||
uri = "http://127.0.0.1:8080" | ||
timeout = "10s" | ||
project = "prometheus" | ||
repository = "rules" | ||
} | ||
} | ||
|
||
-- webserver.go -- | ||
package main | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
"time" | ||
) | ||
|
||
func main() { | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
io.WriteString(w, "OK") | ||
}) | ||
|
||
listener, err := net.Listen("tcp", "127.0.0.1:8080") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
server := &http.Server{ | ||
Addr: "127.0.0.1:8080", | ||
} | ||
|
||
go func() { | ||
_ = server.Serve(listener) | ||
}() | ||
|
||
pid := os.Getpid() | ||
err = os.WriteFile("server.pid", []byte(strconv.Itoa(pid)), 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
stop := make(chan os.Signal, 1) | ||
signal.Notify(stop, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
<-stop | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
server.Shutdown(ctx) | ||
} | ||
|
||
-- webserver.sh -- | ||
env GOCACHE=$TMPDIR go run webserver.go |