bard 2.0.1

Creates PDF and HTML songbooks out of easy-to-write Markdown sources.
Documentation
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
on: [push, pull_request]

name: CI

env:
  CARGO_DEB: 1.37.0
  CARGO_RPM: 0.8.0
  CARGO_OUTDATED: 0.11.1
  CARGO_AUDIT: 0.17.0
  TECTONIC_VER: 0.14.1

jobs:
  fmt:
    name: Format check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Install rustfmt
        run: rustup component add rustfmt
      - name: Perform format check
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  lints:
    name: Lints
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          components: clippy
          override: true
      - name: Cache cargo tools
        id: cargo-tools-cache
        uses: actions/cache@v3
        with:
          path: cargo-tools
          key: lint-tools-${{ env.CARGO_OUTDATED }}-${{ env.CARGO_AUDIT }}
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: lint-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Install cargo tools if not cached
        if: steps.cargo-tools-cache.outputs.cache-hit != 'true'
        run: |
          cargo install cargo-outdated --version ${{ env.CARGO_OUTDATED }} --root cargo-tools --target-dir cargo-tools-build
          cargo install cargo-audit --version ${{ env.CARGO_AUDIT }} --root cargo-tools --target-dir cargo-tools-build
      - name: Clippy
        run: cargo clippy --no-deps -- -D warnings
      - name: Outdated dependencies
        # TODO: add support for githubActions format in cargo-outdated directly?
        shell: python
        run: |
          import json
          import subprocess
          import os

          env = os.environ.copy()
          env["PATH"] = os.getcwd() + "/cargo-tools/bin:" + env["PATH"]
          ps = subprocess.Popen(['cargo', 'outdated', '--format', 'json'], stdout=subprocess.PIPE, env=env)
          output = json.load(ps.stdout)
          outdated = output['dependencies']

          for dep in outdated:
              msg = "{}: project: {}, compat: {}, latest: {}, kind: {}".format(dep['name'], dep['project'], dep['compat'], dep['latest'], dep['kind'])
              print("::warning title=Outdated dependency '{}'::{}".format(dep['name'], msg))
      - name: Audit
        run: |
          PATH="$PATH:$PWD/cargo-tools/bin" cargo audit

  test-linux:
    name: Test on Linux
    needs: fmt
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: test-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Cache tectonic
        id: tectonic-cache
        uses: actions/cache@v3
        with:
          path: |
            ~/tectonic-bin
            ~/.cache/Tectonic
          key: test-tectonic-${{ runner.os }}-${{ env.TECTONIC_VER }}-${{ hashFiles('src/render/templates/pdf.hbs') }}
      - name: Download tectonic binary if not cached
        if: steps.tectonic-cache.outputs.cache-hit != 'true'
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          mkdir -p ~/tectonic-bin
          cd ~/tectonic-bin
          gh release download --repo tectonic-typesetting/tectonic tectonic@${{ env.TECTONIC_VER }} -p tectonic-${{ env.TECTONIC_VER }}-x86_64-unknown-linux-musl.tar.gz
          tar -xzf tectonic-${{ env.TECTONIC_VER }}-x86_64-unknown-linux-musl.tar.gz
          ls -la ~/tectonic-bin
      - name: Test
        run: |
          PATH="$PATH:$HOME/tectonic-bin" tectonic -V
          PATH="$PATH:$HOME/tectonic-bin" cargo test --locked -- --nocapture
      - name: Install apt packages
        id: apt-packages
        uses: awalsh128/cache-apt-pkgs-action@v1
        with:
          packages: nodejs poppler-utils
          version: 1.0
      - name: Cache npm dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.npm
          key: test-npm-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Additional tests
        run: |
          PATH="$PATH:$HOME/tectonic-bin" tectonic -V
          PATH="$PATH:$HOME/tectonic-bin" cargo test --locked -- --ignored --nocapture

  test-windows:
    name: Test on Windows
    needs: fmt
    runs-on: windows-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: test-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Cache tectonic
        id: tectonic-cache
        uses: actions/cache@v3
        with:
          path: ~\AppData\Local\TectonicProject  # as per https://github.com/actions/cache/tree/ac25611caef967612169ab7e95533cf932c32270#windows-environment-variables
          key: test-tectonic-${{ runner.os }}-${{ env.TECTONIC_VER }}-${{ hashFiles('src/render/templates/pdf.hbs') }}
      - name: Download tectonic binary if not cached
        if: steps.tectonic-cache.outputs.cache-hit != 'true'
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          mkdir ~\AppData\Local\TectonicProject\bin
          cd ~\AppData\Local\TectonicProject\bin
          gh release download --repo tectonic-typesetting/tectonic tectonic@${{ env.TECTONIC_VER }} -p tectonic-${{ env.TECTONIC_VER }}-x86_64-pc-windows-msvc.zip
          7z x tectonic-${{ env.TECTONIC_VER }}-x86_64-pc-windows-msvc.zip
          rm tectonic-${{ env.TECTONIC_VER }}-x86_64-pc-windows-msvc.zip
          dir ~\AppData\Local\TectonicProject\bin
      - name: Test
        run: |
          $env:PATH += ";$env:USERPROFILE\AppData\Local\TectonicProject\bin"
          Write-Output $env:PATH
          tectonic -V
          cargo test --locked -- --nocapture

  msrv:
    name: MSRV check
    needs: fmt
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Extract MSRV
        id: get-msrv
        run: echo msrv=$(yq .package.rust-version Cargo.toml -oy) | tee -a "$GITHUB_OUTPUT"
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ steps.get-msrv.outputs.msrv }}
          override: true
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: msrv-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Perform MSRV check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --locked --tests

  book-check:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
      - name: Setup mdBook
        uses: peaceiris/actions-mdbook@v1
        with:
          mdbook-version: 'latest'
      - run: make book

  build-linux:
    name: Linux build
    if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/ci'
    needs:
      - test-linux
      - test-windows
      - msrv
      - book-check
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          target: x86_64-unknown-linux-musl
          override: true
      - name: Install APT packages
        uses: awalsh128/cache-apt-pkgs-action@v1
        with:
          packages: musl-tools # provides musl-gcc
          version: 1.0
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Cache cargo tools
        id: cargo-tools-cache
        uses: actions/cache@v3
        with:
          path: cargo-tools
          key: build-tools-${{ env.CARGO_DEB }}-${{ env.CARGO_RPM }}
      - name: Install cargo tools if not cached
        if: steps.cargo-tools-cache.outputs.cache-hit != 'true'
        run: |
          cargo install cargo-deb --version ${{ env.CARGO_DEB }} --root cargo-tools --target-dir cargo-tools-build
          cargo install cargo-generate-rpm --version ${{ env.CARGO_RPM }} --root cargo-tools --target-dir cargo-tools-build
      - name: Build
        run: cargo build --locked --release --target=x86_64-unknown-linux-musl
      - name: Generate packages
        run: |
          PATH="$PATH:$PWD/cargo-tools/bin" cargo deb --no-build --target=x86_64-unknown-linux-musl -o target/debian/bard.deb
          PATH="$PATH:$PWD/cargo-tools/bin" cargo generate-rpm --target=x86_64-unknown-linux-musl -o target/generate-rpm/bard.rpm
      # call upload-artifact per file to flatten resulting directory structure
      - name: Upload linux binary
        uses: actions/upload-artifact@v3
        with:
          name: bard-linux
          path: target/x86_64-unknown-linux-musl/release/bard
          if-no-files-found: error
      - name: Upload deb package
        uses: actions/upload-artifact@v3
        with:
          name: bard-linux
          path: target/debian/bard.deb
          if-no-files-found: error
      - name: Upload rpm package
        uses: actions/upload-artifact@v3
        with:
          name: bard-linux
          path: target/generate-rpm/bard.rpm
          if-no-files-found: error

  build-windows:
    name: Windows build
    if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/ci'
    needs:
      - test-linux
      - test-windows
      - msrv
      - book-check
    runs-on: windows-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3
      - name: Setup Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Cache dependencies
        uses: actions/cache@v3
        with:
          path: |
            ~/.cargo/.crates.toml
            ~/.cargo/.crates2.json
            ~/.cargo/bin
            ~/.cargo/registry/index
            ~/.cargo/registry/cache
            target
          key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}
      - name: Build
        run: |
          cargo build --locked --release
          Move-Item -Force -Path target\release\bard.exe -Destination target\release\bard-no-tectonic.exe
      - name: Upload Windows exe
        uses: actions/upload-artifact@v3
        with:
          name: bard-windows
          path: target/release/bard-no-tectonic.exe
          if-no-files-found: error

  deploy-docker:
    name: Deploy to DockerHub
    if: startsWith(github.ref, 'refs/tags/')
    needs:
      - build-linux
    runs-on: ubuntu-latest
    steps:
      - name: Checkout sources
        uses: actions/checkout@v3 # need the Dockerfile
      - uses: actions/download-artifact@v3
        with:
          name: bard-linux
          path: bard-linux
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
        with:
          driver: docker
      - name: Docker metadata
        uses: docker/metadata-action@v4
        id: meta
        with:
          images: vojtechkral/bard
          tags: |
            type=ref,event=tag
            type=sha,prefix=git-
      - name: Login to DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@v3
        with:
          context: .
          file: .github/workflows/Dockerfile
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

  daft-release:
    name: Draft a Release
    if: startsWith(github.ref, 'refs/tags/')
    needs:
      - build-linux
      - build-windows
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v3
        # no options -> gets all the artifacts
      - name: Create a Release draft
        uses: softprops/action-gh-release@v1
        with:
          draft: true
          name: "bard ${{ github.ref_name }}"
          files: |
            ./bard-linux/bard
            ./bard-linux/bard.deb
            ./bard-linux/bard.rpm
            ./bard-windows/bard-no-tectonic.exe