From e9148b4c6b75b8f7d4e9dac9bd9482d4c4d3aab0 Mon Sep 17 00:00:00 2001 From: Dennis Bell Date: Fri, 11 Mar 2022 20:02:54 -0800 Subject: [PATCH] [ci] Refactor release notes release detection Now (hopefully) better automatic detection of types/urls --- ci/scripts/release-notes | 61 ++++++++++++++++++++++++---------------- ci/upstream.yml | 35 ----------------------- 2 files changed, 36 insertions(+), 60 deletions(-) diff --git a/ci/scripts/release-notes b/ci/scripts/release-notes index 77f90865..287bad6b 100755 --- a/ci/scripts/release-notes +++ b/ci/scripts/release-notes @@ -144,12 +144,26 @@ sub get_releases { my @months = qw(ignored January February March April May June July August September October November December); sub github { - my ($org, $repo, $tag, $type, $orig_url) = @_; - my ($url, $day, $mon, $year); + my ($org, $repo, $versions, $type, $orig_url) = @_; + my ($url, $day, $mon, $year, $out, $tag); + + unless ($org && $repo) { + if ($orig_url =~ m|https://bosh.io/d/github.com/([^/]*)/([^/]*)\?v=(.*)$|) { + $org = $1; + $repo = $2; + } elsif ($orig_url =~ m|https://github.com/([^/]*)/([^/]*)/releases|) { + $org = $1; + $repo = $2; + } + return ("-","-") unless ($org && $repo); + } - # Try release + # Try release - the preferred method my $lookup_url="https://api.github.com/repos/$org/$repo/releases"; - my $out = qx(curl -Ls -u "$ENV{GITHUB_ACCESS_TOKEN}:" "$lookup_url" | jq -r --arg t "$tag" '.[] | select(.tag_name == \$t)'); + for $tag (@$versions) { + $out = qx(curl -Ls -u "$ENV{GITHUB_ACCESS_TOKEN}:" "$lookup_url" | jq -r --arg t "$tag" '.[] | select(.tag_name == \$t)'); + last if $out; + } if ($out) { printf STDERR " - $org/$repo release $tag\n"; my $data = decode_json($out); @@ -159,20 +173,26 @@ sub github { } else { # Next try tag my $lookup_url="https://api.github.com/repos/$org/$repo/tags"; - my $out = qx(curl -Ls -u "$ENV{GITHUB_ACCESS_TOKEN}:" "$lookup_url"); + $out = qx(curl -Ls -u "$ENV{GITHUB_ACCESS_TOKEN}:" "$lookup_url"); + my $target_tag; if ($out) { - printf STDERR " - $org/$repo tag $tag\n"; my $tags = decode_json($out); - my $target_tag = (grep {$_->{name} eq $tag} @$tags)[0]; - return ("Tag $tag not found",''); # TBD... + for $tag (@$versions) { + $target_tag = (grep {$_->{name} eq $tag} @$tags)[0]; + last if $target_tag; + } + } + if ($target_tag) { + printf STDERR " - $org/$repo tag $tag\n"; my $commit_url = $target_tag->{commit}{url}; $out = qx(curl -Ls -u "$ENV{GITHUB_ACCESS_TOKEN}:" "$commit_url"); my $data = decode_json($out); (my $url = $data->{html_url}) =~ s#/commit/#/tree/#; ($year, $mon, $day) = ($data->{commit}{author}{date} =~ m/^(\d{4})-(\d{2})-(\d{2})/); + } else { printf STDERR " - $org/$repo version $tag not found!"; - return ("Tag $tag not found",'') unless $out; + return ('-','-'); } } return ("$day $months[$mon] $year", $url); @@ -224,22 +244,13 @@ sub calculate_software_updates { $found{$section} ||= {}; unless (defined($found{$section}{"$name/$version"})) { - my ($date,$release_url); - if ($upstream->{$section}{$name}{org} && $upstream->{$section}{$name}{repo}) { - for my $prefix (@prefixes) { - ($date,$release_url) = github( - $upstream->{$section}{$name}{org}, - $upstream->{$section}{$name}{repo}, - $prefix.$version, - $upstream->{$section}{$name}{type}, - $upstream->{$section}{$name}{url} - ); - last if $release_url; - } - } else { - $date = ""; - $release_url = ""; - } + my ($date,$release_url) = github( + $upstream->{$section}{$name}{org}, + $upstream->{$section}{$name}{repo}, + [map {$_.$version} @prefixes], + $upstream->{$section}{$name}{type}, + $url + ); $found{$section}{"$name/$version"} = { name => $name, version => $version, diff --git a/ci/upstream.yml b/ci/upstream.yml index 9da5d23f..523b94d7 100644 --- a/ci/upstream.yml +++ b/ci/upstream.yml @@ -8,142 +8,107 @@ core: bpm: org: cloudfoundry repo: bpm-release - type: release capi: org: cloudfoundry repo: capi-release - type: release cf-networking: org: cloudfoundry repo: cf-networking-release - type: release cf-smoke-tests: org: cloudfoundry repo: cf-smoke-tests-release - type: release cflinuxfs3: org: cloudfoundry repo: cflinuxfs3-release - type: release cf-cli: org: bosh-packages repo: cf-cli-release - type: release diego: org: cloudfoundry repo: diego-release - type: release garden-runc: org: cloudfoundry repo: garden-runc-release - type: release loggregator: org: cloudfoundry repo: loggregator-release - type: release loggregator-agent: org: cloudfoundry repo: loggregator-agent-release - type: release log-cache: org: cloudfoundry repo: log-cache-release - type: release nats: org: cloudfoundry repo: nats-release - type: release routing: org: cloudfoundry repo: routing-release - type: release statsd-injector: org: cloudfoundry repo: statsd-injector-release - type: release cf-syslog-drain: org: cloudfoundry repo: cf-syslog-drain-release - type: release uaa: org: cloudfoundry repo: uaa-release - type: release silk: org: cloudfoundry repo: silk-release - type: release bosh-dns-aliases: org: cloudfoundry repo: bosh-dns-aliases-release - type: release cflinuxfs2: org: cloudfoundry repo: cflinuxfs2-release - type: release app-autoscaler: org: cloudfoundry-incubator repo: app-autoscaler-release - type: release nfs-volume: org: cloudfoundry repo: nfs-volume-release - type: release mapfs: org: cloudfoundry repo: mapfs-release - type: release postgres: org: cloudfoundry-community repo: postgres-boshrelease - type: release haproxy: org: cloudfoundry-incubator repo: haproxy-boshrelease - type: release buildpacks: binary-buildpack: org: cloudfoundry repo: binary-buildpack-release - type: release dotnet-core-buildpack: org: cloudfoundry repo: dotnet-core-buildpack-release - type: release go-buildpack: org: cloudfoundry repo: go-buildpack-release - type: release java-buildpack: org: cloudfoundry repo: java-buildpack-release - type: release nginx-buildpack: org: cloudfoundry repo: nginx-buildpack-release - type: release nodejs-buildpack: org: cloudfoundry repo: nodejs-buildpack-release - type: release php-buildpack: org: cloudfoundry repo: php-buildpack-release - type: release python-buildpack: org: cloudfoundry repo: python-buildpack-release - type: release r-buildpack: org: cloudfoundry repo: r-buildpack-release - type: release ruby-buildpack: org: cloudfoundry repo: ruby-buildpack-release - type: release staticfile-buildpack: org: cloudfoundry repo: staticfile-buildpack-release - type: release