aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/format-validation.yml
blob: 2104f9da110d086743dff75c46428dbcf940b14d (plain)
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
name: Format validation

on:
  push:
    branches:
      - '*'
      - '!rc/*'
    paths:
      - 'test/writer.jats_articleauthoring'
      - 'test/writer.jats_publishing'
      - 'test/writer.jats_archiving'
      - 'test/tables.jats_archiving'
  pull_request:
    branches:
      - '*'
      - '!rc/*'
    paths:
      - 'test/writer.jats_articleauthoring'
      - 'test/writer.jats_publishing'
      - 'test/writer.jats_archiving'
      - 'test/tables.jats_archiving'

jobs:
  jats:
    name: JATS
    runs-on: ubuntu-latest
    env:
      VALIDATOR_URL: "https://jats-validator.hubmed.org/dtd/"
    strategy:
      fail-fast: false
      matrix:
        tagset:
          - articleauthoring
          - publishing
          - archiving
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Validate writer output
        run: |
          filename=test/writer.jats_${{ matrix.tagset }}
          printf "Validating file %s\n" "$filename"
          json="$(curl --form "xml=@${filename}" --silent "$VALIDATOR_URL")"
          err_count="$(printf '%s' "$json" | jq '.errors | length')"
          if [ "$err_count" -eq 0 ]; then
              printf "File was validated successfully.\n"
              exit 0
          else
              printf "Validator report:\n%s" "$json"
              exit 1
          fi

      - name: Validate tables
        # Archiving has the simplest template, so we only check with that.
        if: matrix.tagset == 'archiving'
        run: |
          tmpl="$(cat <<EOF
          <?xml version="1.0" encoding="utf-8" ?>
          <!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.2 20190208//EN"
                  "JATS-archivearticle1.dtd">
          <article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="1.2" article-type="other">
          <front><article-meta></article-meta></front>
          <body>%s</body></article>
          EOF
          )"
          jats_file="$(mktemp jats-tables.XXXXX)"
          printf "$tmpl" "$(cat test/tables.jats_archiving)" > "$jats_file"
          json="$(curl --form "xml=@${jats_file}" --silent "$VALIDATOR_URL")"
          err_count="$(printf "%s" "$json" | jq '.errors | length')"
          if [ "$err_count" -eq 0 ]; then
              printf "Table output is valid when used as body content.\n"
              exit 0
          else
              printf "Validator report:\n%s" "$json"
              exit 1
          fi