Skip to content

Commit

Permalink
Add release notes parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 5, 2024
1 parent b745f56 commit 88d5da3
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 3 deletions.
146 changes: 146 additions & 0 deletions .ci/mknotes
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env perl

package mknotes;

use strict;
use warnings;
use v5.30;
use Getopt::Long qw(GetOptions);
use utf8;

my $item_regex = qr/^[*-+]\s+/;
my $indent_regex = qr/^\s+/;

sub new {
my $self = {
version => '',
file => '',
repo => '',
output => '',
};

GetOptions(
"f=s" => \$self->{file},
"v=s" => \$self->{version},
"r=s" => \$self->{repo},
"o=s" => \$self->{output},
) or die("Error in command line arguments\n");

if (!$self->{file} || !$self->{version} || !$self->{repo}) {
die "Usage: mknotes -v [VERSION] -f [CHANGELOG] -r [REPO]\n";
}

# Trim a slash from the URI.
$self->{repo} =~ s{/$}{};

bless $self => __PACKAGE__;
}

sub run {
my $self = shift;

open my $fh, '<:encoding(UTF-8)', $self->{file}
or die "Cannot open $self->{file}: $!\n";

# Print to STDOUT by default.
my $out;
if ($self->{output}) {
open $out, '>:encoding(UTF-8)', $self->{output}
or die "Cannot open $self->{output}: $!\n";
} else {
$out = \*STDOUT;
binmode $out, ':encoding(UTF-8)';
}

my $header = "## [v$self->{version}]";
my ($found, $in_item) = (0, 0);

while (my $line = <$fh>) {
if ($line =~ /^\Q$header/) {
# Found the header for this version. Build a regex for its link
# reference.
$found = 1;
my $link_regex = qr/^\s*\Q[v$self->{version}]\E:\s+https:/;

# Continue scanning until we reach the next `## ` header.
while (my $line = <$fh>) {
chomp $line;
return $self->finish_list($out, $line) if $line =~ /^## /;

# Skip the line if it's the link reference for the header.
$in_item = $self->print_line($out, $line, $in_item)
unless $line =~ $link_regex;
}
}
}

# All done!
die "Version $self->{version} not found in $self->{file}\n" unless $found;
}

# Called when the next version header is found in line.
sub finish_list {
my ($self, $out, $line) = @_;
# Next header. Extract its version.

my ($prev) = $line =~ /\[([^]]+)\]/;
die "No version found in $line\n" unless $prev;

# Emit a footer line with a link to the diff for this version.
print {$out} sprintf(
"---\n\n🆚 For more detail compare [changes since %s](%s/compare/%s...%s).\n",
$prev, $self->{repo}, $prev, $self->{version},
);

# All done.
return 1;
}

# Called for a line to print, keeping track of list item status.
sub print_line {
my ($self, $out, $line, $in_item) = @_;
# Convert wrapped list items to single lines.
if ($line =~ $item_regex) {
if ($in_item) {
# Previous item done
print {$out} "\n";
} else {
# We're in an item now.
$in_item = 1
}
# Print the line with no newline.
print {$out} $line;

return $in_item;
}

if ($in_item) {
# In an item, but not starting a new item.
if ($line =~ $indent_regex) {
# Continued item, convert indent to single space.
$line =~ s/$indent_regex/ /g;
# Print without newline.
print {$out} $line;
} else {
# No longer in an item.
$in_item = 0;
# Previous item done; print complete line.
print {$out} "\n", $line, "\n";
}

return $in_item;
}

# Not in an item.
$in_item = 0;
# Print complete line
print {$out} $line, "\n";

return $in_item;
}

package main;

mknotes->new->run;

__END__
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ jobs:
run: make META.json && pgxn-bundle
- name: Release on PGXN
run: ls -lah # pgxn-release
# - name: Generate Release Changes
# run: make latest-changes.md
- name: Generate Release Changes
run: make target/release-notes.md
- run: cat target/release-notes.md
# - name: Create GitHub Release
# id: release
# uses: actions/create-release@v1
# with:
# tag_name: ${{ github.ref }}
# release_name: Release ${{ github.ref }}
# body_path: latest-changes.md
# body_path: target/release-notes.md
# - name: Upload Release Asset
# uses: actions/upload-release-asset@v1
# with:
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Changelog

All notable changes to this project will be documented in this file. It uses the
[Keep a Changelog] format, and this project adheres to [Semantic Versioning].

[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
"Semantic Versioning 2.0.0"

## [v0.1.0] --- Unreleased

The theme of this release is *learning Rust and pgrx.*

### ⚡ Improvements

* First release, everything is new!
* JSON Schema validation using [boon]
* Fully supports draft 2020-12, draft 2019-09, draft-7, draft-6, and draft-4
* Multi-object schema specification

### 🏗️ Build Setup

* Built with Rust
* Use `make` for most actions

### 📚 Documentation

* Build and install docs in the [README]
* Full [reference documentation]

[v0.1.0]: https://github.com/tembo-io/pg-jsonschema/compare/34d5d49...HEAD
[boon]: https://github.com/santhosh-tekuri/boon
[README]: https://github.com/tembo-io/pg-jsonschema/blob/v0.1.0/README.md
[reference documentation]: https://github.com/tembo-io/pg-jsonschema/blob/v0.1.0/doc/jsonschema.md
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ $(DISTNAME)-$(DISTVERSION).zip: META.json

## pgxn-zip: Create a PGXN-compatible zip file.
pgxn-zip: $(DISTNAME)-$(DISTVERSION).zip

target/release-notes.md: CHANGELOG.md .ci/mknotes
@./.ci/mknotes -v $(DISTVERSION) -f $< -r https://github.com/$(or $(GITHUB_REPOSITORY),tembo-io/pg-jsonschema) -o $@
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ JSON Schema Postgres Extension
[![Build Status](https://github.com/tembo-io/pg-jsonschema/actions/workflows/lint-and-test.yml/badge.svg)](https://github.com/tembo-io/pg-jsonschema/actions/workflows/lint-and-test.yml "🧪 Lint and Test")
[![Code Coverage](https://codecov.io/gh/tembo-io/pg-jsonschema/graph/badge.svg?token=DIFED324ZY)](https://codecov.io/gh/tembo-io/pg-jsonschema "📊 Code Coverage")

[Change Log](CHANGELOG.md) | [Documentation](doc/jsonschema.md)

This library provides the `jsonschema` extension for validating JSON and JSONB
against a [JSON Schema] in Postgres. It supports the following [specification
drafts] as validated by the [JSON-Schema-Test-Suite] excluding optional
Expand Down

0 comments on commit 88d5da3

Please sign in to comment.