diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml new file mode 100644 index 000000000..cdce4a9bf --- /dev/null +++ b/.github/workflows/artifacts.yml @@ -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 = `\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('') + ); + + 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 + }); + } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a4cb901b..5f915454a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,6 @@ name: CI on: [pull_request, push] -permissions: - checks: write - env: MIX_ENV: test @@ -41,7 +38,7 @@ jobs: - run: mix deps.get - # Generate docs artifact + # Generate and upload artifacts - name: Generate docs run: | mix build @@ -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