-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Rewrite qhelp-pr-preview.yml #6995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8077a49
Switch qhelp-pr-preview.yml to pull_request_target
aibaars 54e9469
QHelp preview: run if paths.txt is non-empty
aibaars ce3a194
Set persist-credentials: false
aibaars 19e010e
fetch-codeql action: unzip in runner.temp
aibaars b128c7c
Don't use local actions
aibaars aeedfd9
Filter out non-qhelp files
aibaars 5e2cab4
Split workflow into separate jobs
aibaars 3fb0139
Protect against flag injection
aibaars a0903c3
Use pull_request + workflow_run instead of pull_request_target
aibaars 9604cd5
Revert "Don't use local actions"
aibaars d1852af
Add error messages
aibaars 501ff12
Use NUL character as separator
aibaars 53b0315
Use 'gh' command to download artifacts
aibaars 18a4722
Remove redundant permissions block
aibaars b9bf597
Address comments
aibaars 7b4460e
Apply suggestions from code review
aibaars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,31 @@ | ||
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 "${WORKFLOW_RUN_ID}" --repo "${GITHUB_REPOSITORY}" --name "comment" | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }} | ||
- run: | | ||
PR="$(grep -o '^[0-9]\+$' pr.txt)" | ||
adityasharad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
echo "PR head SHA ${PR_HEAD_SHA} does not match workflow_run event SHA ${WORKFLOW_RUN_HEAD_SHA}. Stopping." 1>&2 | ||
exit 1 | ||
aibaars marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
gh pr comment "${PR}" --repo "${GITHUB_REPOSITORY}" -F comment.txt | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
WORKFLOW_RUN_HEAD_SHA: ${{ github.event.workflow_run.head_commit.id }} |
This file contains hidden or 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,63 @@ | ||
name: Query help preview | ||
|
||
permissions: | ||
contents: read | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- 'rc/*' | ||
- "rc/*" | ||
paths: | ||
- "ruby/**/*.qhelp" | ||
|
||
jobs: | ||
qhelp: | ||
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) | | ||
adityasharad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.