-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (62 loc) · 1.91 KB
/
validate-metadata.yaml
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
name: Validate metadata
on:
push:
paths:
- '**metadata.ya?ml'
pull_request:
workflow_dispatch:
jobs:
yamale-validate:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install Yamale
run: "pip install yamale"
- name: Install ruamel
run: |
pip install ruamel.yaml \
pip install ruamel.yaml.cmd
- name: Run Yamale on ./raw
run: |
yamale -s ./schemas/raw_schema.yaml \
-p ruamel ./raw
cff-validate:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- name: Set up R packages
uses: r-lib/actions/setup-r-dependencies@v2
with:
packages:
any::yaml
any::cffr
- name: Validate citation
shell: Rscript {0}
run: |
dir.create(file.path(tempdir(), 'cff'))
files <- list.files(pattern = '^metadata\\.yaml$', recursive = TRUE, full.names = TRUE)
for(i in seq_along(files)){
parsed_yaml <- yaml::read_yaml(files[i], readLines.warn = FALSE)
parsed_yaml$citation.cff |>
yaml::write_yaml(
file.path(
tempdir(),
'cff',
paste0(
gsub('[\\. ]', '_', parsed_yaml$name),
'.cff')
)
)
}
cff_files <- list.files(file.path(tempdir(), 'cff'), full.names = T)
validation_result <- vector("logical", length(cff_files))
for(i in seq_along(cff_files)) {
validation_result[i] <- cffr::cff_validate(cff_files[i])
}
if(!all(validation_result)) stop('Invalid cff detected.')