Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metadata escaping #8

Merged
merged 17 commits into from May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions linux/create-git-metadata.sh
@@ -1,3 +1,7 @@
escape () {
echo $1 | sed "s/'/'\"'\"r'/g"
}

GIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
GIT_COMMIT_HASH=$(git rev-parse HEAD)
GIT_COMMIT_MESSAGE=$(git log -1 --pretty=%s)
Expand All @@ -7,8 +11,8 @@ GIT_COMMIT_FILE="../lib/utils/metadata.dart"

sed --i '1,5d' $GIT_COMMIT_FILE

echo "const String gitBranchName = '$GIT_BRANCH_NAME';" >> $GIT_COMMIT_FILE
echo "const String gitCommitHash = '$GIT_COMMIT_HASH';" >> $GIT_COMMIT_FILE
echo "const String gitCommitMessage = '$GIT_COMMIT_MESSAGE';" >> $GIT_COMMIT_FILE
echo "const String gitCommitDate = '$GIT_COMMIT_DATE';" >> $GIT_COMMIT_FILE
echo "const String gitOriginUrl = '$GIT_ORIGIN_URL';" >> $GIT_COMMIT_FILE
echo "const String gitBranchName = r'$(escape $GIT_BRANCH_NAME)';" >> $GIT_COMMIT_FILE
echo "const String gitCommitHash = r'$GIT_COMMIT_HASH';" >> $GIT_COMMIT_FILE
echo "const String gitCommitMessage = r'$(escape $GIT_COMMIT_MESSAGE)';" >> $GIT_COMMIT_FILE
echo "const String gitCommitDate = r'$GIT_COMMIT_DATE';" >> $GIT_COMMIT_FILE
echo "const String gitOriginUrl = r'$(escape $GIT_ORIGIN_URL)';" >> $GIT_COMMIT_FILE
2 changes: 1 addition & 1 deletion macos/Runner.xcodeproj/project.pbxproj
Expand Up @@ -359,7 +359,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "GIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)\nGIT_COMMIT_HASH=$(git rev-parse HEAD)\nGIT_COMMIT_MESSAGE=$(git log -1 --pretty=%s)\nGIT_COMMIT_DATE=$(git --no-pager log -1 --format=\"%ai\")\nGIT_ORIGIN_URL=$(git config --get remote.origin.url)\nGIT_COMMIT_FILE=\"../lib/utils/metadata.dart\"\n\nsed -i '' '1,5d' $GIT_COMMIT_FILE\necho \"const String gitBranchName = '$GIT_BRANCH_NAME';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitHash = '$GIT_COMMIT_HASH';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitMessage = '$GIT_COMMIT_MESSAGE';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitDate = '$GIT_COMMIT_DATE';\" >> $GIT_COMMIT_FILE\necho \"const String gitOriginUrl = '$GIT_ORIGIN_URL';\" >> $GIT_COMMIT_FILE\n\n\n";
shellScript = "escape () {\n echo $1 | sed \"s/'/'\\\"'\\\"r' / g\"\n}\n\nGIT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)\nGIT_COMMIT_HASH=$(git rev-parse HEAD)\nGIT_COMMIT_MESSAGE=$(git log -1 --pretty=%s)\nGIT_COMMIT_DATE=$(git --no-pager log -1 --format=\"%ai\")\nGIT_ORIGIN_URL=$(git config --get remote.origin.url)\nGIT_COMMIT_FILE=\"../lib/utils/metadata.dart\"\n\nsed -i '' '1,5d' $GIT_COMMIT_FILE\n\necho \"const String gitBranchName = r'$(escape $GIT_BRANCH_NAME)';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitHash = r'$GIT_COMMIT_HASH';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitMessage = r'$(escape $GIT_COMMIT_MESSAGE)';\" >> $GIT_COMMIT_FILE\necho \"const String gitCommitDate = r'$GIT_COMMIT_DATE';\" >> $GIT_COMMIT_FILE\necho \"const String gitOriginUrl = r'$(escape $GIT_ORIGIN_URL)';\" >> $GIT_COMMIT_FILE\n\n\n";
};
96DA24F0296EB70E00545E88 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
14 changes: 9 additions & 5 deletions windows/CreateGitMetadata.ps1
@@ -1,3 +1,7 @@
Function Escape($String) {
Return $String.Replace("'", "'`"'`"r'");
}

$GIT_BRANCH_NAME = git rev-parse --abbrev-ref HEAD
$GIT_COMMIT_HASH = git rev-parse HEAD
$GIT_COMMIT_MESSAGE = git log -1 --pretty=%s
Expand All @@ -7,8 +11,8 @@ $GIT_COMMIT_FILE = "${PSScriptRoot}\..\lib\utils\metadata.dart"

Clear-Content $GIT_COMMIT_FILE -Force

Add-Content $GIT_COMMIT_FILE "const String gitBranchName = '$GIT_BRANCH_NAME';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitHash = '$GIT_COMMIT_HASH';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitMessage = '$GIT_COMMIT_MESSAGE';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitDate = '$GIT_COMMIT_DATE';"
Add-Content $GIT_COMMIT_FILE "const String gitOriginUrl = '$GIT_ORIGIN_URL';"
Add-Content $GIT_COMMIT_FILE "const String gitBranchName = r'$(Escape $GIT_BRANCH_NAME)';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitHash = r'$GIT_COMMIT_HASH';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitMessage = r'$(Escape $GIT_COMMIT_MESSAGE)';"
Add-Content $GIT_COMMIT_FILE "const String gitCommitDate = r'$GIT_COMMIT_DATE';"
Add-Content $GIT_COMMIT_FILE "const String gitOriginUrl = r'$(Escape $GIT_ORIGIN_URL)';"