Skip to content

Commit 31dd6a7

Browse files
committed
Add a magical configurator
1 parent 4053bb6 commit 31dd6a7

File tree

5 files changed

+162
-0
lines changed

5 files changed

+162
-0
lines changed

docs/assets/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
label {
2+
cursor: pointer;
3+
}
4+
5+
.configurator input:not(:checked) + label {
6+
opacity: 0.7;
7+
}

docs/configurator.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<div class="configurator">
2+
<strong>I am developing</strong>
3+
<input type="radio" name="software-kind" id="software-kind-app"><label for="software-kind-app"><strong>an application</strong></label>
4+
<input type="radio" name="software-kind" id="software-kind-lib"><label for="software-kind-lib"><strong>a library</strong> (also track updates of deps)</label>.
5+
<br>
6+
I want to support Linux, <input type="checkbox" id="os-mac"><label for="os-mac">macOS</label>, <input type="checkbox" id="os-win"><label for="os-win">Windows</label>.
7+
<br>
8+
I want to support latest Crystal, <input type="checkbox" id="crystal-ver"><label for="crystal-ver">a particular older version</label> <input type="checkbox" id="crystal-nightly"><label for="crystal-nightly">and follow Crystal nightly</label>.
9+
<br>
10+
<input type="checkbox" id="tool-format"><label for="tool-format">I format code with <code>crystal tool format</code></label>.
11+
<br>
12+
<input type="checkbox" id="cache-shards"><label for="cache-shards">Cache dependencies (worth only if there are many).</label>
13+
14+
{% for is_app in false, true %}
15+
{% for os_win in false, true %}
16+
{% for os_mac in false, true %}
17+
{% for crystal_ver in false, true %}
18+
{% for crystal_nightly in false, true %}
19+
{% for tool_format in false, true %}
20+
{% for cache_shards in false, true %}
21+
22+
<div class="{% for cls in [is_app, not is_app, os_mac, os_win, crystal_ver, crystal_nightly, tool_format, cache_shards] %}{% if cls %}c{{loop.index}} {% endif %}{% endfor %}">
23+
24+
<p>Add this content to your GitHub repository as <code>.github/workflows/ci.yml</code>:</p>
25+
26+
```yaml
27+
on:
28+
push:
29+
pull_request:
30+
branches: [master]
31+
{%- if crystal_nightly or not is_app %}
32+
schedule:
33+
- cron: '0 6 * * 6' # Every Saturday 6 AM
34+
{%- endif %}
35+
jobs:
36+
build:
37+
{%- set unroll = os_win or (crystal_ver and crystal_nightly) %}
38+
{%- if os_mac or os_win or crystal_nightly or crystal_ver %}
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
{%- if unroll %}
43+
include:
44+
- os: ubuntu-latest
45+
{%- if crystal_ver %}
46+
- os: ubuntu-latest
47+
crystal: 0.35.1
48+
{%- endif %}
49+
{%- if crystal_nightly %}
50+
- os: ubuntu-latest
51+
crystal: nightly
52+
{%- endif %}
53+
{%- if os_mac %}
54+
- os: macos-latest
55+
{%- endif %}
56+
{%- if os_win %}
57+
- os: windows-latest
58+
{%- endif %}
59+
{%- else %}
60+
{%- if os_mac or os_win %}
61+
os: [ubuntu-latest{% if os_mac %}, macos-latest{% endif %}{% if os_win %}, windows-latest{% endif %}]
62+
{%- endif %}
63+
{%- if crystal_nightly or crystal_ver %}
64+
crystal: [{% if crystal_ver %}0.35.1, {% endif %}latest{% if crystal_nightly %}, nightly{% endif %}]
65+
{%- endif %}
66+
{%- endif %}
67+
{%- endif %}
68+
runs-on: {% if os_mac or os_win %}{{ "${{ matrix.os }}" }}{% else %}ubuntu-latest{% endif %}
69+
{%- if crystal_nightly %}
70+
env:
71+
SHARDS_OPTS: --ignore-crystal-version
72+
{%- endif %}
73+
steps:
74+
- name: Install Crystal
75+
uses: oprypin/install-crystal@v1
76+
{%- if crystal_nightly or crystal_ver %}
77+
with:
78+
crystal: {{ "${{ matrix.crystal }}" }}
79+
{%- endif %}
80+
- name: Download source
81+
uses: actions/checkout@v2
82+
{%- if cache_shards %}
83+
- name: Cache shards
84+
uses: actions/cache@v2
85+
with:
86+
{%- if is_app %}
87+
path: lib
88+
key: {{ "${{ runner.os }}-shards-${{ hashFiles('**/shard.lock') }}" }}
89+
{%- else %}
90+
path: ~/.cache/shards
91+
key: {{ "${{ runner.os }}-shards-${{ hashFiles('shard.yml') }}" }}
92+
restore-keys: {{ "${{ runner.os }}-shards-" }}
93+
{%- endif %}
94+
{%- endif %}
95+
- name: Install Shards
96+
{%- if is_app %}
97+
run: {% if cache_shards %}shards check || {% endif %}shards install
98+
{%- else %}
99+
run: shards update
100+
{%- endif %}
101+
- name: Run tests
102+
run: crystal spec
103+
{%- if is_app %}
104+
- name: Build
105+
run: shards build
106+
{%- endif %}
107+
{%- if tool_format %}
108+
- name: Check formatting
109+
run: crystal tool format --check
110+
{%- set latest = "== 'latest'" if not unroll else "!= 'nightly'" if not crystal_ver else "== null" -%}
111+
{%- if os_win and (crystal_nightly or crystal_ver) %}
112+
if: matrix.crystal {{ latest }} && matrix.os == 'ubuntu-latest'
113+
{%- elif os_win %}
114+
if: matrix.os == 'ubuntu-latest'
115+
{%- elif crystal_nightly or crystal_ver %}
116+
if: matrix.crystal {{ latest }}{% endif %}
117+
{%- endif %}
118+
```
119+
120+
{%- if is_app %}
121+
<p>Make sure to check <code>shard.lock</code> in to source control. And <code>shard.yml</code> should be checked in, of course.</p>
122+
{%- endif %}
123+
124+
</div>
125+
126+
{% endfor %}
127+
{% endfor %}
128+
{% endfor %}
129+
{% endfor %}
130+
{% endfor %}
131+
{% endfor %}
132+
{% endfor %}
133+
134+
</div>

docs/gen_pages.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import mkdocs_gen_files
2+
3+
with mkdocs_gen_files.open("assets/style.css", "a") as f:
4+
f.write(
5+
"\n"
6+
+ ",\n".join(
7+
f".configurator > input:nth-of-type({i}):checked ~ div:not(.c{i}), "
8+
f".configurator > input:nth-of-type({i}):not(:checked) ~ div.c{i}"
9+
for i in range(1, 10)
10+
)
11+
+ " {\n display: none;\n}\n"
12+
)

docs/mkdocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ theme:
1414
primary: teal
1515
accent: purple
1616

17+
extra_css:
18+
- assets/style.css
19+
1720
plugins:
1821
- search
22+
- macros
1923
- same-dir
24+
- gen-files:
25+
scripts:
26+
- gen_pages.py
2027

2128
markdown_extensions:
2229
- pymdownx.highlight

docs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
mkdocs
22
mkdocs-material
3+
mkdocs-macros-plugin
34
mkdocs-same-dir
5+
mkdocs-gen-files

0 commit comments

Comments
 (0)