5

I am automating version bumping of my project with this bash script:

#!/usr/bin/env bash CHANGELOG="Changelog.md" DEBIAN_CHANGELOG="debian/changelog" UPSTREAM_VERSION=$(cat VERSION) # Updating entries in rpm files DEB_RELEASE_NOTES=$(awk '{print " * " $0}' < RELEASE_NOTES) echo "Adding new Debian changelog entry for version $UPSTREAM_VERSION." dch -D unstable -m "$DEB_RELEASE_NOTES" --newversion "$UPSTREAM_VERSION-0debian1-unstable1" # Prompt user to edit Debian changelog $EDITOR_CHOICE "$DEBIAN_CHANGELOG" echo "Version updated successfully: $UPSTREAM_VERSION" 

What it does it sync and places the version in both rpm and debian packages. But this command:

dch -D unstable -m "$DEB_RELEASE_NOTES" --newversion "$UPSTREAM_VERSION-0debian1-unstable1" 

Gives me some trouble because in places upon debian/changelog the following:

mkdotenv (0.2.0-0debian1-unstable1) unstable; urgency=medium * * 1. Split codebase into multiple files. * 2. Use a seperate version file and define built version upon compile. * 4. [BUGFIX] If input file is same as output file copy input file into a temporary one. * 5. Improved Documentation -- Dimitrios Desyllas <[email protected]> Mon, 10 Mar 2025 20:08:00 +0200 

Whereas the RELEASE_NOTES file contains:

1. Split codebase into multiple files. 2. Use a seperate version file and define built version upon compile. 4. [BUGFIX] If input file is same as output file copy input file into a temporary one. 5. Improved Documentation 

Do you know why all lines are stuck as a single bullet???

1
  • 1
    You could replace the select_editor function and use sensible-editor instead Commented Mar 10 at 19:42

2 Answers 2

7

dch expects a single changelog entry, undecorated. It will format it for you, adding an asterisk and wrapping as appropriate.

For your use-case you need to run it once per entry, without specifying the target distribution. Then, to “close” the entries for the target version, run

dch -M -r -D unstable ignored 

This needs an argument but ignores it, hence the “ignored” argument. -r updates the first line in the changelog to specify the distribution given with -D; -M uses the name and email address specified in the “Maintainer” field in debian/control instead of relying on environment variables.

The overall process would look like this:

DEB_VERSION="$UPSTREAM_VERSION-0debian1-unstable1" while IFS= read -r line; do dch -v "$DEB_VERSION" -- "$line" done < RELEASE_NOTES dch -M -r -D unstable ignored 

There’s no need to “initialise” a new version, it happens automatically when dch is given a version that doesn’t match the version at the top of the changelog.

0
4

In the end was as @Stephen Kitt said:

#!/usr/bin/env bash UPSTREAM_VERSION=$(cat VERSION) echo "Adding new Debian changelog entry for version $UPSTREAM_VERSION." DEB_VERSION="$UPSTREAM_VERSION-0debian1~unstable1" if [ -f DEBEMAIL ];then DEBEMAIL_VAL=$(cat DEBEMAIL) fi DEBEMAIL_VAL=$(dialog --inputbox "Enter your email:" 8 50 "$DEBEMAIL_VAL" 3>&1 1>&2 2>&3) if [ ! -z "$DEBEMAIL_VAL" ]; then echo $DEBEMAIL_VAL > DEBEMAIL fi export DEBEMAIL=$DEBEMAIL_VAL dch --distribution unstable --newversion $DEB_VERSION -m "" while IFS= read -r line; do echo $line; dch -a "$line" done < RELEASE_NOTES # Prompt user to edit Debian changelog $EDITOR_CHOICE "$DEBIAN_CHANGELOG" echo "Version updated successfully: $UPSTREAM_VERSION" 

For this, you need to init the version by calling:

dch --newversion "$DEB_VERSION" 

Then for each line in the file RELEASE_NOTES we need to call:

 dch --newversion "$DEB_VERSION" -a "$line" 

This appends a line upon the debian/changelog file, then we finalize the line:

dch --newversion "$DEB_VERSION" --distribution unstable ignored 

Then the release needs to be finalized as:

dch --newversion "$DEB_VERSION" --distribution unstable ignored 

In your example, this will result this changelog entry:

mkdotenv (0.2.0-0debian1-unstable1) unstable; urgency=medium [ John Doe ] * 1. Split codebase into multiple files. * 2. Use a seperate version file and define built version upon compile. * 4. [BUGFIX] If input file is same as output file copy input file into a temporary one. * 5. Improved Documentation -- username <username@hostname> Mon, 10 Mar 2025 22:01:07 +0200 

Update 25/3/2025

Some lines were omitted if not DEBEMAIL env var exported, therefore I made a small prompt for the user to enter his/her email and store it upon DEBEMAIL file.

7
  • 3
    Nice! Thanks for taking the time to post the solution you went with. Just one minor note: you really don't want to use CAPS for shell variable names. Since, by convention, global environment variables are capitalized, it is bad practice to also use caps for your own, local variables because this can lead to naming collisions and hard to find bugs. Commented Mar 10 at 20:35
  • You shouldn’t need to repeat the version all the time — you only need it when initialising the version. Your finalisation command isn’t quite right, as I mentioned you need -r (or --release) and you only need it once, again without the version. Commented Mar 10 at 22:15
  • In fact you can’t initialise the version as you’re doing, running dch --newversion without a changelog entry opens an editor… Commented Mar 11 at 12:30
  • -r asks for DEBEMAIL or EMAIL env variable to be set @StephenKitt Commented Mar 11 at 15:28
  • Also I want to enforce my own version nevertheless. Commented Mar 11 at 16:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.