Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 99 additions & 66 deletions pipelines/pingcap/docs-cn/latest/pull_verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,80 +10,113 @@ final REFS = readJSON(text: params.JOB_SPEC).refs

prow.setPRDescription(REFS)
pipeline {
agent none
agent {
kubernetes {
namespace K8S_NAMESPACE
yamlFile POD_TEMPLATE_FILE
defaultContainer 'runner'
}
}
options {
timeout(time: 40, unit: 'MINUTES')
parallelsAlwaysFailFast()
}
stages {
stage("Tests") {
matrix {
axes {
axis {
name 'CHECK_CMD'
values "python3 check-file-encoding.py", "python3 check-conflicts.py", "markdownlint",
"python3 check-control-char.py", "python3 check-tags.py", "python3 check-manual-line-breaks.py"
stage('Checkout') {
steps {
dir(REFS.repo) {
sh label: 'set git config', script: """
git config --global --add safe.directory '*'
"""
script {
prow.checkoutRefsWithCacheLock(REFS)
}
}
agent{
kubernetes {
namespace K8S_NAMESPACE
yamlFile POD_TEMPLATE_FILE
defaultContainer 'runner'
}
}
}
stage('Prepare') {
steps {
dir(REFS.repo) {
sh label: 'Prepare check scripts', script: """#!/usr/bin/env bash
set -euo pipefail

rm -rf ../check-scripts
mkdir -p ../check-scripts

wget -O ../check-scripts/check-file-encoding.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-file-encoding.py
wget -O ../check-scripts/check-conflicts.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-conflicts.py
wget -O ../check-scripts/check-control-char.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-control-char.py
wget -O ../check-scripts/check-tags.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-tags.py
wget -O ../check-scripts/check-manual-line-breaks.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-manual-line-breaks.py

ls -al ../check-scripts
"""
}
stages {
stage('Checkout') {
steps {
dir(REFS.repo) {
sh label: "set git config", script: """
git config --global --add safe.directory '*'
"""

script {
prow.checkoutRefsWithCache(REFS)
}
}
}
}
stage('Prepare') {
steps {
dir('check-scripts') {
sh label: 'Prepare', script: """
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-file-encoding.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-conflicts.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-control-char.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-tags.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-manual-line-breaks.py
"""
}
}
}
stage("Test") {
steps {
dir(REFS.repo) {
sh label: "set git config", script: """
git rev-parse --show-toplevel
git status -s .
git log --format="%h %B" --oneline -n 3
"""
// TODO: remove this debug lines
sh """
git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*'
"""
sh label: "check ${CHECK_CMD}", script: """#!/usr/bin/env bash
cp -r ../check-scripts/* ./
diff_docs_files=\$(git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*')

if [[ "${CHECK_CMD}" == "markdownlint" ]]; then
npm install -g markdownlint-cli@0.17.0
fi

${CHECK_CMD} \$diff_docs_files
"""
}
}
}
}
stage('Verify') {
steps {
dir(REFS.repo) {
sh label: 'Debug info', script: """
git rev-parse --show-toplevel
git status -s .
git log --format="%h %B" --oneline -n 3
"""
sh label: 'Run pull_verify checks', script: """#!/usr/bin/env bash
set -uo pipefail

mapfile -t diff_docs_files < <(
git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*'
)

if ((\${#diff_docs_files[@]} == 0)); then
echo 'No changed Markdown files, skip pull_verify checks.'
exit 0
fi

printf 'Changed Markdown files (%s):\\n' "\${#diff_docs_files[@]}"
printf ' - %s\\n' "\${diff_docs_files[@]}"

cp -r ../check-scripts/* ./

failed_checks=()

run_check() {
local name="\$1"
shift

echo "==> Running \${name}"
if "\$@" "\${diff_docs_files[@]}"; then
echo "==> \${name}: PASS"
else
echo "==> \${name}: FAIL"
failed_checks+=("\${name}")
fi
echo
}

run_check 'check-conflicts' python3 ./check-conflicts.py
run_check 'check-control-char' python3 ./check-control-char.py
run_check 'check-tags' python3 ./check-tags.py
run_check 'check-manual-line-breaks' python3 ./check-manual-line-breaks.py
Comment on lines +79 to +100
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of managing check scripts at runtime by copying them or referencing sibling directories, these scripts should be baked into the Docker image. This approach improves CI reliability and performance by ensuring a consistent environment and reducing runtime overhead, consistent with repository practices.

                    failed_checks=()

                    run_check() {
                        local name="\$1"
                        shift

                        echo "==> Running \${name}"
                        if "\$@" "\${diff_docs_files[@]}"; then
                            echo "==> \${name}: PASS"
                        else
                            echo "==> \${name}: FAIL"
                            failed_checks+=("\${name}")
                        fi
                        echo
                    }

                    run_check 'check-file-encoding' python3 /usr/local/bin/check-file-encoding.py
                    run_check 'check-conflicts' python3 /usr/local/bin/check-conflicts.py
                    run_check 'check-control-char' python3 /usr/local/bin/check-control-char.py
                    run_check 'check-tags' python3 /usr/local/bin/check-tags.py
                    run_check 'check-manual-line-breaks' python3 /usr/local/bin/check-manual-line-breaks.py
References
  1. For better CI performance and reliability, bake dependencies into the Docker image instead of installing them at runtime in CI scripts.


echo '==> Installing markdownlint-cli@0.17.0'
if npm install -g markdownlint-cli@0.17.0; then
run_check 'markdownlint' markdownlint
else
echo '==> markdownlint-install: FAIL'
failed_checks+=('markdownlint-install')
fi

run_check 'check-file-encoding' python3 ./check-file-encoding.py

if ((\${#failed_checks[@]} > 0)); then
printf 'pull_verify failed checks (%s):\\n' "\${#failed_checks[@]}"
printf ' - %s\\n' "\${failed_checks[@]}"
exit 1
fi

echo 'All pull_verify checks passed.'
"""
}
}
}
Expand Down
165 changes: 98 additions & 67 deletions pipelines/pingcap/docs/latest/pull_verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,113 @@ final REFS = readJSON(text: params.JOB_SPEC).refs

prow.setPRDescription(REFS)
pipeline {
agent none
environment {
FILE_SERVER_URL = 'http://fileserver.pingcap.net'
agent {
kubernetes {
namespace K8S_NAMESPACE
yamlFile POD_TEMPLATE_FILE
defaultContainer 'runner'
}
}
options {
timeout(time: 40, unit: 'MINUTES')
parallelsAlwaysFailFast()
}
stages {
stage("Tests") {
matrix {
axes {
axis {
name 'CHECK_CMD'
values "python3 check-file-encoding.py", "python3 check-conflicts.py", "markdownlint",
"python3 check-control-char.py", "python3 check-tags.py", "python3 check-manual-line-breaks.py"
stage('Checkout') {
steps {
dir(REFS.repo) {
sh label: 'set git config', script: """
git config --global --add safe.directory '*'
"""
script {
prow.checkoutRefsWithCacheLock(REFS)
}
}
agent{
kubernetes {
namespace K8S_NAMESPACE
yamlFile POD_TEMPLATE_FILE
defaultContainer 'runner'
}
}
}
stage('Prepare') {
steps {
dir(REFS.repo) {
sh label: 'Prepare check scripts', script: """#!/usr/bin/env bash
set -euo pipefail

rm -rf ../check-scripts
mkdir -p ../check-scripts

wget -O ../check-scripts/check-file-encoding.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-file-encoding.py
wget -O ../check-scripts/check-conflicts.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-conflicts.py
wget -O ../check-scripts/check-control-char.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-control-char.py
wget -O ../check-scripts/check-tags.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-tags.py
wget -O ../check-scripts/check-manual-line-breaks.py https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-manual-line-breaks.py

ls -al ../check-scripts
"""
}
stages {
stage('Checkout') {
steps {
dir(REFS.repo) {
sh label: "set git config", script: """
git config --global --add safe.directory '*'
"""
script {
prow.checkoutRefsWithCache(REFS)
}
}
}
}
stage('Prepare') {
steps {
dir('check-scripts') {
sh label: 'Prepare', script: """
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-file-encoding.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-conflicts.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-control-char.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-tags.py
wget https://raw.githubusercontent.com/pingcap/docs/master/scripts/check-manual-line-breaks.py
"""
}
}
}
stage("Test") {
steps {
dir(REFS.repo) {
sh label: "set git config", script: """
git rev-parse --show-toplevel
git status -s .
git log --format="%h %B" --oneline -n 3
"""
// TODO: remove this debug lines
sh """
git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*'
"""
sh label: "check ${CHECK_CMD}", script: """#!/usr/bin/env bash
cp -r ../check-scripts/* ./
diff_docs_files=\$(git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*')

if [[ "${CHECK_CMD}" == "markdownlint" ]]; then
npm install -g markdownlint-cli@0.17.0
fi

${CHECK_CMD} \$diff_docs_files
"""
}
}
}
}
stage('Verify') {
steps {
dir(REFS.repo) {
sh label: 'Debug info', script: """
git rev-parse --show-toplevel
git status -s .
git log --format="%h %B" --oneline -n 3
"""
sh label: 'Run pull_verify checks', script: """#!/usr/bin/env bash
set -uo pipefail

mapfile -t diff_docs_files < <(
git diff-tree --name-only --no-commit-id -r origin/${REFS.base_ref}..HEAD -- '*.md' ':(exclude).github/*'
)

if ((\${#diff_docs_files[@]} == 0)); then
echo 'No changed Markdown files, skip pull_verify checks.'
exit 0
fi

printf 'Changed Markdown files (%s):\\n' "\${#diff_docs_files[@]}"
printf ' - %s\\n' "\${diff_docs_files[@]}"

cp -r ../check-scripts/* ./

failed_checks=()

run_check() {
local name="\$1"
shift

echo "==> Running \${name}"
if "\$@" "\${diff_docs_files[@]}"; then
echo "==> \${name}: PASS"
else
echo "==> \${name}: FAIL"
failed_checks+=("\${name}")
fi
echo
}

run_check 'check-conflicts' python3 ./check-conflicts.py
run_check 'check-control-char' python3 ./check-control-char.py
run_check 'check-tags' python3 ./check-tags.py
run_check 'check-manual-line-breaks' python3 ./check-manual-line-breaks.py
Comment on lines +79 to +100
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of managing check scripts at runtime by copying them or referencing sibling directories, these scripts should be baked into the Docker image. This approach improves CI reliability and performance by ensuring a consistent environment and reducing runtime overhead, consistent with repository practices.

                    failed_checks=()

                    run_check() {
                        local name="\$1"
                        shift

                        echo "==> Running \${name}"
                        if "\$@" "\${diff_docs_files[@]}"; then
                            echo "==> \${name}: PASS"
                        else
                            echo "==> \${name}: FAIL"
                            failed_checks+=("\${name}")
                        fi
                        echo
                    }

                    run_check 'check-file-encoding' python3 /usr/local/bin/check-file-encoding.py
                    run_check 'check-conflicts' python3 /usr/local/bin/check-conflicts.py
                    run_check 'check-control-char' python3 /usr/local/bin/check-control-char.py
                    run_check 'check-tags' python3 /usr/local/bin/check-tags.py
                    run_check 'check-manual-line-breaks' python3 /usr/local/bin/check-manual-line-breaks.py
References
  1. For better CI performance and reliability, bake dependencies into the Docker image instead of installing them at runtime in CI scripts.


echo '==> Installing markdownlint-cli@0.17.0'
if npm install -g markdownlint-cli@0.17.0; then
run_check 'markdownlint' markdownlint
else
echo '==> markdownlint-install: FAIL'
failed_checks+=('markdownlint-install')
fi

run_check 'check-file-encoding' python3 ./check-file-encoding.py

if ((\${#failed_checks[@]} > 0)); then
printf 'pull_verify failed checks (%s):\\n' "\${#failed_checks[@]}"
printf ' - %s\\n' "\${failed_checks[@]}"
exit 1
fi

echo 'All pull_verify checks passed.'
"""
}
}
}
Expand Down