Comment Pull Request #314
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 workflow add comment on PR to help user to fix contribution issue. | |
# See "Check Pull Request" workflow (main.yml) for more details | |
name: Comment Pull Request | |
permissions: | |
pull-requests: write # we need pull-request permission to write comment on PR | |
on: | |
workflow_run: | |
workflows: ["Check Pull Request"] | |
types: | |
- completed | |
env: | |
build_status_filename: "build_status" | |
pr_id_key: "pullrequestid" | |
run_id_key: "runid" | |
jobs: | |
add_comment: | |
runs-on: ubuntu-latest | |
# we don't want to run workflow if "Check Pull Request" is skipped or cancelled | |
# and we don't run this workflow in forks | |
if: ${{ github.repository == 'eclipse-leshan/leshan' && github.event.workflow_run.event == 'pull_request' && (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure')}} | |
strategy: | |
# Maybe we could create this matrix dynamically : | |
# See : https://tomasvotruba.com/blog/2020/11/16/how-to-make-dynamic-matrix-in-github-actions/ | |
matrix: | |
jobstep: [nomerge,sortpom,formatter,build,sortimport,checkstyle,androidcheck,semvercheck,javadoc,unittests,integrationtests,buildstatus] | |
steps: | |
# Get Build Status produced by "Check Pull Request" (main.yml) workflow. | |
# See : https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ | |
- name: Download Build Status Archive | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{env.build_status_filename}} | |
run-id: ${{ github.event.workflow_run.id }} | |
github-token: ${{ github.token }} | |
- name: Read Build Status Properties File | |
id: read_property | |
# unstrusted action use commit ID instead of version | |
uses: christian-draeger/read-properties@908f99d3334be3802ec7cb528395a69d19914e7b #1.1.1 | |
with: | |
path: ${{env.build_status_filename}} | |
properties: ${{env.pr_id_key}} ${{ matrix.jobstep }} ${{env.run_id_key}} | |
- name: Download Add Comment Action | |
if: ${{ steps.read_property.outputs[matrix.jobstep] == 'failure'}} | |
# unstrusted action use commit ID instead of version | |
uses: Bhacaz/checkout-files@e3e34e7daef91a5f237485bb88a260aee4be29dd #v2 | |
with: | |
files: .github/actions/utils/addcomment/action.yml | |
- name: Add Comment on failure | |
if: ${{ steps.read_property.outputs[matrix.jobstep] == 'failure'}} | |
uses: ./.github/actions/utils/addcomment | |
with: | |
pullrequest_id: ${{ steps.read_property.outputs[env.pr_id_key]}} | |
action_name: ${{ matrix.jobstep }} | |
job_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{steps.read_property.outputs[env.run_id_key]}} | |
- name: Delete Comment on Success | |
if: ${{ steps.read_property.outputs[matrix.jobstep] == 'success'}} | |
# unstrusted action use commit ID instead of version | |
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 #v2.9.0 | |
with: | |
number: ${{ steps.read_property.outputs[env.pr_id_key]}} | |
header: ${{matrix.jobstep}} | |
delete: true |