-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from cloudflare/owner
Add require owner flag to ci command
- Loading branch information
Showing
3 changed files
with
131 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
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,118 @@ | ||
exec bash -x ./webserver.sh & | ||
exec bash -c 'I=0 ; while [ ! -f server.pid ] && [ $I -lt 30 ]; do sleep 1; I=$((I+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 [email protected] | ||
env GIT_COMMITTER_NAME=pint | ||
env [email protected] | ||
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.error -l error --no-color ci --require-owner | ||
! stdout . | ||
cd .. | ||
cmp stderr stderr.txt | ||
exec sh -c 'cat server.pid | xargs kill' | ||
|
||
-- stderr.txt -- | ||
rules.yml:1: rule/owner comments are required in all files, please add a "# pint file/owner $owner" somewhere in this file and/or "# pint rule/owner $owner" on top of each rule (rule/owner) | ||
groups: | ||
|
||
rules.yml:5: alert query doesn't have any condition, it will always fire if the metric exists (alerts/comparison) | ||
expr: sum(foo) by(job) | ||
|
||
level=fatal msg="Fatal error" error="problems found" | ||
-- src/v1.yml -- | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
- alert: rule2 | ||
expr: sum(foo) by(job) | ||
for: 0s | ||
|
||
-- src/v2.yml -- | ||
groups: | ||
- name: foo | ||
rules: | ||
- alert: rule1 | ||
expr: sum(foo) by(job) | ||
- alert: rule2 | ||
expr: sum(foo) by(job) > 0 | ||
|
||
-- src/.pint.hcl -- | ||
ci { | ||
baseBranch = "main" | ||
} | ||
repository { | ||
bitbucket { | ||
uri = "http://127.0.0.1:6071" | ||
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:6071") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
server := &http.Server{ | ||
Addr: "127.0.0.1:6071", | ||
} | ||
|
||
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) | ||
go func() { | ||
time.Sleep(time.Minute*2) | ||
stop <- 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 |
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