Skip to content

Commit 3b6bb07

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/examples/datadog/expressjs/lambda-asset/src/multi-c6f6658ed3
2 parents b54b85c + 04e1898 commit 3b6bb07

167 files changed

Lines changed: 4642 additions & 2889 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitallowed‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎.github/CODEOWNERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @awslabs/aws-lambda-adapter-maintainers
1+
* @aws/aws-lambda-tooling

‎.github/scripts/verify-http.sh‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Verify that an example's HTTP endpoint serves the expected response.
4+
#
5+
# Unlike a plain liveness check (any 2xx-4xx == "OK"), this asserts that a
6+
# specific route returns an exact status code and, optionally, that the body
7+
# contains a known substring. This catches broken routing and apps that boot
8+
# but serve the wrong (or empty) content.
9+
#
10+
# Usage:
11+
# verify-http.sh <base_url> <path> <expect_status> [expect_body]
12+
#
13+
# base_url e.g. http://127.0.0.1:3000
14+
# path request path, e.g. / or /healthz
15+
# expect_status comma-separated acceptable status codes, e.g. "200" or "200,307"
16+
# expect_body optional substring that must appear in the response body
17+
#
18+
# Waits up to 90s (wall-clock) for the endpoint to satisfy BOTH conditions
19+
# (the app may still be warming up), then exits 0 on success or 1 with
20+
# diagnostics. Uses a wall-clock deadline plus a short per-request timeout
21+
# (curl -m 5) so a hanging endpoint can't multiply the wait window.
22+
23+
set -uo pipefail
24+
25+
BASE_URL="${1:?base_url required}"
26+
REQ_PATH="${2:-/}"
27+
EXPECT_STATUS="${3:-200}"
28+
EXPECT_BODY="${4:-}"
29+
30+
URL="${BASE_URL%/}${REQ_PATH}"
31+
IFS=',' read -ra ACCEPT <<< "$EXPECT_STATUS"
32+
33+
status_ok() {
34+
local s="$1"
35+
for code in "${ACCEPT[@]}"; do
36+
[ "$s" = "$code" ] && return 0
37+
done
38+
return 1
39+
}
40+
41+
echo "Verifying ${URL} (expect status ${EXPECT_STATUS}${EXPECT_BODY:+, body contains \"${EXPECT_BODY}\"})"
42+
43+
last_status=""
44+
last_body=""
45+
START=$SECONDS
46+
DEADLINE=$((START + 90))
47+
while [ $SECONDS -lt $DEADLINE ]; do
48+
resp="$(curl -s -m 5 -w $'\n%{http_code}' "$URL" 2>/dev/null || true)"
49+
last_status="${resp##*$'\n'}"
50+
last_body="${resp%$'\n'*}"
51+
if status_ok "$last_status"; then
52+
if [ -z "$EXPECT_BODY" ] || grep -qF -- "$EXPECT_BODY" <<< "$last_body"; then
53+
echo "OK after $((SECONDS - START))s: status ${last_status}${EXPECT_BODY:+, body contains \"${EXPECT_BODY}\"}"
54+
exit 0
55+
fi
56+
fi
57+
sleep 1
58+
done
59+
60+
echo "FAIL: expectation not met within 90s (elapsed $((SECONDS - START))s)"
61+
echo " last status: ${last_status:-<none>} (expected ${EXPECT_STATUS})"
62+
[ -n "$EXPECT_BODY" ] && echo " expected body substring: ${EXPECT_BODY}"
63+
echo "--- last response body (first 30 lines) ---"
64+
printf '%s\n' "$last_body" | head -30
65+
exit 1
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Commit Lint Comment
2+
3+
# Privileged follow-up to commitlint.yaml. Triggered by completion of the
4+
# unprivileged Commit Lint workflow; downloads the lint output artifact and
5+
# posts it as a PR comment. This split is the recommended pattern for safely
6+
# performing privileged operations in response to fork PRs:
7+
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
8+
#
9+
# Security: this workflow does not check out PR code. The PR number is
10+
# resolved from the trusted workflow_run event payload (not the artifact),
11+
# and the commitlint text output is rendered inside a dynamically sized
12+
# code fence so embedded backticks cannot escape it.
13+
on:
14+
workflow_run:
15+
workflows: ["Commit Lint"]
16+
types:
17+
- completed
18+
19+
permissions:
20+
contents: read
21+
pull-requests: write
22+
actions: read
23+
24+
jobs:
25+
comment:
26+
name: Comment on PR
27+
if: >
28+
github.event.workflow_run.event == 'pull_request' &&
29+
github.event.workflow_run.conclusion == 'failure'
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Download lint artifact
33+
id: download
34+
uses: actions/download-artifact@v4
35+
with:
36+
name: commitlint-failure
37+
path: lint-artifact
38+
run-id: ${{ github.event.workflow_run.id }}
39+
github-token: ${{ secrets.GITHUB_TOKEN }}
40+
continue-on-error: true
41+
42+
- name: Skip if no artifact
43+
if: steps.download.outcome != 'success'
44+
run: |
45+
echo "No commitlint-failure artifact uploaded by the Commit Lint run; nothing to comment."
46+
47+
- name: Resolve PR number from workflow_run
48+
if: steps.download.outcome == 'success'
49+
id: pr
50+
env:
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
53+
REPO: ${{ github.repository }}
54+
shell: bash
55+
run: |
56+
# Derive PR number from trusted GitHub event data, not the artifact.
57+
# The artifact is produced by an unprivileged pull_request workflow
58+
# whose workflow file PR authors control on fork PRs, so any value
59+
# they write into the artifact could be used to spoof comments onto
60+
# a different PR. head_sha on the workflow_run event is GitHub-set
61+
# and trustworthy.
62+
pr=$(gh api "repos/$REPO/commits/$HEAD_SHA/pulls" \
63+
--jq '.[] | select(.state=="open") | .number' | head -n1)
64+
if ! [[ "$pr" =~ ^[0-9]+$ ]]; then
65+
echo "No open PR found for head SHA $HEAD_SHA; nothing to comment."
66+
exit 0
67+
fi
68+
echo "pr_number=$pr" >> "$GITHUB_OUTPUT"
69+
70+
- name: Post comment
71+
if: steps.download.outcome == 'success' && steps.pr.outputs.pr_number != ''
72+
env:
73+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
PR_NUMBER: ${{ steps.pr.outputs.pr_number }}
75+
REPO: ${{ github.repository }}
76+
shell: bash
77+
run: |
78+
# The artifact contents are untrusted PR-author-controlled commit
79+
# text. Pick a code-fence length that is at least one backtick
80+
# longer than the longest backtick run in the file, so the author
81+
# cannot escape the fence by embedding ``` in a commit message.
82+
max_ticks=$(grep -oE '`+' lint-artifact/commitlint-output.txt 2>/dev/null \
83+
| awk '{ if (length > m) m = length } END { print m+0 }')
84+
fence_len=$((max_ticks + 1))
85+
[ "$fence_len" -lt 3 ] && fence_len=3
86+
fence=$(printf '`%.0s' $(seq 1 "$fence_len"))
87+
{
88+
echo "## Commit message lint failed"
89+
echo ""
90+
echo "One or more commit messages don't follow the [Conventional Commits](https://www.conventionalcommits.org) format required by this project."
91+
echo ""
92+
echo "<details><summary>commitlint output</summary>"
93+
echo ""
94+
echo "$fence"
95+
cat lint-artifact/commitlint-output.txt
96+
echo "$fence"
97+
echo ""
98+
echo "</details>"
99+
echo ""
100+
echo "**Required format:** \`<type>: <description>\` (max 120 chars for the header)"
101+
echo ""
102+
echo "**Allowed types:** \`feat\`, \`fix\`, \`docs\`, \`example\`, \`examples\`, \`chore\`, \`refactor\`, \`perf\`, \`test\`, \`ci\`, \`revert\`"
103+
echo ""
104+
echo "To fix the most recent commit: \`git commit --amend\`"
105+
echo ""
106+
echo "To reword older commits: \`git rebase -i origin/main\`"
107+
} > comment.md
108+
gh pr comment "$PR_NUMBER" --repo "$REPO" --body-file comment.md

‎.github/workflows/commitlint.yaml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@ jobs:
1717
uses: actions/checkout@v4
1818
with:
1919
fetch-depth: 0
20+
persist-credentials: false
2021

2122
- name: Setup Node.js
2223
uses: actions/setup-node@v4
2324
with:
2425
node-version: 20
2526

2627
- name: Install commitlint
27-
run: npm install --save-dev @commitlint/{cli,config-conventional}
28+
run: npm install --ignore-scripts --save-dev @commitlint/{cli,config-conventional}
2829

2930
- name: Lint commits
3031
id: lint
32+
shell: bash
3133
run: |
34+
set -o pipefail
3235
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose 2>&1 | tee commitlint-output.txt
3336
continue-on-error: true
3437

38+
- name: Upload lint output
39+
if: steps.lint.outcome == 'failure'
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: commitlint-failure
43+
path: commitlint-output.txt
44+
retention-days: 1
45+
3546
- name: Show help on failure
3647
if: steps.lint.outcome == 'failure'
3748
run: |

0 commit comments

Comments
 (0)