Skip to content

Commit 4c2790c

Browse files
committed
hacking new release script, and updated code formatters
1 parent 8c18458 commit 4c2790c

23 files changed

+662
-3
lines changed

.circleci/config.yml

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dd-opentracing-cpp/.clang-format: dd-opentracing-cpp/.git
5454

5555
.PHONY: format
5656
format: .clang-format
57-
find src/ -type f \( -name '*.h' -o -name '*.cpp' \) -not \( -name 'json.h' -o -name 'json.cpp' \) -print0 | xargs -0 clang-format-9 -i --style=file
57+
find src/ -type f \( -name '*.h' -o -name '*.cpp' \) -not \( -name 'json.h' -o -name 'json.cpp' \) -print0 | xargs -0 clang-format-14 -i --style=file
5858
find bin/ -type f -name '*.py' -print0 | xargs -0 yapf3 -i
5959
test/bin/format
6060

bin/README.md

100644100755
File mode changed.

bin/generate_jobs.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ cd "$REPO"
1515
name: "build $nginx_tag"
1616
build-image: "datadog/docker-library:nginx-datadog-build-$nginx_tag"
1717
nginx-tag: "$nginx_tag"
18+
filters:
19+
tags:
20+
only: /^v[0-9]+\.[0-9]+\.[0-9]+/
1821
- test:
1922
name: "test $nginx_tag"
2023
requires:
2124
- "build $nginx_tag"
25+
filters:
26+
tags:
27+
only: /^v[0-9]+\.[0-9]+\.[0-9]+/
2228
END_SNIPPET
2329
done } | sed "s/^/$indentation/"

bin/release.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
#!/usr/bin/env python3
2+
"""TODO - Document this
3+
"""
4+
5+
import argparse
6+
import json
7+
import os
8+
import re
9+
import shlex
10+
import shutil
11+
import subprocess
12+
import sys
13+
import urllib.request
14+
15+
16+
class MissingDependency(Exception):
17+
pass
18+
19+
20+
def get_token():
21+
name = 'CIRCLE_CI_API_TOKEN'
22+
token = os.environ.get(name)
23+
if token is None:
24+
raise MissingDependency(
25+
f'{name} must be set in the environment. Note that it must be a "personal" API token.'
26+
)
27+
return token
28+
29+
30+
def get_gh():
31+
exe_path = shutil.which('gh')
32+
if exe_path is None:
33+
raise MissingDependency(
34+
'The "gh" command must be available to publish a release to GitHub. Installation instructions are available at <https://cli.github.com/>.'
35+
)
36+
return exe_path
37+
38+
39+
def get_gpg():
40+
exe_path = shutil.which('gpg')
41+
if exe_path is None:
42+
raise MissingDependency(
43+
'The "gpg" command must be available and configured to be able to create detached signatures of release artifacts.'
44+
)
45+
return exe_path
46+
47+
48+
def get_git():
49+
exe_path = shutil.which('git')
50+
if exe_path is None:
51+
raise MissingDependency(
52+
'The "git" command must be available to tag the release commit.')
53+
return exe_path
54+
55+
56+
def validate_version_tag(tag):
57+
pattern = r'v[0-9]+\.[0-9]+\.[0-9]+'
58+
if re.fullmatch(pattern, tag) is None:
59+
raise ValueError(
60+
f'Tag does not match the regular expression /{pattern}/.')
61+
return tag
62+
63+
64+
def parse_options(args):
65+
parser = argparse.ArgumentParser(
66+
description='Build and publish a release of nginx-datadog.',
67+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
68+
parser.add_argument(
69+
'--remote',
70+
type=str,
71+
default='origin',
72+
help='local name of the git remote that points to GitHub')
73+
parser.add_argument('--no-tag',
74+
action='store_true',
75+
help="don't tag the current HEAD")
76+
parser.add_argument('--pipeline-id',
77+
type=str,
78+
help='use an already-started CircleCI pipeline')
79+
parser.add_argument(
80+
'version_tag',
81+
help='git tag to associate with the release (e.g. "v1.2.3")')
82+
return parser.parse_args()
83+
84+
85+
try:
86+
ci_api_token = get_token()
87+
gh_exe = get_gh()
88+
gpg_exe = get_gpg()
89+
git_exe = get_git()
90+
options = parse_options(sys.argv[1:])
91+
options.version_tag = validate_version_tag(options.version_tag)
92+
except (MissingDependency, ValueError) as error:
93+
print(str(error), file=sys.stderr)
94+
sys.exit(1)
95+
96+
print({
97+
'token': ci_api_token,
98+
'gh': gh_exe,
99+
'gpg': gpg_exe,
100+
'git': git_exe,
101+
'tag': options.version_tag,
102+
'remote': options.remote,
103+
'no-tag': options.no_tag
104+
})
105+
106+
107+
def run(command, *args, **kwargs):
108+
print('+', shlex.join(command), file=sys.stderr)
109+
return subprocess.run(command, *args, **kwargs)
110+
111+
112+
if not options.no_tag:
113+
command = [
114+
git_exe, 'ls-remote', '--tags', options.remote, options.version_tag
115+
]
116+
result = run(command, stdout=subprocess.PIPE, check=True)
117+
if result.stdout:
118+
raise Exception(
119+
f'Tag {options.version_tag} already exists on {options.remote}.')
120+
121+
command = [
122+
git_exe, 'tag', '-a', options.version_tag, '-m',
123+
f'release ${options.version_tag}'
124+
]
125+
run(command, check=True)
126+
127+
command = [git_exe, 'push', options.remote, options.version_tag]
128+
run(command, check=True)
129+
130+
PROJECT_URL = 'https://circleci.com/api/v2/project/gh/DataDog/nginx-datadog'
131+
132+
133+
def send_ci_request(path, payload=None, method=None):
134+
headers = {'Circle-Token': ci_api_token}
135+
if payload is not None:
136+
headers['Content-Type'] = 'application/json; charset=utf-8'
137+
payload = json.dumps(payload).encode('utf8')
138+
139+
url = f'{PROJECT_URL}{path}'
140+
request = urllib.request.Request(url,
141+
data=payload,
142+
headers=headers,
143+
method=method)
144+
print('+', request.get_method(), request.full_url, request.data or '')
145+
146+
response = urllib.request.urlopen(request)
147+
response_body = json.load(response)
148+
if response.status < 200 or response.status > 299:
149+
raise Exception(
150+
f'HTTP error response {response.status}: {response_body}')
151+
return response.status, response_body
152+
153+
154+
# Kick off a CircleCI pipeline.
155+
if options.pipeline_id is not None:
156+
pipeline_id = options.pipeline_id
157+
else:
158+
body = {"tag": options.version_tag}
159+
_, response = send_ci_request('/pipeline', payload=body, method='POST')
160+
pipeline_id = response.get('id')
161+
if pipeline_id is None:
162+
raise Exception(
163+
f'POST [...]/pipeline response did not contain pipeline "id": {response}'
164+
)
165+
166+
# Fetch the pipeline's information. This will contain its jobs.
167+
_, response = send_ci_request(f'/pipeline/{pipeline_id}')
168+
print(response)
169+
170+
# TODO
171+
#
172+
# x tag the current head
173+
# - kick off pipeline
174+
# - get workflows
175+
# - extrace "build-and-test-all" workflow
176+
# - poll workflow's jobs until all are successful
177+
# - for each build job, download artifacts
178+
# - .tgz with GPG detached signature
179+
# - use "gh"
File renamed without changes.

release.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"release_tag": "v0.4.0",
33
"nginx_tags": [
4+
"1.23.1-alpine",
45
"1.23.1",
56
"1.23.0-alpine",
67
"1.23.0",

src/datadog_directive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ char *hijack_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *command, void *conf) no
296296
return hijack_pass_directive(&propagate_fastcgi_datadog_context, cf, command, conf);
297297
}
298298

299-
char *propagate_grpc_datadog_context(ngx_conf_t *cf, ngx_command_t *command,
300-
void *conf) noexcept try {
299+
char *propagate_grpc_datadog_context(ngx_conf_t *cf, ngx_command_t *command, void *conf) noexcept
300+
try {
301301
auto main_conf = static_cast<datadog_main_conf_t *>(
302302
ngx_http_conf_get_module_main_conf(cf, ngx_http_datadog_module));
303303
if (!main_conf->is_tracer_configured) {

test/cases/access_log/test_access_log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
class TestAccessLog(case.TestCase):
11+
1112
def test_default_format(self):
1213
"""Verify that the default access log format contains the trace ID
1314
and span ID.

test/cases/auto_propagation/test_fastcgi.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class TestFastCGI(case.TestCase):
8+
89
def test_auto_propagation(self):
910
return self.run_test('./conf/fastcgi_auto.conf', should_propagate=True)
1011

0 commit comments

Comments
 (0)