Skip to content
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

Build docs as CI artifacts #1996

Merged
merged 9 commits into from
Jan 2, 2025
Merged
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
166 changes: 102 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,99 +5,137 @@ on:
push:

env:
node-version: 18.x
MIX_ENV: test

jobs:
mix_test:
elixir_js_and_lint:
runs-on: ubuntu-20.04
env:
MIX_ENV: test
strategy:
fail-fast: false
matrix:
include:
- pair: # Test very old Elixir and Erlang
elixir: "1.14"
otp: "25"
- pair: # Test Erlang without -doc attribute support
elixir: "1.16"
otp: "26"
- pair: # Test Erlang with -doc attribute support
elixir: "1.17"
otp: "27"
lint: lint
- elixir: "1.17"
otp: "27"
node: 18.x
steps:
- uses: actions/checkout@v3

- uses: erlef/setup-beam@v1
# Setup Node
- uses: actions/setup-node@v3
with:
otp-version: ${{matrix.pair.otp}}
elixir-version: ${{matrix.pair.elixir}}

- name: Install Dependencies
run: mix deps.get

- run: mix format --check-formatted
if: ${{ matrix.lint }}

- run: mix deps.unlock --check-unused
if: ${{ matrix.lint }}
node-version: ${{matrix.node}}

- run: mix deps.compile
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('asssets/package-lock.json') }}

- run: mix compile --warnings-as-errors
if: ${{ matrix.lint }}
- run: npm ci --prefix assets

- run: mix test
# Setup Elixir
- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- name: Prerelease
run: test/prerelease.sh
- run: mix deps.get

# Generate docs artifact
- name: Generate docs
run: |
mix docs
mix build
test -f doc/index.html && echo "doc/index.html exists."
test -f doc/ExDoc.epub && echo "doc/ExDoc.epub exists."

check_js:
name: Check JS
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Upload docs
uses: actions/upload-artifact@v4
id: docs-upload
with:
node-version: ${{ env.node-version }}
- name: Cache npm dependencies
uses: actions/cache@v3
name: docs
path: doc/
overwrite: true

- name: Build update
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
env:
ARTIFACT_ID: ${{ steps.docs-upload.outputs.artifact-id }}
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('asssets/package-lock.json') }}
- run: npm install --prefix assets
script: |
const artifactUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/artifacts/${process.env.ARTIFACT_ID}`;
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
});
}

# Test Elixir
- run: mix format --check-formatted
- run: mix deps.unlock --check-unused
- run: mix compile --force --warnings-as-errors
- run: mix test
- run: test/prerelease.sh

# Test JS
- run: npm run lint --prefix assets
- run: sudo apt-get install xvfb
- run: |
- name: npm run test --prefix assets
run: |
sudo apt-get install xvfb
xvfb-run --auto-servernum npm run test --prefix assets
env:
CI: true

assets:
needs: [check_js]
runs-on: ubuntu-20.04
if: github.ref_name == 'main'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('asssets/package-lock.json') }}
- run: npm ci --prefix assets
- run: npm run build --prefix assets
# Push updated assets if all good
- name: Push updated assets
if: github.ref_name == 'main'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update assets
file_pattern: formatters

elixir:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
# Test very old Elixir and Erlang
- elixir: "1.14"
otp: "25"
# Test Erlang without -doc attribute support
- elixir: "1.16"
otp: "26"
steps:
- uses: actions/checkout@v3

- uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- run: mix deps.get
- run: mix test
- run: test/prerelease.sh