Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract metadata JSON. #688

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dependencies: see zip-guide.rst and protocol/README.rst

.PHONY: all all-zips release protocol discard
all-zips: .Makefile.uptodate
all-zips: .Makefile.uptodate zip-metadata.json
find . -name 'zip-*.rst' -o -name 'zip-*.md' |sort >.zipfilelist.new
diff .zipfilelist.current .zipfilelist.new || cp -f .zipfilelist.new .zipfilelist.current
rm -f .zipfilelist.new
Expand All @@ -10,6 +10,9 @@ all-zips: .Makefile.uptodate

all: all-zips protocol

zip-metadata.json: zip-*.rst
./extract-metadata.sh > $@

release:
$(MAKE) -C protocol release

Expand Down
55 changes: 55 additions & 0 deletions extract-metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash
#
# Parse all `zip-*.rst` file for header metadata.
#
# # Output Format:
#
# This outputs a single JSON object. Each key is the basename of a
# `zip-*.rst` file, and value is a JSON object containing the ZIP metadata
# fields.
#
# The ZIP metadata values are strings for single-line values, or JSON
# arrays of strings for each line in a multi-line value.
#
# # Input Format:
#
# This is a sensitive line-noise unix pipeline that REQUIRES zip rst
# files to follow this format:
#
# - The metadata must occur before the first alphabetic character on column 1.
# - The metadata keys must occur in column 3, after two spaces.
# - Metadata keys must be immediately followed by ": ".
# - Multi-line metadata values must be in continuation lines with the
# first non-space character occurring after column 3.
#
# Integration testing:
#
# Run `./extract-metadata.sh | jq > /dev/null` and verify there's no
# stderr and it has a 0 exit status. This indicates the script completed
# successfully and the result is valid JSON.

set -euo pipefail

ZIPSDIR="$(dirname "$(readlink -f "$0")")"

# Whether or not to emit a comma to separate the previous zip entry:
OPTCOMMA='' #

echo '{'
for ziprst in $(find "$ZIPSDIR" -type f -name 'zip-*.rst')
do
echo "${OPTCOMMA}"
OPTCOMMA=','

echo " \"$(basename "$ziprst")\": {"
< "$ziprst" \
sed -n '/^ /p; /^[A-Za-z]/q' | \
tr '\n' '|' | \
sed 's/^ //; s/| /|/g; s/| */", "/g' | \
tr '|' '\n' | \
sed 's/^\([^:]*\): *\(.*\)$/"\1": ["\2"],/g; s/^/ /; $s/,$//' | \
sed '/\[".*", ".*\]/s/\["/[\n "/g' | \
sed 's/", "/",\n "/g; s/^ \(".*"\)\(\],*\)/ \1\n \2/; s/: \[\("[^"]*"\)\]/: \1/'
echo -n " }"
done
echo '}'
22 changes: 11 additions & 11 deletions zip-1006.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
::

ZIP: 1006
Title: Development Fund of 10% to a 2-of-3 Multisig with Community-Involved Third Entity
Owners: James Todaro <[email protected]>
Joseph Todaro <[email protected]>
Credits: Mario Laul
Chris Burniske
Status: Obsolete
Category: Consensus Process
Created: 2019-08-31
License: MIT
Discussions-To: <https://forum.zcashcommunity.com/t/blocktown-development-fund-proposal-10-to-a-2-of-3-multisig-with-community-involved-third-entity/34782>
ZIP: 1006
Title: Development Fund of 10% to a 2-of-3 Multisig with Community-Involved Third Entity
Owners: James Todaro <[email protected]>
Joseph Todaro <[email protected]>
Credits: Mario Laul
Chris Burniske
Status: Obsolete
Category: Consensus Process
Created: 2019-08-31
License: MIT
Discussions-To: <https://forum.zcashcommunity.com/t/blocktown-development-fund-proposal-10-to-a-2-of-3-multisig-with-community-involved-third-entity/34782>


Terminology
Expand Down
Loading