-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yml
171 lines (151 loc) · 5.86 KB
/
action.yml
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
name: cff-validator
author: Diego Hernangómez
description: "Validate your repository's CITATION.cff file using R software"
branding:
icon: 'book-open'
color: 'gray-dark'
inputs:
citation-path:
description: 'Path to .cff file to be validated. By default it selects a CITATION.cff file on the root of the repository.'
required: false
default: 'CITATION.cff'
cache-version:
description: 'The version of the cache, change this from the default (1) to start over with a fresh cache.'
required: false
default: 1
install-r:
description: 'If "true" download and install R during the setup. If "false"
use the existing installation in the GitHub Action image,'
required: false
default: false
# pak cache management derived from https://github.com/r-lib/actions/blob/v2-branch/setup-r-dependencies/action.yaml
# By Jim Hester
runs:
using: composite
steps:
- name: Install R
uses: r-lib/actions/setup-r@v2
if: runner.os != 'macOS'
with:
install-r: ${{ inputs.install-r }}
use-public-rspm: true
# Need to install R on macOS
- name: Install R on macOS
uses: r-lib/actions/setup-r@v2
if: runner.os == 'macOS'
with:
install-r: true
use-public-rspm: true
- name: Install libcurl on Linux
if: runner.os == 'Linux'
run: |
# Install libcurl4-openssl-dev
echo "::group::Install libcurl4-openssl-dev"
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
echo "::endgroup::"
shell: bash
- name: Query dependencies
id: install
run: |
# Dependency resolution
cat("os-version=", sessionInfo()$running, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
cat("r-version=", if (grepl("development", rv <- R.Version()$version.string)) as.character(getRversion()) else rv, "\n", file = Sys.getenv("GITHUB_OUTPUT"), sep = "", append = TRUE)
shell: Rscript {0}
- name: Restore R package cache
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ steps.install.outputs.os-version }}-${{ steps.install.outputs.r-version }}-${{inputs.cache-version }}-cff
restore-keys: ${{ steps.install.outputs.os-version }}-${{ steps.install.outputs.r-version }}-${{ inputs.cache-version }}-cff
- name: Install pak
run: |
# Install pak
cat("::group::Install pak\n")
install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))
cat("::endgroup::\n")
shell: Rscript {0}
- name: Install dependencies
run: |
# Install dependencies
cat("::group::Install/update packages\n")
# Install/Update packages
Sys.setenv("PKGCACHE_HTTP_VERSION" = "2")
pak::pkg_install(c("yaml", "jsonlite", "knitr", "jsonvalidate", "cffr", "sessioninfo"),
upgrade = TRUE, dependencies = NA)
cat("::endgroup::\n")
shell: Rscript {0}
- name: Session info
run: |
# Session info
cat("::group::Session info\n")
if (requireNamespace("sessioninfo", quietly = TRUE)) {
if (packageVersion("sessioninfo") >= "1.2.1") {
sessioninfo::session_info(pkgs = "installed", include_base = TRUE)
} else {
options(width = 200)
sessioninfo::session_info(rownames(installed.packages()), include_base=TRUE)
}
} else {
sessionInfo()
}
cat("::endgroup::\n")
shell: Rscript {0}
- name: Validate cff
run: |
# Validate cff
cat("Validating cff\n")
citfile <- yaml::read_yaml("${{ inputs.citation-path }}")
# All elements to character
citfile <- rapply(citfile, function(x) as.character(x), how = "replace")
# Convert to json
cit_temp <- jsonlite::toJSON(citfile, pretty = TRUE, auto_unbox = TRUE)
# Use local copy of schema, included with cffr
schema_local <- system.file("schema/schema.json", package = "cffr")
# Validate
result <- jsonvalidate::json_validate(cit_temp,
schema_local,
verbose = TRUE
)
# Results
if (result == FALSE) {
writeLines(paste0("\n:x: ${{ inputs.citation-path }} has errors"),
con = "citation_cff_errors.md"
)
# Format outputs
get_errors <- attr(result, "errors")
get_errors$field <- gsub(
"^data", "cff",
get_errors$field
)
write(knitr::kable(get_errors, align = "l"),
file = "citation_cff_errors.md",
append = TRUE
)
write("\n\nSee [Guide to Citation File Format schema version 1.2.0](https://github.com/citation-file-format/citation-file-format/blob/main/schema-guide.md) for debugging.",
file = "citation_cff_errors.md",
append = TRUE
)
stop("${{ inputs.citation-path }} file not valid. See Job Summary.")
} else {
writeLines(paste0(
":white_check_mark: Congratulations! ${{ inputs.citation-path }} is valid"
),
con = "citation_cff_ok.md"
)
}
shell: Rscript {0}
# Report on success
- name: Report success
shell: bash
if: success()
run: |
# OK :)
cat citation_cff_ok.md >$GITHUB_STEP_SUMMARY
# Upload artifact
- name: Upload error report
if: failure()
shell: bash
run: |
# Not OK :( See summary
cat citation_cff_errors.md >$GITHUB_STEP_SUMMARY