oscar-system / oscar-website

Dev repo for the oscar website
https://www.oscar-system.org
8 stars 32 forks source link

Automate news items for package releases #318

Open fingolfin opened 5 months ago

fingolfin commented 5 months ago

@lkastner made the PR #317 using this Perl script, saved as scrape.pl in news/_posts/ and run from inside that directory:

#!/usr/bin/perl

use strict;
use warnings;
use JSON;

# Sample usage:
# perl scrape.pl oscar-system/Singular.jl 0.14.0 0.16.0
# perl scrape.pl oscar-system/Polymake.jl 0.8.1 0.8.3
# perl scrape.pl oscar-system/Singular.jl
# perl scrape.pl oscar-system/Polymake.jl

my $name = $ARGV[0];
my $upper = $ARGV[2];
my $lower = $ARGV[1];
my $all_selected = 0;
if(!defined($lower)){
   $all_selected = 1;
}
if(!defined($upper)){
   $all_selected = 1;
}
print "name is $name $lower -- $upper\n";
my($progname) = $name =~ m/\/(.*)/;
my $filename = "$progname-release.md";
print "Will use filename $filename\n";

my $current = `curl https://api.github.com/repos/$name/releases`;

my $json = JSON->new->allow_nonref;
my $perl_scalar = $json->decode($current);
foreach my $v (@$perl_scalar){
   my($version) = $v->{"name"} =~ m/v(.*)/;
   if(defined($version)){
      if((version_compare($lower,$version)> 0 && version_compare($version, $upper)<=1) || $all_selected){
         print "$version selected\n";
         write_file($filename, $progname, $v);
      } else {
         print $version," not selected\n";
      }
   }
}

sub write_file {
   my($filename, $progname, $v) = @_;
   my($version) = $v->{"name"} =~ m/v(.*)/;
   my $body = $v->{"body"};
   print "$body\n";
   my $date = $v->{"published_at"};
   ($date) = $date =~ m/(\d\d\d\d-\d\d-\d\d)/;
   ($body) = $body =~ m/(\[Diff.*)/ms;
   if(!-e "$date-$filename"){
      open(my $fh, ">$date-$filename");
      print $fh <<"%%%";
---
layout: post
title: $progname $version released
author: TagBot
---

Today [$progname $version](https://github.com/$name/releases/tag/v$version) has
been released.

$body
%%%
      close($fh);
   }
}

sub version_compare {
   my($v1, $v2) = @_;
   if(!defined $v1){ return 1; }
   if(!defined $v2){ return 1; }
   print "v1:$v1 v2:$v2\n";
   my($v1major, $v1minor, $v1patch) = $v1 =~ m/(.*)\.(.*)\.(.*)/;
   my($v2major, $v2minor, $v2patch) = $v2 =~ m/(.*)\.(.*)\.(.*)/;
   if($v1major < $v2major) { return 1; }
   if($v1major > $v2major) { return -1; }
   if($v1minor < $v2minor) { return 1; }
   if($v1minor > $v2minor) { return -1; }
   if($v1patch < $v2patch) { return 1; }
   if($v1patch > $v2patch) { return -1; }
   return 0;
}

It would be nice if we had a GH Action that run this script or something equivalent to query all our packages for updates, and if there are any, open a PR (e.g. using https://github.com/peter-evans/create-pull-request) with the new stuff. Or even just directly apply the updates, whatever.

Of course one could also improve it. E.g. the automatic release notes provided by GitHub reference pull requests and issues by number. It would be nice if those were actual hyperlinks in the news items.