Skip to content

Commit

Permalink
Add GitHub Actions » Automatic issues (annual review) & check metadat…
Browse files Browse the repository at this point in the history
…a in PRs (#823)
  • Loading branch information
svenja11 authored Apr 19, 2024
1 parent 401b4f5 commit f685b55
Show file tree
Hide file tree
Showing 6 changed files with 668 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/scripts-metadata/check-meta-files.sh
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"
Loading

0 comments on commit f685b55

Please sign in to comment.