Skip to content

Commit 37be4cd

Browse files
Cherry-pick 76ebfa4 with conflicts
1 parent 2d80a92 commit 37be4cd

5 files changed

Lines changed: 391 additions & 1 deletion

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: 'Setup Percona Apt Repo'
2+
description: 'Set up Percona Apt Repo for use in GitHub Actions workflows'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Build weekly cache key
7+
id: cache-key
8+
shell: bash -e {0}
9+
run: echo "week=$(date +%G-%V)" >> "$GITHUB_OUTPUT"
10+
11+
- name: Cache percona-release package
12+
id: cache-percona-release
13+
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
14+
with:
15+
path: percona-release_latest.deb
16+
key: percona-release_latest.deb.${{ steps.cache-key.outputs.week }}
17+
18+
- name: Get Percona Apt Repo package (on cache miss)
19+
if: steps.cache-percona-release.outputs.cache-hit != 'true'
20+
shell: bash -e {0}
21+
run: |
22+
curl -sLo percona-release_latest.deb https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb
23+
24+
- name: Install Percona Apt Repo package
25+
shell: bash -e {0}
26+
run: |
27+
sudo apt-get -qq install -y gnupg2 lsb-release
28+
sudo DEBIAN_FRONTEND="noninteractive" dpkg -i percona-release_latest.deb
29+
sudo apt-get update
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Adds a comment with a link to arewefastyet when the "Benchmark me" label is added.
2+
name: arewefastyet comment
3+
4+
permissions: read-all
5+
6+
on:
7+
pull_request_target:
8+
types: [labeled]
9+
10+
jobs:
11+
add_arewefastyet_comment:
12+
name: Add arewefastyet comment
13+
permissions:
14+
pull-requests: write
15+
runs-on: ubuntu-latest
16+
if: github.event.label.name == 'Benchmark me'
17+
18+
steps:
19+
- name: Harden the runner (Audit all outbound calls)
20+
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
21+
with:
22+
egress-policy: audit
23+
24+
- name: Generate GitHub App token
25+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
26+
id: app-token
27+
with:
28+
app-id: ${{ vars.APP_ID }}
29+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
30+
permission-pull-requests: write
31+
32+
- name: Check if comment already exists
33+
id: check_comment
34+
env:
35+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
36+
run: |
37+
# Get all comments on the PR
38+
COMMENTS=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments --jq '.[].body')
39+
40+
# Check if arewefastyet comment already exists
41+
if echo "$COMMENTS" | grep -q "This Pull Request is now handled by arewefastyet"; then
42+
echo "skip=true" >> "$GITHUB_OUTPUT"
43+
echo "arewefastyet comment already exists"
44+
else
45+
echo "skip=false" >> "$GITHUB_OUTPUT"
46+
fi
47+
48+
- name: Add arewefastyet comment
49+
if: steps.check_comment.outputs.skip != 'true'
50+
env:
51+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
52+
run: |
53+
gh pr comment ${{ github.event.pull_request.number }} \
54+
--repo ${{ github.repository }} \
55+
--body "Hello! :wave:
56+
57+
This Pull Request is now handled by arewefastyet. The current HEAD and future commits will be benchmarked.
58+
59+
You can find the performance comparison on the [arewefastyet website](https://benchmark.vitess.io/pr/${{ github.event.pull_request.number }})."

.github/workflows/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,6 @@ jobs:
153153
files: coverage.out
154154
fail_ci_if_error: true
155155
verbose: true
156-
flags: ${{ steps.mode.outputs.is_full_run == 'true' && '' || 'partial' }}
156+
flags: ${{ steps.mode.outputs.is_full_run != 'true' && 'partial' || '' }}
157157
env:
158158
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Updates the website repository with generated error code documentation.
2+
name: Update error code docs
3+
4+
on:
5+
workflow_run:
6+
workflows: ["Generate error code docs"]
7+
types: [completed]
8+
9+
permissions:
10+
contents: read
11+
actions: read
12+
13+
jobs:
14+
update_error_code_docs:
15+
name: Update error code docs
16+
runs-on: ubuntu-latest
17+
if: github.event.workflow_run.conclusion == 'success'
18+
19+
steps:
20+
- name: Harden the runner (Audit all outbound calls)
21+
uses: step-security/harden-runner@bf7454d06d71f1098171f2acdf0cd4708d7b5920 # v2.20.0
22+
with:
23+
egress-policy: audit
24+
25+
- name: Download artifact
26+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
27+
with:
28+
pattern: error-codes-*
29+
path: /tmp/artifact
30+
github-token: ${{ secrets.GITHUB_TOKEN }}
31+
run-id: ${{ github.event.workflow_run.id }}
32+
merge-multiple: true
33+
34+
- name: Read metadata
35+
id: metadata
36+
run: |
37+
if [[ ! -f /tmp/artifact/metadata.json ]]; then
38+
echo "No metadata found, skipping"
39+
echo "skip=true" >> "$GITHUB_OUTPUT"
40+
exit 0
41+
fi
42+
43+
echo "pr_number=$(jq -r '.pr_number' /tmp/artifact/metadata.json)" >> "$GITHUB_OUTPUT"
44+
echo "base_ref=$(jq -r '.base_ref' /tmp/artifact/metadata.json)" >> "$GITHUB_OUTPUT"
45+
46+
- name: Generate GitHub App token
47+
if: steps.metadata.outputs.skip != 'true'
48+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
49+
id: app-token
50+
with:
51+
app-id: ${{ vars.APP_ID }}
52+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
53+
owner: ${{ github.repository_owner }}
54+
repositories: vitess,website
55+
permission-contents: write
56+
permission-pull-requests: write
57+
58+
- name: Determine docs version
59+
if: steps.metadata.outputs.skip != 'true'
60+
id: docs_version
61+
env:
62+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
63+
BASE_REF: ${{ steps.metadata.outputs.base_ref }}
64+
REPO_OWNER: ${{ github.repository_owner }}
65+
run: |
66+
if [[ "$BASE_REF" == "main" ]]; then
67+
# Get the "next" version from website config.toml.
68+
VERSION=$(gh api "repos/${REPO_OWNER}/website/contents/config.toml" \
69+
--jq '.content' | base64 -d | grep 'next = ' | sed 's/.*"\([0-9.]*\)".*/\1/')
70+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
71+
echo "Docs version (from next): $VERSION"
72+
elif [[ "$BASE_REF" =~ ^release-([0-9]+\.[0-9]+)$ ]]; then
73+
VERSION="${BASH_REMATCH[1]}"
74+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
75+
echo "Docs version (from release branch): $VERSION"
76+
else
77+
echo "Unknown base ref: $BASE_REF, skipping"
78+
echo "skip=true" >> "$GITHUB_OUTPUT"
79+
fi
80+
81+
- name: Clone website repository
82+
if: steps.metadata.outputs.skip != 'true' && steps.docs_version.outputs.skip != 'true'
83+
env:
84+
REPO_OWNER: ${{ github.repository_owner }}
85+
run: |
86+
git clone --depth 1 "https://github.com/${REPO_OWNER}/website.git" /tmp/website
87+
88+
- name: Update error documentation
89+
if: steps.metadata.outputs.skip != 'true' && steps.docs_version.outputs.skip != 'true'
90+
id: update_docs
91+
env:
92+
VERSION: ${{ steps.docs_version.outputs.version }}
93+
run: |
94+
DOC_PATH="/tmp/website/content/en/docs/${VERSION}/reference/errors/query-serving.md"
95+
96+
if [[ ! -f "$DOC_PATH" ]]; then
97+
echo "Documentation file not found: $DOC_PATH"
98+
echo "skip=true" >> "$GITHUB_OUTPUT"
99+
exit 0
100+
fi
101+
102+
# Read the generated error codes.
103+
ERROR_CODES=$(cat /tmp/artifact/error_codes.txt)
104+
105+
# Update the documentation between <!-- start --> and <!-- end --> markers.
106+
awk -v codes="$ERROR_CODES" '
107+
/<!-- start -->/ { print; print codes; skip=1; next }
108+
/<!-- end -->/ { skip=0 }
109+
!skip { print }
110+
' "$DOC_PATH" > /tmp/query-serving-new.md
111+
112+
mv /tmp/query-serving-new.md "$DOC_PATH"
113+
114+
# Check if there are actual changes.
115+
cd /tmp/website
116+
if git diff --quiet; then
117+
echo "No changes detected in error code documentation"
118+
echo "skip=true" >> "$GITHUB_OUTPUT"
119+
else
120+
echo "Changes detected in error code documentation"
121+
echo "doc_path=content/en/docs/${VERSION}/reference/errors/query-serving.md" >> "$GITHUB_OUTPUT"
122+
fi
123+
124+
- name: Get GitHub App user ID
125+
if: steps.metadata.outputs.skip != 'true' && steps.docs_version.outputs.skip != 'true' && steps.update_docs.outputs.skip != 'true'
126+
id: get-user-id
127+
env:
128+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
129+
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
130+
run: |
131+
echo "user-id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
132+
133+
- name: Configure Git
134+
if: steps.metadata.outputs.skip != 'true' && steps.docs_version.outputs.skip != 'true' && steps.update_docs.outputs.skip != 'true'
135+
env:
136+
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
137+
USER_ID: ${{ steps.get-user-id.outputs.user-id }}
138+
run: |
139+
git config --global user.name "${APP_SLUG}[bot]"
140+
git config --global user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
141+
142+
- name: Create or update PR on website
143+
if: steps.metadata.outputs.skip != 'true' && steps.docs_version.outputs.skip != 'true' && steps.update_docs.outputs.skip != 'true'
144+
env:
145+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
146+
PR_NUMBER: ${{ steps.metadata.outputs.pr_number }}
147+
DOC_PATH: ${{ steps.update_docs.outputs.doc_path }}
148+
REPO_OWNER: ${{ github.repository_owner }}
149+
REPOSITORY: ${{ github.repository }}
150+
run: |
151+
BRANCH_NAME="update-error-code-${PR_NUMBER}"
152+
153+
cd /tmp/website
154+
155+
# Check if branch already exists.
156+
if gh api "repos/${REPO_OWNER}/website/branches/${BRANCH_NAME}" --silent 2>/dev/null; then
157+
echo "Branch ${BRANCH_NAME} already exists, updating..."
158+
git fetch origin "${BRANCH_NAME}"
159+
git checkout "${BRANCH_NAME}"
160+
git reset --hard origin/prod
161+
else
162+
echo "Creating new branch ${BRANCH_NAME}..."
163+
git checkout -b "${BRANCH_NAME}"
164+
fi
165+
166+
# Stage and commit changes.
167+
git add "$DOC_PATH"
168+
git commit -m "Updated the query-serving error code"
169+
170+
# Push changes.
171+
git push -f "https://x-access-token:${GH_TOKEN}@github.com/${REPO_OWNER}/website.git" "${BRANCH_NAME}"
172+
173+
# Check if PR already exists.
174+
EXISTING_PR=$(gh pr list --repo "${REPO_OWNER}/website" --head "${BRANCH_NAME}" --json number --jq '.[0].number' 2>/dev/null || echo "")
175+
176+
if [[ -n "$EXISTING_PR" ]]; then
177+
echo "PR #${EXISTING_PR} already exists, updated branch"
178+
echo "https://github.com/${REPO_OWNER}/website/pull/${EXISTING_PR}"
179+
else
180+
# Create new PR.
181+
gh pr create \
182+
--repo "${REPO_OWNER}/website" \
183+
--title "Update error code documentation (#${PR_NUMBER})" \
184+
--body "## Description
185+
This Pull Request updates the error code documentation based on the changes made in https://github.com/${REPOSITORY}/pull/${PR_NUMBER}" \
186+
--base prod \
187+
--head "${BRANCH_NAME}"
188+
fi

0 commit comments

Comments
 (0)