-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream-main' into upstream-merge
- Loading branch information
Showing
497 changed files
with
2,899 additions
and
1,078 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
name: Validate filenames | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "ct/*.sh" | ||
- "install/*.sh" | ||
- "json/*.json" | ||
- ".github/workflows/validate-filenames.yml" | ||
|
||
jobs: | ||
check-files: | ||
name: Check changed files | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 # Ensure the full history is fetched for accurate diffing | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
run: | | ||
if ${{ github.event_name == 'pull_request' }}; then | ||
echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT | ||
else | ||
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT | ||
fi | ||
- name: "Validate filenames in ct and install directory" | ||
if: always() && steps.changed-files.outputs.files != '' | ||
id: check-scripts | ||
run: | | ||
CHANGED_FILES=$(printf "%s\n" ${{ steps.changed-files.outputs.files }} | { grep -E '^(ct|install)/.*\.sh$' || true; }) | ||
NON_COMPLIANT_FILES="" | ||
for FILE in $CHANGED_FILES; do | ||
BASENAME=$(echo "$(basename "${FILE%.*}")") | ||
if [[ ! "$BASENAME" =~ ^[a-z0-9-]+$ ]]; then | ||
NON_COMPLIANT_FILES="$NON_COMPLIANT_FILES $FILE" | ||
fi | ||
done | ||
if [ -n "$NON_COMPLIANT_FILES" ]; then | ||
echo "files=$NON_COMPLIANT_FILES" >> $GITHUB_OUTPUT | ||
echo "Non-compliant filenames found, change to lowercase:" | ||
for FILE in $NON_COMPLIANT_FILES; do | ||
echo "$FILE" | ||
done | ||
exit 1 | ||
fi | ||
- name: "Validate filenames in json directory." | ||
if: always() && steps.changed-files.outputs.files != '' | ||
id: check-json | ||
run: | | ||
CHANGED_FILES=$(printf "%s\n" ${{ steps.changed-files.outputs.files }} | { grep -E '^json/.*\.json$' || true; }) | ||
NON_COMPLIANT_FILES="" | ||
for FILE in $CHANGED_FILES; do | ||
BASENAME=$(echo "$(basename "${FILE%.*}")") | ||
if [[ ! "$BASENAME" =~ ^[a-z0-9-]+$ ]]; then | ||
NON_COMPLIANT_FILES="$NON_COMPLIANT_FILES $FILE" | ||
fi | ||
done | ||
if [ -n "$NON_COMPLIANT_FILES" ]; then | ||
echo "files=$NON_COMPLIANT_FILES" >> $GITHUB_OUTPUT | ||
echo "Non-compliant filenames found, change to lowercase:" | ||
for FILE in $NON_COMPLIANT_FILES; do | ||
echo "$FILE" | ||
done | ||
exit 1 | ||
fi | ||
- name: Post results and comment | ||
if: always() && steps.check-scripts.outputs.files != '' && steps.check-json.outputs.files != '' && github.event_name == 'pull_request' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const result = "${{ job.status }}" === "success" ? "success" : "failure"; | ||
const nonCompliantFiles = { | ||
script: "${{ steps.check-scripts.outputs.files }}", | ||
JSON: "${{ steps.check-json.outputs.files }}", | ||
}; | ||
const issueNumber = context.payload.pull_request | ||
? context.payload.pull_request.number | ||
: null; | ||
const commentIdentifier = "validate-filenames"; | ||
let newCommentBody = `<!-- ${commentIdentifier}-start -->\n### Filename validation\n\n`; | ||
if (result === "failure") { | ||
newCommentBody += ":x: We found issues in the following changed files:\n\n"; | ||
for (const [check, files] of Object.entries(nonCompliantFiles)) { | ||
if (files) { | ||
newCommentBody += `**${check.charAt(0).toUpperCase() + check.slice(1)} filename invalid:**\n${files | ||
.trim() | ||
.split(" ") | ||
.map((file) => `- ${file}`) | ||
.join("\n")}\n\n`; | ||
} | ||
} | ||
newCommentBody += | ||
"Please change the filenames to lowercase and use only alphanumeric characters and dashes.\n"; | ||
} else { | ||
newCommentBody += `:rocket: All files passed filename validation!\n`; | ||
} | ||
newCommentBody += `\n\n<!-- ${commentIdentifier}-end -->`; | ||
if (issueNumber) { | ||
const { data: comments } = await github.rest.issues.listComments({ | ||
...context.repo, | ||
issue_number: issueNumber, | ||
}); | ||
const existingComment = comments.find( | ||
(comment) => comment.user.login === "github-actions[bot]", | ||
); | ||
if (existingComment) { | ||
if (existingComment.body.includes(commentIdentifier)) { | ||
const re = new RegExp(String.raw`<!-- ${commentIdentifier}-start -->[\s\S]*?<!-- ${commentIdentifier}-end -->`, ""); | ||
newCommentBody = existingComment.body.replace(re, newCommentBody); | ||
} else { | ||
newCommentBody = existingComment.body + '\n\n---\n\n' + newCommentBody; | ||
} | ||
await github.rest.issues.updateComment({ | ||
...context.repo, | ||
comment_id: existingComment.id, | ||
body: newCommentBody, | ||
}); | ||
} else { | ||
await github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: issueNumber, | ||
body: newCommentBody, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
name: Validate script formatting | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
paths: | ||
- "**/*.sh" | ||
- "**/*.func" | ||
- ".github/workflows/validate-formatting.yaml" | ||
|
||
jobs: | ||
shfmt: | ||
name: Check changed files | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
run: | | ||
if ${{ github.event_name == 'pull_request' }}; then | ||
echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT | ||
else | ||
echo "files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep -E '\.(sh|func)$' | xargs)" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Set up Go | ||
if: steps.changed-files.outputs.files != '' | ||
uses: actions/setup-go@v5 | ||
|
||
- name: Install shfmt | ||
if: steps.changed-files.outputs.files != '' | ||
run: | | ||
go install mvdan.cc/sh/v3/cmd/shfmt@latest | ||
echo "$GOPATH/bin" >> $GITHUB_PATH | ||
- name: Run shfmt | ||
if: steps.changed-files.outputs.files != '' | ||
id: shfmt | ||
run: | | ||
set +e | ||
shfmt_output=$(shfmt -d ${{ steps.changed-files.outputs.files }}) | ||
if [[ $? -eq 0 ]]; then | ||
exit 0 | ||
else | ||
echo "diff=\"$(echo -n "$shfmt_output" | base64 -w 0)\"" >> $GITHUB_OUTPUT | ||
printf "%s" "$shfmt_output" | ||
exit 1 | ||
fi | ||
- name: Post comment with results | ||
if: always() && steps.changed-files.outputs.files != '' && github.event_name == 'pull_request' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const result = "${{ job.status }}" === "success" ? "success" : "failure"; | ||
const diff = Buffer.from( | ||
${{ steps.shfmt.outputs.diff }}, | ||
"base64", | ||
).toString(); | ||
const issueNumber = context.payload.pull_request | ||
? context.payload.pull_request.number | ||
: null; | ||
const commentIdentifier = "validate-formatting"; | ||
let newCommentBody = `<!-- ${commentIdentifier}-start -->\n### Script formatting\n\n`; | ||
if (result === "failure") { | ||
newCommentBody += | ||
`:x: We found issues in the formatting of the following changed files:\n\n\`\`\`diff\n${diff}\n\`\`\`\n`; | ||
} else { | ||
newCommentBody += `:rocket: All changed shell scripts are formatted correctly!\n`; | ||
} | ||
newCommentBody += `\n\n<!-- ${commentIdentifier}-end -->`; | ||
if (issueNumber) { | ||
const { data: comments } = await github.rest.issues.listComments({ | ||
...context.repo, | ||
issue_number: issueNumber, | ||
}); | ||
const existingComment = comments.find( | ||
(comment) => comment.user.login === "github-actions[bot]", | ||
); | ||
if (existingComment) { | ||
if (existingComment.body.includes(commentIdentifier)) { | ||
const re = new RegExp( | ||
String.raw`<!-- ${commentIdentifier}-start -->[\s\S]*?<!-- ${commentIdentifier}-end -->`, | ||
"", | ||
); | ||
newCommentBody = existingComment.body.replace(re, newCommentBody); | ||
} else { | ||
newCommentBody = existingComment.body + "\n\n---\n\n" + newCommentBody; | ||
} | ||
await github.rest.issues.updateComment({ | ||
...context.repo, | ||
comment_id: existingComment.id, | ||
body: newCommentBody, | ||
}); | ||
} else { | ||
await github.rest.issues.createComment({ | ||
...context.repo, | ||
issue_number: issueNumber, | ||
body: newCommentBody, | ||
}); | ||
} | ||
} |
Oops, something went wrong.