aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/test-validators.yml
blob: f734b5ac3bc34dbb76dbb544d6aa7878c7fb73b6 (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
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
name: Validate Validators

on:
  push:
    branches: [main]
    paths:
      - "validators/**"
      - "gitinfo.schema.json"
      - "examples/**"
      - ".github/workflows/test-validators.yml"
  pull_request:
    branches: [main]
    paths:
      - "validators/**"
      - "gitinfo.schema.json"
      - "examples/**"
      - ".github/workflows/test-validators.yml"
  workflow_dispatch:

jobs:
  test-nodejs:
    name: Test Node.js Validator
    runs-on: ubuntu-latest
    container:
      image: node:20-alpine
    steps:
      - uses: actions/checkout@v4

      - name: Validate minimal example
        run: node validators/nodejs/validate.js examples/minimal.gitinfo

      - name: Validate open-source-project example
        run: node validators/nodejs/validate.js examples/open-source-project.gitinfo

      - name: Validate mirror-only example (JSONC with comments)
        run: node validators/nodejs/validate.js examples/mirror-only.gitinfo

      - name: Test invalid file detection
        run: |
          echo '{"invalid_field": "should fail"}' > /tmp/invalid.gitinfo
          if node validators/nodejs/validate.js /tmp/invalid.gitinfo; then
            echo "Expected validation to fail but it passed"
            exit 1
          else
            echo "Correctly detected invalid file"
          fi

  test-powershell:
    name: Test PowerShell Validator
    runs-on: ubuntu-latest
    container:
      image: mcr.microsoft.com/powershell:latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate minimal example
        shell: pwsh
        run: ./validators/powershell/Validate-GitInfo.ps1 -Path examples/minimal.gitinfo

      - name: Validate open-source-project example
        shell: pwsh
        run: ./validators/powershell/Validate-GitInfo.ps1 -Path examples/open-source-project.gitinfo

      - name: Validate mirror-only example (JSONC with comments)
        shell: pwsh
        run: ./validators/powershell/Validate-GitInfo.ps1 -Path examples/mirror-only.gitinfo

      - name: Test invalid file detection
        shell: pwsh
        run: |
          '{"invalid_field": "should fail"}' | Set-Content /tmp/invalid.gitinfo
          ./validators/powershell/Validate-GitInfo.ps1 -Path /tmp/invalid.gitinfo
          if ($LASTEXITCODE -eq 0) {
            Write-Host "Expected validation to fail but it passed"
            exit 1
          }
          Write-Host "Correctly detected invalid file"
          exit 0

  test-bash:
    name: Test Bash Validator
    runs-on: ubuntu-latest
    container:
      image: alpine:latest
    steps:
      - uses: actions/checkout@v4

      - name: Install dependencies
        run: apk add --no-cache bash jq coreutils sed

      - name: Make script executable
        run: chmod +x validators/bash/validate.sh

      - name: Validate minimal example
        shell: bash
        run: ./validators/bash/validate.sh examples/minimal.gitinfo

      - name: Validate open-source-project example
        shell: bash
        run: ./validators/bash/validate.sh examples/open-source-project.gitinfo

      - name: Validate mirror-only example (JSONC with comments)
        shell: bash
        run: ./validators/bash/validate.sh examples/mirror-only.gitinfo

      - name: Test invalid file detection
        shell: bash
        run: |
          echo '{"invalid_field": "should fail"}' > /tmp/invalid.gitinfo
          if ./validators/bash/validate.sh /tmp/invalid.gitinfo; then
            echo "Expected validation to fail but it passed"
            exit 1
          else
            echo "Correctly detected invalid file"
          fi