feat(doc): changelog system (#6350)

This system provides rules and automatizes (Deno-typescript) the creation of a changelog file to help developers to adapt their code and know what is new with every (pre)release
This commit is contained in:
Yehonal
2021-06-15 11:04:29 +02:00
committed by GitHub
parent 067eb82302
commit 3f70d0b80f
14 changed files with 1447 additions and 19 deletions

View File

@@ -0,0 +1,54 @@
import * as semver from "https://deno.land/x/semver/mod.ts";
// specify the needed paths here
const CHANGELOG_PATH = "doc/changelog";
const CHANGELOG_PENDING_PATH = `${CHANGELOG_PATH}/pendings`;
const CHANGELOG_MASTER_FILE = `${CHANGELOG_PATH}/master.md`;
const ACORE_JSON = "./acore.json";
// read the acore.json file to work with the versioning
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile(ACORE_JSON);
const acoreInfo = JSON.parse(decoder.decode(data));
let changelogText = await Deno.readTextFile(CHANGELOG_MASTER_FILE);
const currentVersion = acoreInfo.version;
const res=Deno.run({ cmd: [ "git", "rev-parse",
"HEAD"],
stdout: 'piped',
stderr: 'piped',
stdin: 'null' });
await res.status();
const gitVersion = new TextDecoder().decode(await res.output());
for await (const dirEntry of Deno.readDir(CHANGELOG_PENDING_PATH)) {
if (!dirEntry.isFile || !dirEntry.name.endsWith(".md")) {
continue;
}
// Upgrade the prerelease version number (e.g. 1.0.0-dev.1 -> 1.0.0-dev.2)
acoreInfo.version = semver.inc(acoreInfo.version, "prerelease", {
includePrerelease: true,
});
// read the pending file found and add it at the beginning of the changelog text
const data = await Deno.readTextFile(
`${CHANGELOG_PENDING_PATH}/${dirEntry.name}`,
);
changelogText = `## ${acoreInfo.version} | Commit: ${gitVersion}\n\n${data}\n${changelogText}`;
// remove the pending file
await Deno.remove(`${CHANGELOG_PENDING_PATH}/${dirEntry.name}`);
}
// write to acore.json and master.md only if new version is available
if (currentVersion != acoreInfo.version) {
console.log(`Changelog version upgraded from ${currentVersion} to ${acoreInfo.version}`)
Deno.writeTextFile(CHANGELOG_MASTER_FILE, changelogText);
Deno.writeTextFile(ACORE_JSON, JSON.stringify(acoreInfo, null, 2)+"\n");
} else {
console.log("No changelogs to add")
}

125
apps/ci/ci-pending-sql.sh Normal file
View File

@@ -0,0 +1,125 @@
#!/usr/bin/env bash
CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$CURRENT_PATH/../bash_shared/includes.sh"
UPDATES_PATH="$AC_PATH_ROOT/data/sql/updates/"
COMMIT_HASH=
function import() {
db=$1
folder="db_"$db
pendingPath="$AC_PATH_ROOT/data/sql/updates/pending_$folder"
updPath="$UPDATES_PATH/$folder"
latestUpd=$(ls -1 $updPath/ | tail -n 1)
if [ -z $latestUpd ]; then
echo "FIRST UPDATE FILE MISSING!! DID YOU ARCHIVED IT?";
exit 1;
fi
dateToday=$(date +%Y_%m_%d)
counter=0
dateLast=$latestUpd
tmp=${dateLast#*_*_*_}
oldCnt=${tmp%.sql}
oldDate=${dateLast%_$tmp}
if [ "$oldDate" = "$dateToday" ]; then
((counter=10#$oldCnt+1)) # 10 # is needed to explictly add to a base 10 number
fi;
for entry in "$pendingPath"/*.sql
do
if [[ -e $entry ]]; then
oldVer=$oldDate"_"$oldCnt
cnt=$(printf -v counter "%02d" $counter ; echo $counter)
newVer=$dateToday"_"$cnt
startTransaction="START TRANSACTION;";
updHeader="ALTER TABLE version_db_$db CHANGE COLUMN $oldVer $newVer bit;";
endTransaction="COMMIT;";
newFile="$updPath/$dateToday_$cnt.sql"
oldFile=$(basename "$entry")
prefix=${oldFile%_*.sql}
suffix=${oldFile#rev_}
rev=${suffix%.sql}
isRev=0
if [[ $prefix = "rev" && $rev =~ ^-?[0-9]+$ ]]; then
isRev=1
fi
echo "-- DB update $oldVer -> $newVer" > "$newFile";
if [[ $isRev -eq 1 ]]; then
echo "DROP PROCEDURE IF EXISTS \`updateDb\`;" >> "$newFile";
echo "DELIMITER //" >> "$newFile";
echo "CREATE PROCEDURE updateDb ()" >> "$newFile";
echo "proc:BEGIN DECLARE OK VARCHAR(100) DEFAULT 'FALSE';" >> "$newFile";
echo "SELECT COUNT(*) INTO @COLEXISTS" >> "$newFile";
echo "FROM information_schema.COLUMNS" >> "$newFile";
echo "WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'version_db_$db' AND COLUMN_NAME = '$oldVer';" >> "$newFile";
echo "IF @COLEXISTS = 0 THEN LEAVE proc; END IF;" >> "$newFile";
fi
echo "$startTransaction" >> "$newFile";
echo "$updHeader" >> "$newFile";
if [[ $isRev -eq 1 ]]; then
echo "SELECT sql_rev INTO OK FROM version_db_$db WHERE sql_rev = '$rev'; IF OK <> 'FALSE' THEN LEAVE proc; END IF;" >> "$newFile";
fi;
echo "--" >> "$newFile";
echo "-- START UPDATING QUERIES" >> "$newFile";
echo "--" >> "$newFile";
echo "" >> "$newFile";
cat $entry >> "$newFile";
echo "" >> "$newFile";
echo "--" >> "$newFile";
echo "-- END UPDATING QUERIES" >> "$newFile";
echo "--" >> "$newFile";
echo "UPDATE version_db_$db SET date = '$newVer' WHERE sql_rev = '$rev';" >> "$newFile";
echo "$endTransaction" >> "$newFile";
if [[ $isRev -eq 1 ]]; then
echo "END //" >> "$newFile";
echo "DELIMITER ;" >> "$newFile";
echo "CALL updateDb();" >> "$newFile";
echo "DROP PROCEDURE IF EXISTS \`updateDb\`;" >> "$newFile";
fi;
currentHash="$(git log --diff-filter=A "$entry" | grep "^commit " | sed -e 's/commit //')"
if [[ "$COMMIT_HASH" != *"$currentHash"* ]]
then
COMMIT_HASH="$COMMIT_HASH $currentHash"
fi
rm $entry;
oldDate=$dateToday
oldCnt=$cnt
((counter+=1))
fi
done
}
import "world"
import "characters"
import "auth"
echo "Done."