Skip to content

Commit

Permalink
Use workflow runs to publish comments (#2000)
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim authored Jan 3, 2025
1 parent da64416 commit 743446b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 28 deletions.
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

0 comments on commit 743446b

Please sign in to comment.