Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
name: ${{ format('{0} ({1}, {2})', matrix.action, matrix.runs-on, toJson(matrix.with)) }}
needs: generate-matrix
permissions:
actions: read # needed for artifact_comment action
contents: write # needed for setup_release action
runs-on: ${{ matrix.runs-on }}
container: ${{ matrix.container }}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

| Action | Description | Type | Language |
|-------------------------------------------------------|---------------------------------------------------------------------------------|-----------|------------------|
| [artifact_comment](actions/artifact_comment#readme) | Post workflow artifact links in a sticky pull request comment | composite | javascript |
| [audit_repos](actions/audit_repos#readme) | Audit repositories in an organization | composite | javascript |
| [facebook_post](actions/facebook_post#readme) | Post to Facebook page/group using Graph API | docker | python |
| [get_changed_files](actions/get_changed_files#readme) | Get the list of changed files in a pull request | composite | javascript |
Expand Down
85 changes: 85 additions & 0 deletions actions/artifact_comment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# artifact_comment

Post links to selected workflow artifacts in a pull request comment. The action uses a stable message ID, so later
workflow runs update the existing comment instead of adding another comment.

## 🛠️ Prep Work

Run this action from a `workflow_run` workflow after the CI workflow that uploads the artifacts has completed. This
gives the follow-up workflow its own trusted token, including when the source pull request came from a fork. The token
needs permission to read Actions artifacts and write pull request comments:

```yaml
permissions:
actions: read
pull-requests: write
```

## 🚀 Basic Usage

See [action.yml](action.yml)

```yaml
name: Comment PR Artifacts

on:
workflow_run:
workflows: ["CI"]
types:
- completed

permissions: {}

jobs:
comment:
if: github.event.workflow_run.event == 'pull_request'
permissions:
actions: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Comment with build artifacts
uses: LizardByte/actions/actions/artifact_comment@master
with:
artifact_patterns: |
build-linux-*
build-windows-*
```

Each non-empty line in `artifact_patterns` is matched against the complete artifact name. `*` matches any number of
characters and `?` matches one character. A literal artifact name is therefore also a valid pattern.

## 📥 Inputs

| Name | Description | Default | Required |
|---------------------|------------------------------------------------------------------------------|---------------------------------------|----------|
| `artifact_patterns` | Newline-separated artifact name patterns. Supports `*` and `?` wildcards. | `*` | `false` |
| `dry_run` | Build the comment and outputs without posting it. | `false` | `false` |
| `message_id` | Stable ID used to find and update the existing comment. | `artifact-comment` | `false` |
| `pr_number` | Pull request number. By default it is resolved from the source workflow run. | | `false` |
| `run_id` | Workflow run ID whose artifacts should be listed. | Source workflow run, then current run | `false` |
| `title` | Markdown heading text for the comment. | `Build artifacts` | `false` |
| `token` | GitHub token used to read artifacts and post the pull request comment. | `${{ github.token }}` | `false` |

## 📤 Outputs

| Name | Description |
|-------------------|---------------------------------------------------------------|
| `artifact_count` | Number of artifacts included in the comment. |
| `artifact_names` | Newline-separated names of artifacts included in the comment. |
| `comment_created` | Whether a new pull request comment was created. |
| `comment_body` | Generated Markdown comment body. |
| `comment_id` | ID of the created or updated pull request comment. |
| `comment_updated` | Whether an existing pull request comment was updated. |
| `pr_number` | Pull request number resolved for the source workflow run. |

## 📝 Notes

- The default `message_id` creates one sticky artifact comment per pull request. Set a different ID for each workflow
if multiple workflows should maintain separate artifact comments.
- When no artifact matches, the action updates the comment to say that the source workflow run produced no matching
artifacts. This prevents links from an older run from remaining visible.
- Artifact download links require the reader to sign in to GitHub and stop working when GitHub expires or deletes the
artifact.
- The action first uses the pull request attached to the source workflow run. If GitHub omits that association, it
resolves the open pull request from the source repository, branch, and head SHA.
89 changes: 89 additions & 0 deletions actions/artifact_comment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: "PR Artifact Comment"
description: "Post workflow artifact links in a sticky pull request comment."
author: "LizardByte"

branding:
icon: package
color: green

inputs:
artifact_patterns:
description: |
Newline-separated artifact name patterns to include. Supports * and ? wildcards.
required: false
default: '*'
dry_run:
description: 'Build the comment without posting it.'
required: false
default: 'false'
message_id:
description: 'Stable ID used to update the existing comment on later workflow runs.'
required: false
default: 'artifact-comment'
pr_number:
description: 'Pull request number to comment on. By default it is resolved from the source workflow run.'
required: false
default: ''
run_id:
description: 'Workflow run ID whose artifacts should be listed.'
required: false
default: ${{ github.event.workflow_run.id || github.run_id }}
title:
description: 'Markdown heading text for the artifact comment.'
required: false
default: 'Build artifacts'
token:
description: 'GitHub token used to read artifacts and post the pull request comment.'
required: false
default: ${{ github.token }}

outputs:
artifact_count:
description: 'Number of artifacts included in the comment.'
value: ${{ steps.build_comment.outputs.ARTIFACT_COUNT }}
artifact_names:
description: 'Newline-separated names of artifacts included in the comment.'
value: ${{ steps.build_comment.outputs.ARTIFACT_NAMES }}
comment_created:
description: 'Whether a new pull request comment was created.'
value: ${{ steps.comment.outputs.comment-created }}
comment_body:
description: 'Generated Markdown comment body.'
value: ${{ steps.build_comment.outputs.COMMENT_BODY }}
comment_id:
description: 'ID of the created or updated pull request comment.'
value: ${{ steps.comment.outputs.comment-id }}
comment_updated:
description: 'Whether an existing pull request comment was updated.'
value: ${{ steps.comment.outputs.comment-updated }}
pr_number:
description: 'Pull request number resolved for the source workflow run.'
value: ${{ steps.build_comment.outputs.PR_NUMBER }}

runs:
using: "composite"
steps:
- name: Build artifact comment
id: build_comment
env:
INPUT_ARTIFACT_PATTERNS: ${{ inputs.artifact_patterns }}
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
INPUT_RUN_ID: ${{ inputs.run_id }}
INPUT_TITLE: ${{ inputs.title }}
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ inputs.token }}
script: |
const script = require('${{ github.action_path }}/artifact_comment.js');
await script({ github, context, core });

- name: Add pull request comment
id: comment
if: inputs.dry_run != 'true'
uses: mshick/add-pr-comment@ec328af66588ab8f77cdeb2c264f14aba45bbf59 # v3.12.0
with:
issue: ${{ steps.build_comment.outputs.PR_NUMBER }}
message: ${{ steps.build_comment.outputs.COMMENT_BODY }}
message-id: ${{ inputs.message_id }}
repo-token: ${{ inputs.token }}
Loading
Loading