From: Dan Brown Date: Fri, 22 Nov 2019 21:49:52 +0000 (+0000) Subject: Added scripts used for deploy and translation attribution X-Git-Url: http://source.bookstackapp.com/devops/commitdiff_plain/6043c03b615a29e33b9ed6023e6cde472201247f Added scripts used for deploy and translation attribution --- diff --git a/meta-scripts/bookstack-release-steps b/meta-scripts/bookstack-release-steps new file mode 100755 index 0000000..6f1afc3 --- /dev/null +++ b/meta-scripts/bookstack-release-steps @@ -0,0 +1,28 @@ +#!/bin/bash + +echo "Enter the full version (v0.25.5) and press [ENTER]:" +read version + +echo "" +echo "" + +# Translator Attribution Update +echo "bookstack-update-translators" +echo "git commit -a -m \"Updated translator attribution before release ${version}\"" + +# Merge codebase from master +echo "git checkout release" +echo "git merge master" +echo "" + +# Builds deps and increment version +echo "npm run production" +echo "echo \"${version}\" > version" +echo "git commit -a -m \"Updated version and assets for release ${version}\"" +echo "" + + +# Tag release and push it to GitHub +echo "git tag -a ${version} -m \"Beta Release ${version}\" -s" +echo "git push origin release" +echo "git push origin ${version}" \ No newline at end of file diff --git a/meta-scripts/bookstack-update-translators b/meta-scripts/bookstack-update-translators new file mode 100755 index 0000000..717b0cf --- /dev/null +++ b/meta-scripts/bookstack-update-translators @@ -0,0 +1,142 @@ +#!/usr/bin/env php + $languages) { + if (count($languages) === 0 || (count($languages) === 1 && empty($languages[0]))) continue; + if ($name === 'Dan Brown (ssddanbrown)' || $name === 'Name') continue; + $output .= $name . $reportDelimiter . implode('; ', $languages) . "\n"; + } + + file_put_contents($reportLocation, $output); +} + +function mergeCsvDataIntoReportMap(array &$reportMap, array $csvData, string $reportDelimiter) { + foreach ($csvData as $csvLine) { + $name = $csvLine['Name']; + $name = str_replace($reportDelimiter, '', $name); + $languages = explode('; ', $csvLine['Languages']); + if (isset($reportMap[$name])) { + $languages = array_unique(array_merge($languages, $reportMap[$name])); + } + $reportMap[$name] = $languages; + } +} + +function loadExistingReportIntoMap($reportDelimiter, $reportLocation) { + try { + $reportData = file_get_contents($reportLocation); + } catch (Exception $exception) { + $reportData = ''; + } + $reportLines = explode("\n", $reportData); + $reportMap = []; + foreach ($reportLines as $reportLine) { + if (empty($reportLine)) continue; + [$name, $langs] = explode($reportDelimiter, $reportLine); + $splitLangs = explode('; ', $langs); + $reportMap[$name] = $splitLangs; + } + return $reportMap; +} + +function exportTopMembersReport($key) { + $result = makeMemberExportReport($key); + + $exportHash = $result->hash; + $csv = downloadMemberReport($exportHash, $key); + + return $csv; +} + +function makeMemberExportReport(string $key) { + $url = 'https://api.crowdin.com/api/project/bookstack/reports/top-members/export'; + $postData = [ + 'date_from' => '2019-10-01', + 'date_to' => date('Y-m-d'), + 'format' => 'csv', + 'json' => true, + 'key' => $key, + ]; + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, 15); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); + + $result = curl_exec($ch); + curl_close($ch); + + $data = json_decode($result); + return $data; +} + +function downloadMemberReport(string $exportHash, string $key) { + $params = [ + 'hash' => $exportHash, + 'key' => $key + ]; + $url = 'https://api.crowdin.com/api/project/bookstack/reports/top-members/download'; + $url .= '?' . http_build_query($params); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_TIMEOUT, 15); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + curl_close($ch); + + return $result; +} + +/** + * Convert a comma separated string into an associated array. + * @link http://gist.github.com/385876 (Modified) + * @author Jay Williams (Modified) + * @copyright Copyright (c) 2010, Jay Williams (Modified) + * @license http://www.opensource.org/licenses/mit-license.php MIT License + */ +function csv_to_array(string $csvString): array +{ + + $header = null; + $data = []; + $lines = explode("\n", trim($csvString)); + foreach ($lines as $line) { + $csvLine = str_getcsv($line); + if (!$header) { + $header = $csvLine; + } else { + $data[] = array_combine($header, $csvLine); + } + } + + return $data; +}