Skip to content

Commit a0632d4

Browse files
authored
chore(ci): publish pre-release version (#82)
Changes: - add a job to test the package to ensure it can be loaded. - add release workflow. - update main
1 parent c9a6a4c commit a0632d4

File tree

5 files changed

+308
-4
lines changed

5 files changed

+308
-4
lines changed

.github/workflows/dev.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Pull Request
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- '!main'
7+
tags:
8+
- '!tips'
9+
- '!v*.*.*'
10+
11+
jobs:
12+
format:
13+
runs-on: ubuntu-22.04
14+
container: "datadog/docker-library:kong-plugin-ddtrace-ci"
15+
steps:
16+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
17+
- name: "Lint"
18+
run: stylua --check kong/ spec/
19+
- name: "Static analysis"
20+
run: luacheck kong spec
21+
22+
run-test:
23+
runs-on: ubuntu-22.04
24+
steps:
25+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
26+
- uses: Kong/kong-pongo-action@5972effad7a566aed12b879b559bbff07d258d51 #v1.0.3
27+
with:
28+
kong_version: stable
29+
pongo_version: latest
30+
- run: pongo run --no-datadog-agent --no-postgres --no-cassandra -- --coverage
31+
- name: Publish code coverage summary
32+
run: |
33+
beg=$( grep -n "Summary" < luacov.report.out | cut -d ':' -f1 )
34+
tail --lines=+${beg} luacov.report.out >> $GITHUB_STEP_SUMMARY
35+
- name: Upload coverage reports to Codecov
36+
uses: codecov/codecov-action@e0b68c6749509c5f83f984dd99a76a1c1a231044 #v4.0.1
37+
with:
38+
token: ${{ secrets.CODECOV_TOKEN }}
39+
slug: DataDog/kong-plugin-ddtrace

.github/workflows/main.yml

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
name: main
2-
on: [push, workflow_dispatch]
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
37

48
jobs:
59
format:
610
runs-on: ubuntu-22.04
711
container: "datadog/docker-library:kong-plugin-ddtrace-ci"
812
steps:
9-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
1014
- name: "Lint"
1115
run: stylua --check kong/ spec/
1216
- name: "Static analysis"
@@ -15,8 +19,8 @@ jobs:
1519
run-test:
1620
runs-on: ubuntu-22.04
1721
steps:
18-
- uses: actions/checkout@v3
19-
- uses: Kong/kong-pongo-action@v1
22+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
23+
- uses: Kong/kong-pongo-action@5972effad7a566aed12b879b559bbff07d258d51 #v1.0.3
2024
with:
2125
kong_version: stable
2226
pongo_version: latest
@@ -30,3 +34,86 @@ jobs:
3034
with:
3135
token: ${{ secrets.CODECOV_TOKEN }}
3236
slug: DataDog/kong-plugin-ddtrace
37+
38+
package:
39+
runs-on: ubuntu-22.04
40+
needs: [format, run-test]
41+
steps:
42+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
43+
- name: Install Python
44+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 #v5.0.5
45+
- uses: leafo/gh-actions-lua@8aace3457a2fcf3f3c4e9007ecc6b869ff6d74d6 #v11
46+
- uses: leafo/gh-actions-luarocks@4c082a5fad45388feaeb0798dbd82dbd7dc65bca #v5
47+
- name: Generate version
48+
run: |
49+
ORIGINAL_VERSION="$(grep 'VERSION' kong/plugins/ddtrace/handler.lua | awk -F '"' '{print $2;exit}')"
50+
echo "PLUGIN_VERSION=${ORIGINAL_VERSION}.rc.${GITHUB_SHA::7}" >> $GITHUB_ENV
51+
- name: Update plugin handler version
52+
run: sed -i "s|VERSION = \".*\"|VERSION = \"${PLUGIN_VERSION}\"|" kong/plugins/ddtrace/handler.lua
53+
- name: Package
54+
run: |
55+
TIP_ROCKSPEC="$(python scripts/gen-rockspec.py --version ${PLUGIN_VERSION} --tag tip)"
56+
luarocks pack ${TIP_ROCKSPEC}
57+
- name: Export package
58+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
59+
with:
60+
name: kong-ddtrace-artifact
61+
path: kong-plugin-ddtrace*.rock
62+
if-no-files-found: error
63+
64+
test-package:
65+
runs-on: ubuntu-22.04
66+
needs: package
67+
container:
68+
image: "kong/kong-gateway:3.5.0.0-ubuntu"
69+
options: --user root
70+
steps:
71+
- name: Install dependencies
72+
run: apt update -y && apt install -y zip
73+
- name: Download a single artifact
74+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e #v4.2.1
75+
with:
76+
name: kong-ddtrace-artifact
77+
- name: Install plugin
78+
run: luarocks install kong-plugin-ddtrace*.rock
79+
- name: Start Kong
80+
env:
81+
KONG_DATABASE: off
82+
KONG_PLUGINS: bundled,ddtrace
83+
run: kong start
84+
85+
publish-release-candidate:
86+
runs-on: ubuntu-22.04
87+
needs: test-package
88+
permissions:
89+
contents: write
90+
steps:
91+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
92+
- name: Download a single artifact
93+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e #v4.2.1
94+
with:
95+
name: kong-ddtrace-artifact
96+
- name: Generate pre-release metadata
97+
run: |
98+
{
99+
echo "\`Commit SHA: ${GITHUB_SHA}\`"
100+
echo ""
101+
echo "> [!WARNING]"
102+
echo "> **This is a pre-release build** based on the latest development."
103+
echo "> It may introduce breaking changes, unexpected behavior, and other issues. We recommend using it only in non-critical environments."
104+
echo ""
105+
echo "## Install"
106+
echo "1. Download the rock."
107+
echo "2. Install it using luarock: \`luarock install <ROCK>.src.rock\`"
108+
} >> $RUNNER_TEMP/notes.md
109+
- name: Update tip tag
110+
run: git push origin :tip || true
111+
- name: Create or Update Release
112+
env:
113+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
114+
run: |
115+
gh release delete tip --yes || true
116+
gh release create tip --title "Development (pre-release) build" \
117+
--prerelease \
118+
--notes-file "$RUNNER_TEMP/notes.md" \
119+
--target $GITHUB_SHA kong-plugin-ddtrace*.rock

.github/workflows/release.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
8+
jobs:
9+
package:
10+
runs-on: ubuntu-22.04
11+
steps:
12+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
13+
- name: Install Python
14+
uses: actions/setup-python@8d9ed9ac5c53483de85588cdf95a591a75ab9f55 #v5.0.5
15+
- uses: leafo/gh-actions-lua@8aace3457a2fcf3f3c4e9007ecc6b869ff6d74d6 #v11
16+
- uses: leafo/gh-actions-luarocks@4c082a5fad45388feaeb0798dbd82dbd7dc65bca #v5
17+
- name: Retrieve version
18+
run: |
19+
HANDLER_VERSION="$(grep 'VERSION' kong/plugins/ddtrace/handler.lua | awk -F '"' '{print $2;exit}')"
20+
echo "PLUGIN_VERSION=${HANDLER_VERSION}" >> $GITHUB_ENV
21+
- name: Ensure tag match the version
22+
run: |
23+
if [[ "v${PLUGIN_VERSION}" != "$GITHUB_REF_NAME" ]]; then
24+
echo "version mismatch: ${PLUGIN_VERSION} != ${GITHUB_REF_NAME}" >&2
25+
exit 1
26+
fi
27+
- name: Package
28+
run: |
29+
TIP_ROCKSPEC="$(python scripts/gen-rockspec.py --version ${PLUGIN_VERSION} --tag ${GITHUB_REF_NAME})"
30+
luarocks pack ${TIP_ROCKSPEC}
31+
- name: Export package
32+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 #v4.6.2
33+
with:
34+
name: kong-ddtrace-artifact
35+
path: kong-plugin-ddtrace*.rock kong-plugin-ddtrace*.rockspec
36+
if-no-files-found: error
37+
38+
test-package:
39+
runs-on: ubuntu-22.04
40+
needs: package
41+
container:
42+
image: "kong/kong-gateway:3.5.0.0-ubuntu"
43+
options: --user root
44+
steps:
45+
- name: Install dependencies
46+
run: apt update -y && apt install -y zip
47+
- name: Download a single artifact
48+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e #v4.2.1
49+
with:
50+
name: kong-ddtrace-artifact
51+
- name: Install plugin
52+
run: luarocks install kong-plugin-ddtrace*.rock
53+
- name: Start Kong
54+
env:
55+
KONG_DATABASE: off
56+
KONG_PLUGINS: bundled,ddtrace
57+
run: kong start
58+
59+
publish-release:
60+
runs-on: ubuntu-22.04
61+
needs: test-package
62+
permissions:
63+
contents: write
64+
steps:
65+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
66+
- name: Download rock
67+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e #v4.2.1
68+
with:
69+
name: kong-ddtrace-artifact
70+
- name: Create release
71+
env:
72+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
run: |
74+
gh release create ${GITHUB_REF_NAME} --generate-notes \
75+
--target $GITHUB_SHA kong-plugin-ddtrace*.rock
76+
--verify-tag
77+
- name: Publish to Luarocks
78+
run: luarocks upload kong-plugin-ddtrace*.rockspec kong-plugin-ddtrace*.rock \
79+
--temp-key ${{ secrets.LUAROCKS_KEY }} \
80+
--sign \
81+
--skip-pack
82+

kong-plugin-ddtrace.rockspec

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package = "kong-plugin-ddtrace"
2+
version = "$version-$revision"
3+
4+
source = {
5+
url = "https://github.com/datadog/kong-plugin-ddtrace/archive/$tag.zip",
6+
dir = "kong-plugin-ddtrace-$tag",
7+
}
8+
9+
description = {
10+
summary = "This plugin allows Kong to trace requests and report them to the Datadog Agent",
11+
homepage = "https://github.com/datadog/kong-plugin-ddtrace",
12+
license = "Apache 2.0",
13+
}
14+
15+
dependencies = {
16+
"lua >= 5.1",
17+
"lua-resty-http >= 0.11",
18+
}
19+
20+
build = {
21+
type = "builtin",
22+
modules = {
23+
["kong.plugins.ddtrace.agent_writer"] = "kong/plugins/ddtrace/agent_writer.lua",
24+
["kong.plugins.ddtrace.datadog_propagation"] = "kong/plugins/ddtrace/datadog_propagation.lua",
25+
["kong.plugins.ddtrace.handler"] = "kong/plugins/ddtrace/handler.lua",
26+
["kong.plugins.ddtrace.msgpack_encode"] = "kong/plugins/ddtrace/msgpack_encode.lua",
27+
["kong.plugins.ddtrace.propagation"] = "kong/plugins/ddtrace/propagation.lua",
28+
["kong.plugins.ddtrace.protected_tags"] = "kong/plugins/ddtrace/protected_tags.lua",
29+
["kong.plugins.ddtrace.sampler"] = "kong/plugins/ddtrace/sampler.lua",
30+
["kong.plugins.ddtrace.schema"] = "kong/plugins/ddtrace/schema.lua",
31+
["kong.plugins.ddtrace.span"] = "kong/plugins/ddtrace/span.lua",
32+
["kong.plugins.ddtrace.utils"] = "kong/plugins/ddtrace/utils.lua",
33+
["kong.plugins.ddtrace.w3c_propagation"] = "kong/plugins/ddtrace/w3c_propagation.lua",
34+
},
35+
}

scripts/gen-rockspec.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# Generate a .rockspec from the .rockspec in the root directory
3+
from datetime import date
4+
from string import Template
5+
import re
6+
import os
7+
import sys
8+
import argparse
9+
from pathlib import Path
10+
11+
ROOT = Path(__file__).resolve().parent.parent
12+
ROCKSPEC_TEMPLATE = ROOT / "kong-plugin-ddtrace.rockspec"
13+
14+
# Rockspec format 1.0
15+
VERSION_FORMAT = r"[\w.]+-[\d]+"
16+
17+
18+
def main() -> int:
19+
parser = argparse.ArgumentParser(description="TODO")
20+
parser.add_argument("--version", required=True)
21+
parser.add_argument("--tag", required=True)
22+
parser.add_argument("--output")
23+
24+
args = parser.parse_args()
25+
26+
if not os.path.exists(ROCKSPEC_TEMPLATE):
27+
print(f"Missing template rockspec {ROCKSPEC_TEMPLATE}")
28+
sys.exit(1)
29+
30+
revision = "1"
31+
rockspec_version = f"{args.version}-{revision}"
32+
if not re.match(VERSION_FORMAT, rockspec_version):
33+
print(
34+
f"{rockspec_version} does not follow Rockspec version format: {VERSION_FORMAT}"
35+
)
36+
sys.exit(1)
37+
38+
rockspec = Path(ROCKSPEC_TEMPLATE)
39+
final_rockspec = ROOT / f"{rockspec.stem}-{rockspec_version}.rockspec"
40+
41+
vars = {
42+
"tag": args.tag,
43+
"version": args.version,
44+
"revision": revision,
45+
}
46+
47+
with open(final_rockspec, "w") as fw:
48+
today = date.today()
49+
result = f"-- This file was generated by scripts/gen_rockspec.py on {today}\n"
50+
with open(ROCKSPEC_TEMPLATE, "r") as fr:
51+
src = Template(fr.read())
52+
result += src.substitute(vars)
53+
fw.write(result)
54+
55+
print(final_rockspec)
56+
57+
return 0
58+
59+
60+
if __name__ == "__main__":
61+
sys.exit(main())

0 commit comments

Comments
 (0)