Difference between revisions of "Documentation/Nightly/Developers/ReleaseProcess"
Line 155: | Line 155: | ||
# | # | ||
# >>> Make sure the current commit corresponds to ${SVN_REVISION}. <<< | # >>> Make sure the current commit corresponds to ${SVN_REVISION}. <<< | ||
− | # >>> For patch release, | + | # >>> For patch release, checkout master-XY instead of master. <<< |
# | # | ||
+ | git checkout master | ||
git log -1 | git log -1 | ||
− | git tag -s -m "ENH: Slicer ${X}.${Y}.${Z}" v${X}.${Y}.${Z} | + | git tag -s -m "ENH: Slicer ${X}.${Y}.${Z}" v${X}.${Y}.${Z} |
git push origin v${X}.${Y}.${Z} | git push origin v${X}.${Y}.${Z} | ||
</li> | </li> |
Revision as of 03:54, 16 January 2019
Home < Documentation < Nightly < Developers < ReleaseProcessContents
- 1 Release planning
- 2 Day 1: Release
- 2.1 Update Slicer.crt and commit change
- 2.2 CMakeLists.txt: Update the Slicer version information for the release
- 2.3 CMakeLists.txt: Update the Slicer version information for the development
- 2.4 Tag and publish SlicerBuildEnvironment docker image
- 2.5 Update release scripts
- 2.6 Disable regular nightly builds
- 2.7 Update ExtensionsIndex
- 2.8 Update CDash
- 2.9 Generate application and extension packages
- 2.10 Tag the repository
- 2.11 Create release branch
- 2.12 Update Release Details on the wiki
- 3 Day 2: Post release
- 3.1 Re-enable regular nightly builds
- 3.2 Update Mantis
- 3.3 Update Slicer wiki
- 3.4 Prepare Slicer Announcement
- 3.5 Clean-up older nightly packages
- 3.6 Manually sign packages
- 3.7 Tag release packages
- 3.8 Confirm that packages are tagged
- 3.9 Version NA-MIC data tree
- 3.10 Update external website
- 3.11 Update ExtensionStats extension
- 3.12 Publish Slicer Announcement
- 4 Appendix
- 4.1 Sign packages
- 4.2 Backport commit into release branch
- 4.3 Script to upload Slicer packages
- 4.4 Limitations of download.slicer.org
- 4.5 Explicit tagging of release packages
- 4.6 User Survey (not used anymore)
- 4.7 Converting Google document to markdown
- 4.8 Generating a Discourse compliant table of content for a Markdown document
Release planning
- Decide what will be the version number for the next stable release
- Update issue tracker: https://issues.slicer.org/roadmap_page.php
- Define a release date
- Announce the release: https://discourse.slicer.org/t/upcoming-slicer-4-8-release/1120
Day 1: Release
Since there all development occurs on master
, each time version is updated, two commits will be required.
Update Slicer.crt and commit change
See https://github.com/Slicer/Slicer/blob/master/Base/QTCore/Resources/Certs/README
CMakeLists.txt: Update the Slicer version information for the release
Update the Slicer version information for the release:
In
CMakeLists.txt
, update at least one these variables:Slicer_VERSION_MAJOR
,Slicer_VERSION_MINOR
,Slicer_VERSION_PATCH
-
Re-run CMake with
-DSlicer_RELEASE_TYPE:STRING=Stable
. This is required to updateUtilities/Scripts/SlicerWizard/__version__.py
.If not doing a clean build, make sure to explicitly specify the version re-configuring with
-DSlicer_VERSION_MAJOR:STRING=X -DSlicer_VERSION_MINOR:STRING=Y -DSlicer_VERSION_PATCH:STRING=Z .
Commit the above changes using this message like:
ENH: Slicer X.Y.Z
- Keep track of the SVN_REVISION and SVN_BRANCH for the next steps
CMakeLists.txt: Update the Slicer version information for the development
Update the Slicer version information for the development:
In
CMakeLists.txt
,- Update
Slicer_VERSION_MAJOR
and/orSlicer_VERSION_MINOR
- Update
-
Re-run CMake with
-DSlicer_RELEASE_TYPE:STRING=Experimental
. This is required to updateUtilities/Scripts/SlicerWizard/__version__.py
.If not doing a clean build, make sure to explicitly specify the version re-configuring with
-DSlicer_VERSION_MAJOR:STRING=X -DSlicer_VERSION_MINOR:STRING=Y -DSlicer_VERSION_PATCH:STRING=Z .
Commit the above changes using this message like:
cd ~/Projects/Slicer git add -A git commit -m "ENH: Begin X.Y.Z development"
Tag and publish SlicerBuildEnvironment docker image
-
Tag the docker build environment image. See https://github.com/Slicer/SlicerBuildEnvironment/blob/master/README.rst#maintainers
If the environment did not change, you may skip this step for patch release.
Keep track of the selected TAG for updating the release scripts
Update release scripts
- Update release scripts. See https://github.com/Slicer/DashboardScripts#maintenance-guides
Disable regular nightly builds
- On each factory machines, disable regular nightly build in crontab and task scheduler.
Update ExtensionsIndex
This applies to https://github.com/Slicer/ExtensionsIndex and you may skip this step for patch release.
Create branch X.Y based of master:
DEST_VERSION=X.Y cd /tmp git clone git@github.com:Slicer/ExtensionsIndex cd ExtensionsIndex git checkout master git push origin master:${DEST_VERSION}
Update CDash
This applies to the CDash instance associated with http://slicer.cdash.org/index.php?project=Slicer4 and you may skip this step for patch release.
Create new CDash groups for extension submissions associated with
X.Y
release:Extensions-X.Y-Nightly Extensions-X.Y-Continuous
Generate application and extension packages
- Generate packages running Slicer package scripts on each factory machines. (These are the scripts updated in the previous step)
Tag the repository
Tag the repository:
Set version variables:
X=<major-version> Y=<minor-version> Z=<patch-version> echo "X.Y.Z is ${X}.${Y}.${Z}"
Set SVN revision variable:
SVN_REVISION=<svn-revision-for-release>
SVN (for regular release):
cd ~/Projects svn checkout http://svn.slicer.org/Slicer4/trunk Slicer-${X}.${Y}-SVN cd Slicer-${X}.${Y}-SVN svn copy -r${SVN_REVISION} http://svn.slicer.org/Slicer4/trunk \ http://svn.slicer.org/Slicer4/tags/Slicer-${X}-${Y} \ -m "ENH: Tag of ${X}.${Y}.${Z} release based on r${SVN_REVISION}."
SVN (for patch release):
cd ~/Projects svn checkout http://svn.slicer.org/Slicer4/branches/Slicer-${X}-${Y} Slicer-${X}.${Y}-SVN cd Slicer-${X}.${Y}-SVN svn copy -r${SVN_REVISION} http://svn.slicer.org/Slicer4/branches/Slicer-${X}-${Y} \ http://svn.slicer.org/Slicer4/tags/Slicer-${X}-${Y}-{Z} \ -m "ENH: Tag of ${X}.${Y}.${Z} release based on r${SVN_REVISION}."
GIT:
cd ~/Projects git clone git@github.com:Slicer/Slicer Slicer-${X}.${Y} cd Slicer-${X}.${Y}
# # Rollback by one commit to ignore the "ENH: Begin X.Y.Z development" commit # git reset --hard HEAD^
# # >>> Make sure the current commit corresponds to ${SVN_REVISION}. <<< # >>> For patch release, checkout master-XY instead of master. <<< # git checkout master git log -1 git tag -s -m "ENH: Slicer ${X}.${Y}.${Z}" v${X}.${Y}.${Z} git push origin v${X}.${Y}.${Z}
Create release branch
Create release branch:
Set version variables (same value as in the previous step):
X=<major-version> Y=<minor-version> Z=<patch-version> echo "X.Y.Z is ${X}.${Y}.${Z}"
Set SVN revision variable (same value as in the previous step):
SVN_REVISION=<svn-revision-for-release>
SVN (Keep track of the branch revision. It will be referred below as
BRANCHED_REVISION
.):cd ~/Projects/Slicer-${X}.${Y}-SVN svn copy -r ${SVN_REVISION} http://svn.slicer.org/Slicer4/trunk http://svn.slicer.org/Slicer4/branches/Slicer-${X}-${Y} \ -m "ENH: Branching from trunk to Slicer-${X}-${Y} at r${SVN_REVISION}"
svn switch http://svn.slicer.org/Slicer4/branches/Slicer-${X}-${Y}
BRANCHED_REVISION=$(svn info | grep "Revision" | awk '{print $2}') echo "BRANCHED_REVISION is ${BRANCHED_REVISION}"
GIT:
cd ~/Projects/Slicer-${X}.${Y} # Source: http://ivanz.com/2009/01/15/selective-import-of-svn-branches-into-a-gitgit-svn-repository/ # and https://stackoverflow.com/questions/19712735/git-svn-cannot-setup-tracking-information-starting-point-is-not-a-branch git config --add svn-remote.svn-${X}${Y}.url http://svn.slicer.org/Slicer4/branches/Slicer-${X}-${Y} git config --add svn-remote.svn-${X}${Y}.fetch :refs/remotes/git-svn-${X}${Y} git svn fetch svn-${X}${Y} -r ${BRANCHED_REVISION} git checkout -b master-${X}${Y} remotes/git-svn-${X}${Y} git svn rebase git push origin master-${X}${Y}
Update Release Details on the wiki
- Update Release Details with release information
Day 2: Post release
Re-enable regular nightly builds
On each factory machines, re-enable build in crontab and task scheduler.
Update Mantis
This applies to the Mantis instance associated with https://issues.slicer.org
- "Release" current target
- Create new target
- Check the "fixed in" fields
Update Slicer wiki
This applies to the MediaWiki instance associated with https://wiki.slicer.org
There are two steps involved:
- copy of the pages associated with the
Nightly
namespace into theX.Y
namespace. - update of permanent pages referencing the current Slicer version
As of November 2016, the process is fully automated and can be done using Base/Python/slicer/release/wiki.py script.
1) Install prerequisites:
- Check with <email>jchris.fillionr@kitware.com</email> to get the credential associated with
UpdateBot
user. - Install mwdoc:
$ pip install mwdoc
2) Query current version information:
$ python Base/Python/slicer/release/wiki.py query
3) Copy and update pages
$ DEST_VERSION=X.Y $ python Base/Python/slicer/release/wiki.py update ${DEST_VERSION} $ python Base/Python/slicer/release/wiki.py copy ${DEST_VERSION}
The following pages have been updated:
- Template:Documentation/prevversion
- Template:Documentation/nextversion
- Template:Documentation/currentversion
- Template:Documentation/versionlist
- Template:Documentation/acknowledgments-versionlist
- Documentation
- Documentation/Release/Acknowledgments
The following pages with #REDIRECT have been updated:
- FAQ
- Documentation/Release
- Documentation/Release/Announcements
- Documentation/Release/Report a problem
- Documentation/UserTraining
- Documentation/UserFeedback
- Documentation/Release/SlicerApplication/HardwareConfiguration
Prepare Slicer Announcement
-
(1) Reusing previous documents available in this shared Google folder, create and update the following new Google documents:
- Slicer 4.12: Kitware Social Media (Shared Publicly)
-
Slicer 4.12: Summary, Highlights and Changelog (Shared Publicly)
Updating this document is currently a tedious manual process. It will soon be streamlined by including descriptive text with each contribution to the code base.
- Slicer 4.12: Kitware Annoucement blog
-
(2) Once the Slicer 4.12 Release notes document is mature, post it on discourse for including images.
- (a) Convert it by following #Converting_Google_document_to_markdown guide.
- (b) Then, update the generated markdown document to be compliant with discourse. See #Generating_a_Discourse_compliant_table_of_content_for_a_Markdown_document guide.
- (c) Finally, create a draft discourse post selecting Draft category.
- (d) Select the destination category but do NOT Publish the shared draft.
Clean-up older nightly packages
This applies to the Midas instance associated with http://slicer.kitware.com
See https://gist.github.com/jcfr/ea9ef199bd5a3e071b8f
Manually sign packages
- If needed, create a X.Y.Z folder in Slicer/Packages/Application/Release
- Download package from http://slicer.cdash.org/index.php?project=Slicer4. You may have to click Previous to list the packages generated during Day1.
- After downloading, locally compute the md5 sums and check that they match with the sums associated with download link displayed on the download page:
Sign the package following these instructions:
- Linux: Not available - see #Tag_release_packages
- macOS: See #macOS_Code_Signing
- Windows: See #Windows_Code_Signing
- Upload the signed package using upload-Slicer-to-slicer-kitware-com.cmake.
- The newly uploaded package will be listed in the Midas feed. See http://slicer.kitware.com/midas3/feed
- Manually update the name of the item removing the
(1)
suffix and appending[signed]
. Make sure to not update the bitstream name. For example: see Slicer-4.8.0-win-amd64.exe [signed] available here - For future reference, copy the unsigned packages into the folder created above (Keep the default Create a reference to the existing item)
Tag release packages
This applies to the Midas instance associated with http://slicer.kitware.com
Since the macOS and Windows packages were uploaded during the manual signing, they are already associated with the release tag. On the other hand, due to limitations
of http://download.slicer.org, the Linux package must be downloaded and re-uploaded.
- Download packages from http://slicer.cdash.org/index.php?project=Slicer4. You may have to click Previous to list the packages generated during Day1.
- After downloading, locally compute the md5 sums and check that they match with the sums associated with download link displayed on the download page:
- Re-upload each packages using upload-Slicer-to-slicer-kitware-com.cmake script.
- The newly uploaded packages will be listed in the Midas feed. See http://slicer.kitware.com/midas3/feed
- After each upload, manually update the name of the item removing the
(1)
suffix. Make sure to not update the bitstream name. - For future reference, copy the packages into the folder created above (Keep the default Create a reference to the existing item)
Confirm that packages are tagged
To confirm that all three packages are tagged. The following URL should return three packages:
http://slicer.kitware.com/midas3/api/json?method=midas.slicerpackages.package.list&release=4.10.0
Version NA-MIC data tree
This applies to the Midas instance associated with http://slicer.kitware.com
If you do not have an account and/or if you do not belong to the
DataManager
group:Create an account on the extension server and obtain an API Key. You will then use your midas login and api key to substitute
<YOUR-MIDAS-LOGIN>
and<YOUR-MIDAS-APIKEY>
in the examples.If not already done, go to NA-MIC community and click on
Join community
Send an email on the developer list asking to be added to the
DataManager
group on NA-MIC community. That will grant you read/write permissions to theData
folder and sub-folders.
Install prerequisites
$ mkvirtualenv -p python2.7 version_namic_datatree $ pip install pydas
Confirm that the
id
of theData
folder is still 301.Simulate creation of
X.Y
data folders basedNightly
onesMIDAS_EMAIL=<YOUR-MIDAS-LOGIN> MIDAS_API_KEY=<YOUR-MIDAS-APIKEY> DEST_VERSION=X.Y DATA_FOLDER_ID=301
$ cd /path/to/Slicer/Base/Python/slicer/release $ python midasdata.py --url=http://slicer.kitware.com/midas3 --data_id=$DATA_FOLDER_ID \ --email=$MIDAS_EMAIL --apikey=$MIDAS_API_KEY --source_version=Nightly --dest_version=$DEST_VERSION --dry-run
Example of output:
Application ( folder_id: 302 ) '-Nightly ( folder_id: 831 ) '-'-Testing ( folder_id: 832 ) '-'-'-Baseline ( folder_id: 889 ) '-'-'-'-DiffusionTensorImagingTutorial.png ( item_id: 12067 ) '-'-'-'-NeurosurgicalPlanningTutorial.png ( item_id: 12066 ) '-'-'-'-SlicerTestingTest.png ( item_id: 17760 ) '-'-'-Input ( folder_id: 833 ) '-'-'-'-AtlasTests ( folder_id: 834 ) '-'-'-'-'-2012-10-26-BrainAtlas.mrb ( item_id: 10276 ) [...] Module: VotingBinaryHoleFillingImageFilter ( folder_id: 1491 ) '-Nightly ( folder_id: 1491 ) '-'-Testing ( folder_id: 1492 ) '-'-'-Baseline ( folder_id: 1493 ) '-'-'-'-VotingBinaryHoleFillingImageFilterTest.nhdr ( item_id: 103418 ) '-'-'-'-VotingBinaryHoleFillingImageFilterTest.raw.gz ( item_id: 103419 )
Create
X.Y
data tree basedNightly
ones$ python midasdata.py --url=http://slicer.kitware.com/midas3 --data_id=301 \ --email=$MIDAS_EMAIL --apikey=$MIDAS_API_KEY --source_version=Nightly --dest_version=$DEST_VERSION Versioning of the NA-MIC Data tree for release X.Y... Versioning Modules... [...] Versioning Modules...[DONE] Versioning Application... Creating folder X.Y under Application directory Duplicating subfolders from Nightly to X.Y... Duplicating subfolders from Nightly to X.Y...[DONE] Versioning Application...[DONE] Versioning of the NA-MIC Data tree for release X.Y...[DONE]
Update external website
- http://en.wikipedia.org/wiki/3DSlicer
- Update version. See here for an example.
- Review page (list of external dependencies, ... ) and edit as needed.
- http://www.nitrc.org/projects/slicer/
- Login
- Go to Downloads -> Admin.
- Click on "Edit Release" associated with slicer package.
- Click on "Edit" associated the release named "Latest".
- Update Release Date field.
- Click on Submit/Refresh
Update ExtensionStats extension
- See https://github.com/fbudin69500/SlicerDeveloperToolsForExtensions/blob/master/ExtensionStats/ExtensionStats.py#L209
- Update list of extension names
- Update list of Slicer revisions
Publish Slicer Announcement
- Publish the discourse post created in #Prepare_Slicer_Announcement.
- Update Documentation/4.10/Announcements based of Documentation/4.8/Announcements
- Publish news item to Slicer NITRC project.
Appendix
Sign packages
macOS Code Signing
Packages have to be signed manually.
- (1) connecting using SSH to sign-srv-mac.kitware.com (Available only from within Kitware internal network)
-
(2) Download signing script
mkdir -p ~/tmp cd ~/tmp rm -rf macos-codesign-scripts git clone https://github.com/jcfr/macos-codesign-scripts
- (3) Download unsigned package using curl
-
(4) unlock the keychain
security unlock-keychain "Developer ID Application: Kitware Inc. (W38PE5Y733)"
-
(5) Run signing script
version=X.Y.Z cd ~/tmp ./macos-codesign-scripts/sign.bash \ org.slicer.slicer ${version} \ "Developer ID Application: Kitware Inc. (W38PE5Y733)" \ "Developer ID Installer: Kitware Inc. (W38PE5Y733)" \ ./Slicer-${version}-macosx-amd64.dmg
References:
Windows Code Signing
Packages have to be signed manually.
See Documentation/Nightly/Developers/Windows_Code_Signing for more information.
TBD - See #2697
Backport commit into release branch
The following steps will lead to the creation of new git-svn clone having two branches:
git-svn
git-svn-XY
Reference: http://www.dmo.ca/blog/20070608113513/
Step 1: Checkout sources
git clone git://github.com/Slicer/Slicer.git Slicer-X.Y cd Slicer-X.Y git svn init http://svn.slicer.org/Slicer4/trunk git update-ref refs/remotes/git-svn refs/remotes/origin/master git checkout master git svn rebase
Step 2: Add release branch remote
Edit .git/config
, and in addition to the existing 'git-svn' remote, add the following one:
[svn-remote "svn-XY"] url = http://svn.slicer.org/Slicer4/branches/Slicer-X-Y fetch = :refs/remotes/git-svn-XY
Step 3: Pull associated SVN branch
git svn fetch svn-XY git checkout -b master-XY git-svn-XY
Step 4: Backport
We can now cherry pick commit associated with master (trunk) into master-XY
(Slicer-X-Y)
Script to upload Slicer packages
File: upload-Slicer-to-slicer-kitware-com.cmake
cmake_minimum_required(VERSION 3.9.0) # # To run this script: # # cmake -P upload-Slicer-to-slicer-kitware-com.cmake # # # Variables to update: # # CMAKE_MODULE_PATH # # release # source_revision # source_checkoutdate # MIDAS_PACKAGE_EMAIL # MIDAS_PACKAGE_API_KEY # list(APPEND CMAKE_MODULE_PATH D:/D/N/Slicer-1/CMake ) include(MIDASAPIUploadPackage) set(operating_system "win") # linux, macosx, win set(release "4.8.0") set(source_revision "26489") set(source_checkoutdate "2017-10-18 05:11:33") set(MIDAS_PACKAGE_EMAIL "<YOUR-MIDAS-LOGIN>") set(MIDAS_PACKAGE_API_KEY "<YOUR-MIDAS-APIKEY>") set(ext_linux "tar.gz") set(ext_macosx "dmg") set(ext_win "exe") set(package_filepath "C:/Users/dashboard/Downloads/Slicer-${release}-${operating_system}-amd64.${ext_${operating_system}}") message(STATUS "Upload ${package_filepath}") set(MIDAS_PACKAGE_URL http://slicer.kitware.com/midas3) set(submission_type "experimental") set(architecture "amd64") set(package_type "installer") midas_api_upload_package( SERVER_URL ${MIDAS_PACKAGE_URL} SERVER_EMAIL ${MIDAS_PACKAGE_EMAIL} SERVER_APIKEY ${MIDAS_PACKAGE_API_KEY} SUBMISSION_TYPE ${submission_type} SOURCE_REVISION ${source_revision} SOURCE_CHECKOUTDATE ${source_checkoutdate} OPERATING_SYSTEM ${operating_system} ARCHITECTURE ${architecture} PACKAGE_FILEPATH ${package_filepath} PACKAGE_TYPE ${package_type} RELEASE ${release} RESULT_VARNAME output ) set(expected_output "ok") if(NOT "${output}" STREQUAL "${expected_output}") message(FATAL_ERROR "Problem with midas_api_upload_package()\n" "output:${output}\n" "expected_output:${expected_output}") endif()
Limitations of download.slicer.org
Considering that
(1) few minutes after a package is uploaded on http://slicer.kitware.com, it is indexed in the database associated with http://download.slicer.org, and
(2) the system indexing the package does NOT rewrite its database entries,
using the steps below will NOT result in an update of the packages reported on http://download.slicer.org.
Source code available at https://github.com/mhalle/slicer4-download.
Explicit tagging of release packages
Steps:
- If needed, create a X.Y.Z folder in Slicer/Packages/Application/Release
- Copy uploaded packages into the folder created above (Keep the default Create a reference to the existing item)
- Identify the item_id associated with uploaded packages. For example: 316530, 316529
- From Kitware internal network, SSH connect to
jcfr@slicer.kitware.com
(orjcfr@192.168.120.210
) - Connect to mysql
password=$(cat /var/www/midas3/core/configs/database.local.ini | grep database.params.password | cut -d"=" -f2 | head -n1 | sed 's/"//g')
mysql -u midas -p$password -D midas
- See file
/var/www/midas3/core/configs/database.local.ini
for password - Selected database is midas (
use midas
)
- List packages associated with identified items and check they are the appropriate ones:
select * from slicerpackages_package as p , item as i where i.item_id = p.item_id and p.item_id in (316530, 316529);
- Set release field
update slicerpackages_package set `release`="4.8.0" where item_id in (316530, 316529);
User Survey (not used anymore)
See https://docs.google.com/forms/d/1rggxoTV5KL_vt3gX9BNNAcKH4pnL5lkMqPnklOThINg
With each release, the title of the survey had to be updated.
Now, the Slicer welcome module has been updated to ask user to report feedback on the Slicer forum
Converting Google document to markdown
- (2) Open Google document in an other tab
- (3) Go to Tools -> Script Editor
- (4) Replace text with content of script opened in (1)
- (5) Save script specifying name (e.g slicer-4.12-converttomarkdown). Note that the script is associated with the document and will have to be imported with new version of the document.
- (6) From with the Script Editor, select Run -> Run Function -> ConvertToMarkdown
- (7) When asked, authorize the script to access your account and review permissions.
- (8) Check you email, you should receive a message entitled [MARKDOWN_MAKER] Title Of Document with an attachment named Title Of Document.md.
References:
- https://lifehacker.com/this-script-converts-google-documents-to-markdown-for-e-511746113
- https://github.com/mangini/gdocs2md
Generating a Discourse compliant table of content for a Markdown document
Prerequisites:
- Install executable gh-md-toc available at https://github.com/ekalinin/github-markdown-toc in the PATH
Step-by-steps:
Assuming the document for which a table of content should be generated is saved as /tmp/document.md:
- (1) Remove the "[[TOC]]" string left over from gdoc to markdown conversion
sed -i -E 's/^\[\[TOC\]\]//g' /tmp/document.md
- (2) Generate table of content
$ gh-md-toc /tmp/document.md > /tmp/toc.md
- (3) Create script to convert table of content and document to a format usable by discourse.
cat > /tmp/update-markdown-document-and-toc-for-discourse.sh << 'EOF' #!/usr/bin/env bash set -eo pipefail if [ $# -ne 2 ] then echo "Usage: $0 /path/to/toc.md /path/to/document.md" exit 0 fi toc_document=$1 document=$2 for idx in $(seq 1 10); do # Compute number of spaces expected for each level (( space_count = ${idx} * 3 )) spaces=$(printf %${space_count}s) echo echo "${spaces}level ${idx}" # Extract title and anchor from each TOC entries associated with level ${idx} for line in $(cat ${toc_document} | ack "^${spaces}\* \[" | tr -d " " | sed -E 's/\]\(\#/|/g' | sed -E 's/\*\[//g' | sed -E 's/\)//g'); do title=$(echo $line | cut -d"|" -f1) anchor=$(echo $line | cut -d"|" -f2) echo "${spaces}${title} - ${anchor}" # Replace title with html one header=$(printf %${idx}s | tr " " "#") sed -i -E "s|^${header} ${title}|\\<h${idx} id\\=\"heading--${anchor}\"\\>${title}\\<\\/h${idx}\\>|g" "${document}" # Replace anchor in table of content sed -i -E "s/#${anchor}/#heading--${anchor}/g" ${toc_document} done done EOF chmod u+x /tmp/update-markdown-document-and-toc-for-discourse.sh
- (4) Execute script to update in place the document
/tmp/update-markdown-document-and-toc-for-discourse.sh /tmp/toc.md /tmp/document.md
- (5) Copy content of /tmp/toc.md and /tmp/document.md into a discourse post. Depending on the length of the table of content combined with the document, you may have to update the discourse settings max post length.