Skip to content
Snippets Groups Projects
Select Git revision
  • ec6230c996c49ab16d198ca4da13c16b6e5ca760
  • master default protected
  • 0.5.9
  • 0.5.8
  • 0.5.7
  • 0.5.6
  • 0.5.5
  • 0.5.4
  • 0.5.3
  • 0.5.2
  • 0.5.1
  • 0.5.0
  • 0.4.17
  • 0.4.16
  • 0.4.15
  • 0.4.14
  • 0.4.13
  • 0.4.12
  • 0.4.11
  • 0.4.10
  • 0.4.9
  • 0.4.8
22 results

test2.html

Blame
  • update-changelog.nix 2.70 KiB
    {pkgs', ...}: let
      bashFktScript = import ./bash-fkt.nix {
        inherit pkgs';
      };
    in
      pkgs'.writeShellScriptBin "update-changelog" ''
    
        source ${pkgs'.common}/bin/common
        ${bashFktScript}
    
        echo_section "Update Changelog"
        echo_hint "This script will update the changelog."
        echo_hint "The command is executed in the current working directory and not in a nix derivation."
        cd_working_dir
    
        echo_step "Updating changelog"
    
        CHANGELOG_PATH="./CHANGELOG.md"
        latestDocumentedVersion=$(${pkgs'.gnugrep}/bin/grep '## \['  $CHANGELOG_PATH |  sed -E 's/## \[([0-9]+\.[0-9]+\.[0-9]+).*/\1/' | head -1)
        if [ -z "$latestDocumentedVersion" ]; then
             echo_fail "Could not find latest documented version in changelog"
             echo_hint "Please add a version entry in the file $CHANGELOG_PATH"
             exit 1
        fi
    
        currentVersion=$(${pkgs'.version}/bin/version print -g)
        if [ "$latestDocumentedVersion" = "$currentVersion" ]; then
          echo_ok "changelog already up to date"
        else
    
            tags=$(${pkgs'.git}/bin/git tag --sort=creatordate)
            tags_array=($tags)
            position=$(${pkgs'.coreutils}/bin/printf "%s\n" "''${tags_array[@]}" | ${pkgs'.gnugrep}/bin/grep -n "^$latestDocumentedVersion$" | ${pkgs'.coreutils}/bin/cut -d: -f1)
            if [ -z "$position" ]; then
                echo_fail "Could not find latest documented version in git tags"
                echo_hint "Please check the git tags"
                exit 1
            fi
    
            next_position=$((position + 1))
    
            if [ $next_position -le ''${#tags_array[@]} ]; then
                next_tag=''${tags_array[''$next_position - 1]}
            else
                echo_fail "Could not find next tag"
                echo_hint "Please check the git tags"
                exit 1
            fi
    
            echo_step "Generating changelog"
            tmpChangelog=$(${pkgs'.mktemp}/bin/mktemp)
            if ! ${pkgs'.git-chglog}/bin/git-chglog --config ./.config/chglog/config.yml -o $tmpChangelog $next_tag..
            then
              echo_fail "git-chglog failed"
              ${pkgs'.coreutils}/bin/rm $tmpChangelog
              exit 1
            fi
    
            newChanges=$(${pkgs'.coreutils}/bin/cat $tmpChangelog)
            ${pkgs'.coreutils}/bin/rm $tmpChangelog
    
            if [ -n "$newChanges" ]; then
              ${pkgs'.gnused}/bin/sed -i '/^# Changelog/d' $CHANGELOG_PATH
              ${pkgs'.coreutils}/bin/mv $CHANGELOG_PATH ''${CHANGELOG_PATH}.old
    
              echo -e "# Changelog\n\n" > $CHANGELOG_PATH
              echo "$newChanges" >> $CHANGELOG_PATH
    
              ${pkgs'.coreutils}/bin/cat "''${CHANGELOG_PATH}.old" >> $CHANGELOG_PATH
              ${pkgs'.coreutils}/bin/rm ''${CHANGELOG_PATH}.old
              echo_ok "changelog updated"
            fi
        fi
    
        echo_ok "Change log updated"
      ''