-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Actions » Automatic issues (annual review) & check metadat…
…a in PRs (#823)
- Loading branch information
Showing
6 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
markdown_file="$1" | ||
json_schema=".github/scripts-metadata/schema.json" | ||
output_file=".github/scripts-metadata/meta-converted.json" | ||
validate_file=".github/scripts-metadata/validation_result.txt" | ||
variables=".github/scripts-metadata/variables.txt" | ||
new_variables=".github/scripts-metadata/new-variables.txt" | ||
updated_variables=".github/scripts-metadata/updated-variables.txt" | ||
|
||
echo $markdown_file | ||
|
||
# Extract YAML front matter from Markdown file and turn it into a JSON file | ||
metadata=$(awk '/^---$/{f=!f;next}f' "$markdown_file" | yq eval -o=json - > "$output_file") | ||
|
||
# Validate metadata against the JSON schema | ||
npx ajv-cli validate -s "$json_schema" -d "$output_file" --all-errors --errors=line > "$validate_file" 2>&1 | ||
|
||
# Extract error messages from "validate_file" | ||
cat "$validate_file" | tail -n +2 | jq -r '.[] | "\(.instancePath | ltrimstr("/"))=\(.message)"' > "$new_variables" | ||
|
||
# Check if any keys are missing | ||
for key in SPDX-License-Identifier path slug date title short_description tags author author_link author_img author_description language available_languages header_img cta; do | ||
if ! jq -e ".[\"$key\"]" $output_file > /dev/null; then | ||
echo "$key=Not found" >> $new_variables | ||
fi | ||
done | ||
|
||
# Replace the original variable messages with error messages | ||
awk -F'=' 'NR==FNR{a[$1]=$2; next} {if($1 in a) {$2=a[$1]} print}' OFS='=' "$new_variables" "$variables" > "$updated_variables" | ||
|
||
# Update formatting to make it work for `source` and `envsubst` in `.guthub/workflows/check-metadata-in-files.yml` | ||
sed -i -e 's/SPDX-License-Identifier/license/g' -e "s/^\(.*\)=\(.*\)$/\\1='\2'/g" -e 's/^/export /' "$updated_variables" | ||
echo "$updated_variables" |
Oops, something went wrong.