Skip to content

Commit

Permalink
Make try comment prettier (#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis authored Jan 8, 2024
2 parents 5daae4d + a20df8d commit 4cf07b0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
name: target (${{ matrix.pretty }},${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: [shellcheck, test, generate-matrix, check]
if: (github.event_name == 'push' || github.event_name == 'merge_group' || github.event_name == 'issue_comment') && needs.generate-matrix.outputs.matrix != '{}' && needs.generate-matrix.outputs.matrix != '[]' && needs.generate-matrix.outputs.matrix != ''
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' || github.event_name == 'issue_comment') && needs.generate-matrix.outputs.matrix != '{}' && needs.generate-matrix.outputs.matrix != '[]' && needs.generate-matrix.outputs.matrix != ''
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.pretty }}
cancel-in-progress: false
Expand Down Expand Up @@ -240,6 +240,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Push image to GitHub Container Registry
if: >
(github.event_name == 'push' || github.event_name == 'workflow_dispatch') &&
steps.prepare-meta.outputs.has-image && (
github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
startsWith(github.ref, 'refs/tags/v')
Expand Down Expand Up @@ -344,12 +345,9 @@ jobs:
name: podman
runs-on: ubuntu-latest
needs: [shellcheck, test, check]
if: github.event_name == 'push' || github.event_name == 'issue_comment'
strategy:
fail-fast: false
outputs:
has-image: ${{ steps.prepare-meta.outputs.has-image }}
images: ${{ steps.build-docker-image.outputs.images && fromJSON(steps.build-docker-image.outputs.images) }}
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3
Expand Down
42 changes: 39 additions & 3 deletions .github/workflows/try.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,64 @@ 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(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-->\nStarting 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(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
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 '"Diff for [comment]("+$comment+")\n\n- [Run](" + (.jobs[] | select(.name == "try / generate-matrix") | .url) + ")\n" + ([.jobs[] | select(.name | startswith("try / target")) | select(.name | contains("matrix.pretty") | not ) | "- [" + (.name | capture("\\((?<name>[^,]+),.*") | .name) + "](" + .url + "?pr=" + $pr_id + "#step:10:1)"] | join("\n"))' --arg pr_id "$PR_ID" --arg comment "${{ github.event.comment.url }}"|\
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 }}

0 comments on commit 4cf07b0

Please sign in to comment.