probe for root dir instead of guessing #605
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
name: Try | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
acknowledge: | |
runs-on: ubuntu-latest | |
if: github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && (contains(toJson(github.event.comment.body), '\n/ci try') || startsWith(github.event.comment.body, '/ci try')) | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Acknowledge command | |
id: acknowledge | |
run: | | |
gh pr comment ${{ github.event.issue.number }} --body "<!--try-ack-comment--> | |
Starting try run. [Link to action](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.issue.number }})" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
continue-on-error: true | |
try: | |
if: github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && (contains(toJson(github.event.comment.body), '\n/ci try') || startsWith(github.event.comment.body, '/ci try')) | |
uses: ./.github/workflows/ci.yml | |
with: | |
matrix-args: try --comment "${{ github.event.comment.body }}" --pr ${{ github.event.issue.number }} | |
checkout-ref: refs/pull/${{ github.event.issue.number }}/head | |
comment: | |
needs: [try, acknowledge] | |
if: always() && needs.try.result != 'skipped' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Minimize existing comments | |
run: | | |
COMMENTS=$(gh pr view ${{ github.event.issue.number }} --json comments --jq '.comments[] | select((.body | contains("<!--try-conclusion-comment-->") or contains("<!--try-ack-comment-->")) and (.author.login == "github-actions") and (.isMinimized | not)) | .id') | |
while read -r comment_id; do | |
gh api graphql -f query='mutation { minimizeComment(input: { classifier: OUTDATED, subjectId: "'"$comment_id"'" }) { minimizedComment { isMinimized } } }' | |
done <<< "$COMMENTS" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
continue-on-error: true | |
# comment on the PR with the result and links to the logs using gh cli | |
# Something like `### Try build: [{result}]({link_to_logs})` | |
# the url to the logs are on jobs[name="try"].url gathered with `gh run view ${{ github.run_id }} --json jobs` | |
- name: Comment on PR | |
run: | | |
PR_ID=${{ github.event.issue.number }} | |
gh run view ${{ github.run_id }} --json jobs |\ | |
jq -r --arg pr_id "$PR_ID" --arg comment "${{ github.event.comment.html_url }}" ' | |
def box: .conclusion | if . == "success" then "✔️ " elif . == "skipped" then "🛇 " else "❌ " end; | |
def job_to_md: . | "- [\(.name)](\(.url)?pr=\($pr_id)\(.conclusion | if . == "success" then "#step:10:1)" else "#)" end) - \(box)"; | |
def wrap_if_needed: | |
(.[0].conclusion | if . == "success" then "#### Successful Jobs\n\n" else "#### Failed Jobs\n\n" end) + | |
if length > 10 then | |
"<details>\n<summary>List</summary>\n\n\(map(job_to_md) | join("\n"))\n\n</details>\n" | |
else | |
map(job_to_md) | join("\n") + "\n" | |
end; | |
"<!--try-conclusion-comment-->\n## [Try](\(.jobs[] | select(.name == "try / generate-matrix") | .url + "#step:4:18")) run for [comment](\($comment))\n\n" + | |
"\(.jobs[] | select(.name == "try / conclusion") | job_to_md)\n\n" + | |
([.jobs[] | select(.name | startswith("try / target")) | select(.name | contains("matrix.pretty") | not ) | . as $job | | |
{conclusion: $job.conclusion, name: ($job.name | capture("\\((?<name>[^,]+),.*") | .name), url: $job.url} ] | | |
group_by(if .conclusion == "success" then "success" else "failure" end) | | |
map(wrap_if_needed) | | |
join("\n"))' |\ | |
gh pr comment "$PR_ID" --body "$(< /dev/stdin)" | |
env: | |
GH_TOKEN: ${{ github.token }} |