Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

git config --global --add safe.directory "/github/workspace/$1"

cd $1
export DATA=$(curl $3 | jq --arg APP_NAME "$4" '{"data":map(select(.appName == $APP_NAME))}')

if [[ $2 =~ .*\.json ]]; then
echo -e "$DATA" > $2
# elif [[ $2 =~ .*\.swift ]]; then
# echo -e "// This Source Code Form is subject to the terms of the Mozilla Public\n// License, v. 2.0. If a copy of the MPL was not distributed with this\n// file, You can obtain one at http://mozilla.org/MPL/2.0/\n\nimport Foundation\n\npublic struct FirstRunExperiments {\n public static let value = \"\"\"$DATA\"\"\"\n}" > $2
# elif [[ $2 =~ .*\.kt ]]; then
# if [[ -z $6 ]]; then
# echo "Package is not specified. Package is a required value for the kotlin language."
# exit 1
# fi
# echo -e "// This Source Code Form is subject to the terms of the Mozilla Public\n// License, v. 2.0. If a copy of the MPL was not distributed with this\n// file, You can obtain one at http://mozilla.org/MPL/2.0/\n\npackage $6\n\n/*\n * This is a list of the first-run experiments. It will be passed to Nimbus during startup.\n */\nconst val firstRunExperiments = \"\"\"$DATA\"\"\"" > $2
else
DIR="$1"
FILENAME="$2"
URL="$3"
APP_NAME="$4"
BRANCH="$5"

if [[ ! $FILENAME =~ .*\.json ]]; then
echo "Language of output file is not supported. Please set the output to a JSON file."
exit 1
fi

git config --global --add safe.directory "/github/workspace/$DIR"
pushd "$DIR" || exit 1

curl "$URL" | jq --arg APP_NAME "$APP_NAME" '{"data":map(select(.appName == $APP_NAME))}' > "$FILENAME"

git status
export CHANGED=$(git status -s | wc -l)
export CHANGED_BRANCH=0
CHANGED=$(git status -s | wc -l)
CHANGED_BRANCH=0

git add $2
git add "$FILENAME"
echo "$CHANGED file(s) have been modified"

export REMOTE_BRANCH=$(git ls-remote --head origin $5)
REMOTE_BRANCH=$(git ls-remote --head origin "$BRANCH")
if [[ -z $REMOTE_BRANCH ]];
then
export CHANGED_BRANCH=1
CHANGED_BRANCH=1
echo "Remote branch currently does not exist; outputting that there are changes."
else
export CHANGED_BRANCH=$(git --no-pager diff origin/$5 | grep $2 | wc -l)
if test $CHANGED_BRANCH -ge 1
CHANGED_BRANCH=$(git --no-pager diff "origin/$BRANCH" | grep -c "$FILENAME")
if test "$CHANGED_BRANCH" -ge 1
then
export CHANGED=1
CHANGED=1
echo "Remote branch differs from current changes, it should be updated."
else
echo "Remote branch and current changes are equivalent."
fi
fi

echo "changed=$CHANGED" >> $GITHUB_OUTPUT
echo "changed-branch=$CHANGED_BRANCH" >> $GITHUB_OUTPUT
echo "changed=$CHANGED" >> "$GITHUB_OUTPUT"
echo "changed-branch=$CHANGED_BRANCH" >> "$GITHUB_OUTPUT"

popd 2>/dev/null || exit 0