Repository navigation
95 lines (85 loc) · 3.4 KB
/
Copy pathexport-livescripts.yml
File metadata and controls
95 lines (85 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Export live scripts
# Keeps the documentation that is generated from live scripts in step with
# the live scripts: the tutorials under docs/tutorials, and the Getting
# Started section of the README, which is spliced in from
# code/gettingStarted.mlx between two marker comments.
#
# The export itself is not a check. `export` with Run=true embeds an error
# as ordinary output and returns normally, which is how an exported tutorial
# once sat broken for several releases. So the live scripts are run as tests
# first, and nothing is exported unless they pass.
#
# Runs on push to main only, so the commit it makes lands on main and never
# on a pull request head, where it would rewrite the branch under a stack.
#
# The runner has no MATLAB user folder, and the toolbox resolves its instance
# library under userpath, so without one every controlled-term lookup warns
# and the export captures the warning into the documentation. Each MATLAB
# step therefore gives MATLAB a user folder first.
on:
push:
branches: [main]
paths:
- 'code/gettingStarted.mlx'
- 'code/livescripts/**'
- 'code/+openminds/**'
- 'code/generated/**'
- 'tools/+ommtools/**'
- '.github/workflows/export-livescripts.yml'
workflow_dispatch:
# The push goes over SSH with the deploy key, as in prepare-release.yml, so
# the workflow token needs only read access. A push made with a deploy key
# does trigger other workflows, unlike one made with the workflow token; the
# path filter above stops this workflow retriggering itself, and the
# [skip actions] marker on the commit stops the rest.
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
export:
name: Run the live scripts, then export them
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v6
with:
ssh-key: ${{ secrets.DEPLOY_KEY }}
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v3
with:
cache: true
# The gate. TutorialTest runs every live script; an error fails here
# and nothing below runs.
- name: Run the live scripts as tests
uses: matlab-actions/run-command@v3
with:
command: |
addpath(genpath("tools"));
ensureUserpath();
run(fullfile("code", "startup.m"));
results = runtests("TutorialTest");
assertSuccess(results);
- name: Export the live scripts and update the README
uses: matlab-actions/run-command@v3
with:
command: |
addpath(genpath("tools"));
ensureUserpath();
run(fullfile("code", "startup.m"));
ommtools.exportTutorials();
ommtools.updateReadmeLiveSection("README.md", ...
fullfile("docs", "tutorials", "gettingStarted.md"));
- name: Commit exported documentation if changed
run: |
git config user.name "${{ github.workflow }} by ${{ github.actor }}"
git config user.email "${{ secrets.COMMIT_EMAIL_ADDRESS }}"
git fetch
if [[ $(git add README.md docs/tutorials --dry-run | wc -l) -gt 0 ]]; then
git add README.md docs/tutorials
git commit -m "docs: export live scripts to markdown [skip actions]"
git push
else
echo "Nothing to commit"
fi