Skip to content

Use workflow runs to publish comments #2000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2025
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
57 changes: 57 additions & 0 deletions .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Artifacts
on:
workflow_run:
workflows: ["CI"]
types:
- completed

permissions:
pull-requests: write

jobs:
notify:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- uses: actions/github-script@v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id
});

if (artifacts.data.total_count !== 1) {
throw new Error('Expected one artifact')
}

const artifactUrl = artifacts.data.artifacts[0].archive_download_url;
const commentBody = `<!-- build-artifact-comment -->\n📦 Docs artifacts are ready: ${artifactUrl}`;

const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});

const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('<!-- build-artifact-comment -->')
);

if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
}
29 changes: 1 addition & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: CI

on: [pull_request, push]

permissions:
checks: write

env:
MIX_ENV: test

Expand Down Expand Up @@ -41,7 +38,7 @@ jobs:

- run: mix deps.get

# Generate docs artifact
# Generate and upload artifacts
- name: Generate docs
run: |
mix build
Expand All @@ -54,30 +51,6 @@ jobs:
with:
name: docs
path: doc/
overwrite: true

- name: Docs report
uses: actions/github-script@v7
continue-on-error: true
env:
ARTIFACT_ID: ${{ steps.docs-upload.outputs.artifact-id }}
with:
script: |
const artifactUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/artifacts/${process.env.ARTIFACT_ID}`;

await github.rest.checks.create({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Docs artifacts',
head_sha: context.sha,
status: 'completed',
conclusion: 'success',
output: {
title: '',
summary: '',
text: artifactUrl
}
});

# Test Elixir
- run: mix format --check-formatted
Expand Down