Skip to content

Commit 7847717

Browse files
authored
Build docs as CI artifacts (#1996)
1 parent 7081ba9 commit 7847717

File tree

1 file changed

+102
-64
lines changed

1 file changed

+102
-64
lines changed

.github/workflows/ci.yml

Lines changed: 102 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,99 +5,137 @@ on:
55
push:
66

77
env:
8-
node-version: 18.x
8+
MIX_ENV: test
99

1010
jobs:
11-
mix_test:
11+
elixir_js_and_lint:
1212
runs-on: ubuntu-20.04
13-
env:
14-
MIX_ENV: test
1513
strategy:
16-
fail-fast: false
1714
matrix:
1815
include:
19-
- pair: # Test very old Elixir and Erlang
20-
elixir: "1.14"
21-
otp: "25"
22-
- pair: # Test Erlang without -doc attribute support
23-
elixir: "1.16"
24-
otp: "26"
25-
- pair: # Test Erlang with -doc attribute support
26-
elixir: "1.17"
27-
otp: "27"
28-
lint: lint
16+
- elixir: "1.17"
17+
otp: "27"
18+
node: 18.x
2919
steps:
3020
- uses: actions/checkout@v3
3121

32-
- uses: erlef/setup-beam@v1
22+
# Setup Node
23+
- uses: actions/setup-node@v3
3324
with:
34-
otp-version: ${{matrix.pair.otp}}
35-
elixir-version: ${{matrix.pair.elixir}}
36-
37-
- name: Install Dependencies
38-
run: mix deps.get
39-
40-
- run: mix format --check-formatted
41-
if: ${{ matrix.lint }}
42-
43-
- run: mix deps.unlock --check-unused
44-
if: ${{ matrix.lint }}
25+
node-version: ${{matrix.node}}
4526

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

48-
- run: mix compile --warnings-as-errors
49-
if: ${{ matrix.lint }}
33+
- run: npm ci --prefix assets
5034

51-
- run: mix test
35+
# Setup Elixir
36+
- uses: erlef/setup-beam@v1
37+
with:
38+
otp-version: ${{ matrix.otp }}
39+
elixir-version: ${{ matrix.elixir }}
5240

53-
- name: Prerelease
54-
run: test/prerelease.sh
41+
- run: mix deps.get
5542

43+
# Generate docs artifact
5644
- name: Generate docs
5745
run: |
58-
mix docs
46+
mix build
5947
test -f doc/index.html && echo "doc/index.html exists."
6048
test -f doc/ExDoc.epub && echo "doc/ExDoc.epub exists."
6149
62-
check_js:
63-
name: Check JS
64-
runs-on: ubuntu-20.04
65-
steps:
66-
- uses: actions/checkout@v3
67-
- uses: actions/setup-node@v3
50+
- name: Upload docs
51+
uses: actions/upload-artifact@v4
52+
id: docs-upload
6853
with:
69-
node-version: ${{ env.node-version }}
70-
- name: Cache npm dependencies
71-
uses: actions/cache@v3
54+
name: docs
55+
path: doc/
56+
overwrite: true
57+
58+
- name: Build update
59+
uses: actions/github-script@v7
60+
if: github.event_name == 'pull_request'
61+
env:
62+
ARTIFACT_ID: ${{ steps.docs-upload.outputs.artifact-id }}
7263
with:
73-
path: ~/.npm
74-
key: ${{ runner.os }}-node-${{ hashFiles('asssets/package-lock.json') }}
75-
- run: npm install --prefix assets
64+
script: |
65+
const artifactUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}/artifacts/${process.env.ARTIFACT_ID}`;
66+
const commentBody = `<!-- build-artifact-comment -->\n📦 Docs artifacts are ready: ${artifactUrl}`;
67+
68+
const comments = await github.rest.issues.listComments({
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
issue_number: context.issue.number,
72+
});
73+
74+
const botComment = comments.data.find(comment =>
75+
comment.user.type === 'Bot' &&
76+
comment.body.includes('<!-- build-artifact-comment -->')
77+
);
78+
79+
if (botComment) {
80+
await github.rest.issues.updateComment({
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
comment_id: botComment.id,
84+
body: commentBody
85+
});
86+
} else {
87+
await github.rest.issues.createComment({
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
issue_number: context.issue.number,
91+
body: commentBody
92+
});
93+
}
94+
95+
# Test Elixir
96+
- run: mix format --check-formatted
97+
- run: mix deps.unlock --check-unused
98+
- run: mix compile --force --warnings-as-errors
99+
- run: mix test
100+
- run: test/prerelease.sh
101+
102+
# Test JS
76103
- run: npm run lint --prefix assets
77-
- run: sudo apt-get install xvfb
78-
- run: |
104+
- name: npm run test --prefix assets
105+
run: |
106+
sudo apt-get install xvfb
79107
xvfb-run --auto-servernum npm run test --prefix assets
80108
env:
81109
CI: true
82110

83-
assets:
84-
needs: [check_js]
85-
runs-on: ubuntu-20.04
86-
if: github.ref_name == 'main'
87-
steps:
88-
- uses: actions/checkout@v3
89-
- uses: actions/setup-node@v3
90-
with:
91-
node-version: ${{ env.node-version }}
92-
- name: Cache npm dependencies
93-
uses: actions/cache@v3
94-
with:
95-
path: ~/.npm
96-
key: ${{ runner.os }}-node-${{ hashFiles('asssets/package-lock.json') }}
97-
- run: npm ci --prefix assets
98-
- run: npm run build --prefix assets
111+
# Push updated assets if all good
99112
- name: Push updated assets
113+
if: github.ref_name == 'main'
100114
uses: stefanzweifel/git-auto-commit-action@v4
101115
with:
102116
commit_message: Update assets
103117
file_pattern: formatters
118+
119+
elixir:
120+
runs-on: ubuntu-20.04
121+
strategy:
122+
fail-fast: false
123+
matrix:
124+
include:
125+
# Test very old Elixir and Erlang
126+
- elixir: "1.14"
127+
otp: "25"
128+
# Test Erlang without -doc attribute support
129+
- elixir: "1.16"
130+
otp: "26"
131+
steps:
132+
- uses: actions/checkout@v3
133+
134+
- uses: erlef/setup-beam@v1
135+
with:
136+
otp-version: ${{ matrix.otp }}
137+
elixir-version: ${{ matrix.elixir }}
138+
139+
- run: mix deps.get
140+
- run: mix test
141+
- run: test/prerelease.sh

0 commit comments

Comments
 (0)