forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'aibaars/pr-qhelp-check' into main
- Loading branch information
Showing
3 changed files
with
71 additions
and
16 deletions.
There are no files selected for viewing
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,29 @@ | ||
name: Post pull-request comment | ||
on: | ||
workflow_run: | ||
workflows: ["Query help preview"] | ||
types: | ||
- completed | ||
|
||
permissions: | ||
pull-requests: write | ||
|
||
jobs: | ||
post_comment: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download artifact | ||
run: gh run download "${{ github.event.workflow_run.id }}" --repo "${{ github.repository }}" --name "comment" | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
- run: | | ||
PR=$(grep -o '^[0-9]\+$' pr.txt) | ||
PR_HEAD_SHA=$(gh api "/repos/${{ github.repository }}/pulls/${PR}" --jq .head.sha) | ||
# Check that the pull-request head SHA matches the head SHA of the workflow run | ||
if [ "${WORKFLOW_RUN_HEAD_SHA}" != "${PR_HEAD_SHA}" ]; then | ||
exit 1 | ||
fi | ||
cat comment.txt | gh pr comment "${PR}" --repo "${{ github.repository }}" -F - | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_commit.id }} |
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 |
---|---|---|
@@ -1,39 +1,65 @@ | ||
name: Query help preview | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- 'rc/*' | ||
- "rc/*" | ||
paths: | ||
- "ruby/**/*.qhelp" | ||
|
||
jobs: | ||
qhelp: | ||
permissions: | ||
contents: read | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo "${{ github.event.number }}" > pr.txt | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: comment | ||
path: pr.txt | ||
retention-days: 1 | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 2 | ||
persist-credentials: false | ||
- uses: ./.github/actions/fetch-codeql | ||
- name: Determine changed files | ||
id: changes | ||
run: | | ||
echo -n "::set-output name=qhelp_files::" | ||
(git diff --name-only --diff-filter=ACMRT HEAD~1 HEAD | grep .qhelp$ | grep -v .inc.qhelp; | ||
git diff --name-only --diff-filter=ACMRT HEAD~1 HEAD | grep .inc.qhelp$ | xargs -d '\n' -rn1 basename | xargs -d '\n' -rn1 git grep -l) | | ||
sort -u | xargs -d '\n' -n1 printf "'%s' " | ||
- uses: ./.github/actions/fetch-codeql | ||
(git diff -z --name-only --diff-filter=ACMRT HEAD~1 HEAD | grep -z '.qhelp$' | grep -z -v '.inc.qhelp'; | ||
git diff -z --name-only --diff-filter=ACMRT HEAD~1 HEAD | grep -z '.inc.qhelp$' | xargs --null -rn1 basename | xargs --null -rn1 git grep -z -l) | | ||
grep -z '.qhelp$' | grep -z -v '^-' | sort -z -u > "${{ runner.temp }}/paths.txt" | ||
- name: QHelp preview | ||
if: ${{ steps.changes.outputs.qhelp_files }} | ||
run: | | ||
( echo "QHelp previews:"; | ||
for path in ${{ steps.changes.outputs.qhelp_files }} ; do | ||
EXIT_CODE=0 | ||
echo "QHelp previews:" > comment.txt | ||
while read -r -d $'\0' path; do | ||
if [ ! -f "${path}" ]; then | ||
exit 1 | ||
fi | ||
echo "<details> <summary>${path}</summary>" | ||
echo | ||
codeql generate query-help --format=markdown ${path} | ||
codeql generate query-help --format=markdown -- "./${path}" 2> errors.txt || EXIT_CODE="$?" | ||
if [ -s errors.txt ]; then | ||
echo "# errors/warnings:" | ||
echo '```' | ||
cat errors.txt | ||
cat errors.txt 1>&2 | ||
echo '```' | ||
fi | ||
echo "</details>" | ||
done) | gh pr comment "${{ github.event.pull_request.number }}" -F - | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
done < "${{ runner.temp }}/paths.txt" >> comment.txt | ||
exit "${EXIT_CODE}" | ||
- if: always() | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: comment | ||
path: comment.txt | ||
retention-days: 1 |