From 168dc6e5cd29dd6f0eed212c838665485f4560c9 Mon Sep 17 00:00:00 2001
From: Chevdor <chevdor@users.noreply.github.com>
Date: Tue, 22 Mar 2022 09:55:21 +0100
Subject: [PATCH] Fix changelog (#5155)

* Pass git ref explicitely

* Include a db migration section to the changelog
---
 .../workflows/publish-draft-release.yml       |  3 +--
 polkadot/scripts/changelog/README.md          | 16 +++++-------
 polkadot/scripts/changelog/bin/changelog      | 11 +++++---
 .../templates/global_priority.md.tera         |  2 +-
 .../changelog/templates/migrations-db.md.tera | 26 +++++++++++++++++++
 .../templates/migrations-runtime.md.tera      | 25 ++++++++++++++++++
 .../changelog/templates/migrations.md.tera    | 14 ----------
 .../changelog/templates/template.md.tera      |  4 ++-
 8 files changed, 71 insertions(+), 30 deletions(-)
 create mode 100644 polkadot/scripts/changelog/templates/migrations-db.md.tera
 create mode 100644 polkadot/scripts/changelog/templates/migrations-runtime.md.tera
 delete mode 100644 polkadot/scripts/changelog/templates/migrations.md.tera

diff --git a/polkadot/.github/workflows/publish-draft-release.yml b/polkadot/.github/workflows/publish-draft-release.yml
index a4a6f533bf4..4c71c3779c7 100644
--- a/polkadot/.github/workflows/publish-draft-release.yml
+++ b/polkadot/.github/workflows/publish-draft-release.yml
@@ -108,7 +108,6 @@ jobs:
           KUSAMA_DIGEST: ${{ github.workspace}}/kusama-srtool-json/kusama_srtool_output.json
           POLKADOT_DIGEST: ${{ github.workspace}}/polkadot-srtool-json/polkadot_srtool_output.json
           PRE_RELEASE: ${{ github.event.inputs.pre_release }}
-          HIDE_SRTOOL_ROCOCO: false
         run: |
           find ${{env.GITHUB_WORKSPACE}} -type f -name "*_srtool_output.json"
           ls -al $ROCOCO_DIGEST
@@ -118,7 +117,7 @@ jobs:
 
           cd polkadot/scripts/changelog
 
-          ./bin/changelog
+          ./bin/changelog ${GITHUB_REF}
           ls -al release-notes.md
           ls -al context.json
 
diff --git a/polkadot/scripts/changelog/README.md b/polkadot/scripts/changelog/README.md
index 7226530c42a..cbcc1ea2711 100644
--- a/polkadot/scripts/changelog/README.md
+++ b/polkadot/scripts/changelog/README.md
@@ -5,18 +5,18 @@ Currently, the changelog is built locally. It will be moved to CI once labels st
 For now, a bit of preparation is required before you can run the script:
 - fetch the srtool digests
 - store them under the `digests` folder as `<chain>-srtool-digest.json`
-- ensure the `.env` file is up to date with correct information
+- ensure the `.env` file is up to date with correct information. See below for an example
 
 The content of the release notes is generated from the template files under the `scripts/changelog/templates` folder. For readability and maintenance, the template is split into several small snippets.
 
 Run:
 ```
-./bin/changelog <ref_since> [<ref_until>=HEAD]
+./bin/changelog <ref_until> [<ref_since>]
 ```
 
 For instance:
 ```
-./bin/changelog statemine-v5.0.0
+./bin/changelog v0.9.18
 ```
 
 A file called `release-notes.md` will be generated and can be used for the release.
@@ -29,10 +29,7 @@ You may use the following ENV for testing:
 RUSTC_STABLE="rustc 1.56.1 (59eed8a2a 2021-11-01)"
 RUSTC_NIGHTLY="rustc 1.57.0-nightly (51e514c0f 2021-09-12)"
 PRE_RELEASE=true
-HIDE_SRTOOL_ROCOCO=true
 HIDE_SRTOOL_SHELL=true
-REF1=statemine-v5.0.0
-REF2=HEAD
 DEBUG=1
 NO_CACHE=1
 ```
@@ -45,6 +42,7 @@ Currently, the considered labels are:
 - Priority: C<N> labels
 - Audit: D<N> labels
 - E4 => new host function
+- E2 => database migration
 - B0 => silent, not showing up
 - B1-releasenotes (misc unless other labels)
 - B5-client (client changes)
@@ -61,11 +59,11 @@ decide which label will be considered.
 
 The following command allows **Hot Reload**:
 ```
-fswatch templates -e ".*\.md$" | xargs -n1 -I{} ./bin/changelog statemine-v5.0.0
+fswatch templates -e ".*\.md$" | xargs -n1 -I{} ./bin/changelog v0.9.18
 ```
 ### Caching
 
 By default, if the changelog data from Github is already present, the calls to the Github API will be skipped
 and the local version of the data will be used. This is much faster.
-If you know that some labels have changed in Github, you probably want to refresh the data.
-You can then either delete manually the `cumulus.json` file or `export NO_CACHE=1` to force refreshing the data.
+If you know that some labels have changed in Github, you will want to refresh the data.
+You can then either delete manually the `<chain>.json` file or `export NO_CACHE=1` to force refreshing the data.
diff --git a/polkadot/scripts/changelog/bin/changelog b/polkadot/scripts/changelog/bin/changelog
index f25f57daf46..6627502b25b 100755
--- a/polkadot/scripts/changelog/bin/changelog
+++ b/polkadot/scripts/changelog/bin/changelog
@@ -3,7 +3,11 @@
 # frozen_string_literal: true
 
 # call for instance as:
-# ./bin/changelog v0.9.13
+# ./bin/changelog <to> [<from>] [<output_file>]
+# for instance, for the release notes of v1.2.3:
+# ./bin/changelog v1.2.3
+# or
+# ./bin/changelog v1.2.3 v1.2.2
 #
 # You may set the ENV NO_CACHE to force fetching from Github
 # You should also ensure you set the ENV: GITHUB_TOKEN
@@ -21,8 +25,9 @@ repo = 'polkadot'
 gh_polkadot = SubRef.new(format('%<owner>s/%<repo>s', { owner: owner, repo: repo }))
 last_release_ref = gh_polkadot.get_last_ref()
 
-polkadot_ref1 = ARGV[0] || last_release_ref
-polkadot_ref2 = ARGV[1] || 'HEAD'
+polkadot_ref2 = ARGV[0] || 'HEAD'
+polkadot_ref1 = ARGV[1] || last_release_ref
+
 output = ARGV[2] || 'release-notes.md'
 
 ENV['REF1'] = polkadot_ref1
diff --git a/polkadot/scripts/changelog/templates/global_priority.md.tera b/polkadot/scripts/changelog/templates/global_priority.md.tera
index 87fa0e3b9eb..933f878ceae 100644
--- a/polkadot/scripts/changelog/templates/global_priority.md.tera
+++ b/polkadot/scripts/changelog/templates/global_priority.md.tera
@@ -1,5 +1,5 @@
 {% import "high_priority.md.tera" as m_p -%}
-## Global Priority
+## Upgrade Priority
 
 {%- set polkadot_prio = 0 -%}
 {%- set substrate_prio = 0 -%}
diff --git a/polkadot/scripts/changelog/templates/migrations-db.md.tera b/polkadot/scripts/changelog/templates/migrations-db.md.tera
new file mode 100644
index 00000000000..d2fd8105e41
--- /dev/null
+++ b/polkadot/scripts/changelog/templates/migrations-db.md.tera
@@ -0,0 +1,26 @@
+{%- import "change.md.tera" as m_c %}
+{%- set_global db_migration_count = 0 -%}
+
+## Database Migrations
+
+{% for pr in changes | sort(attribute="merged_at") -%}
+
+{%- if pr.meta.B and pr.meta.B.value == 0 %}
+{#- We skip silent ones -#}
+{%- else -%}
+{%- if pr.meta.E and pr.meta.E.value == 2 -%}
+{%- set_global db_migration_count = db_migration_count + 1 -%}
+- {{ m_c::change(c=pr) }}
+{% endif -%}
+{% endif -%}
+{% endfor -%}
+
+{%- if db_migration_count == 0 -%}
+No Database migration detected in this release.
+{% else  %}
+
+There is {{ db_migration_count }} database migration(s) in this release.
+
+Database migrations are operations bringing your database to the latest stand.
+Some migrations may break compatibility and making a backup of your database is highly recommended.
+{%- endif %}
diff --git a/polkadot/scripts/changelog/templates/migrations-runtime.md.tera b/polkadot/scripts/changelog/templates/migrations-runtime.md.tera
new file mode 100644
index 00000000000..36529e0d21e
--- /dev/null
+++ b/polkadot/scripts/changelog/templates/migrations-runtime.md.tera
@@ -0,0 +1,25 @@
+{%- import "change.md.tera" as m_c %}
+{%- set_global runtime_migration_count = 0 -%}
+
+## Runtime Migrations
+
+{% for pr in changes | sort(attribute="merged_at") -%}
+
+{%- if pr.meta.B and pr.meta.B.value == 0 %}
+{#- We skip silent ones -#}
+{%- else -%}
+{%- if pr.meta.E and pr.meta.E.value == 1 -%}
+{%- set_global runtime_migration_count = runtime_migration_count + 1 -%}
+- {{ m_c::change(c=pr) }}
+{% endif -%}
+{% endif -%}
+{% endfor -%}
+
+{%- if runtime_migration_count == 0 -%}
+No Runtime migration detected in this release.
+{% else  %}
+
+There is {{ runtime_migration_count }} runtime migration(s) in this release.
+
+Runtime migrations are operations running once during a runtime upgrade.
+{%- endif %}
diff --git a/polkadot/scripts/changelog/templates/migrations.md.tera b/polkadot/scripts/changelog/templates/migrations.md.tera
deleted file mode 100644
index af04821a2e1..00000000000
--- a/polkadot/scripts/changelog/templates/migrations.md.tera
+++ /dev/null
@@ -1,14 +0,0 @@
-{%- import "change.md.tera" as m_c %}
-
-## Migrations
-
-{% for pr in changes | sort(attribute="merged_at") -%}
-
-{%- if pr.meta.B and pr.meta.B.value == 0 %}
-{#- We skip silent ones -#}
-{%- else -%}
-{%- if pr.meta.E and pr.meta.E.value == 1 -%}
-- {{ m_c::change(c=pr) }}
-{% endif -%}
-{% endif -%}
-{% endfor -%}
diff --git a/polkadot/scripts/changelog/templates/template.md.tera b/polkadot/scripts/changelog/templates/template.md.tera
index 00040a43669..e6e800fd9c7 100644
--- a/polkadot/scripts/changelog/templates/template.md.tera
+++ b/polkadot/scripts/changelog/templates/template.md.tera
@@ -21,7 +21,9 @@ This release contains the changes from `{{ env.REF1 }}` to `{{ env.REF2 }}`.
 
 {% include "compiler.md.tera" -%}
 
-{% include "migrations.md.tera" -%}
+{% include "migrations-db.md.tera" -%}
+
+{% include "migrations-runtime.md.tera" -%}
 
 {% include "runtimes.md.tera" -%}
 
-- 
GitLab