diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3279b4e75..6f4dbc779 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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') @@ -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 diff --git a/.github/workflows/try.yml b/.github/workflows/try.yml index 806477193..989a5a6ae 100644 --- a/.github/workflows/try.yml +++ b/.github/workflows/try.yml @@ -2,8 +2,19 @@ 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 "\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 @@ -11,11 +22,20 @@ jobs: 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("") or contains("")) 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` @@ -23,7 +43,23 @@ jobs: 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) + "](" + .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 + "
\nList\n\n\(map(job_to_md) | join("\n"))\n\n
\n" + else + map(job_to_md) | join("\n") + "\n" + end; + "\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), 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 }}