Skip to content

Commit

Permalink
Extract mergeToMain.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
patchwork01 committed Nov 24, 2023
1 parent 673afeb commit 82d483c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 26 deletions.
55 changes: 55 additions & 0 deletions scripts/test/nightly/mergeToMain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@


#
# Copyright 2022-2023 Crown Copyright
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -e
unset CDPATH

THIS_DIR=$(cd "$(dirname "$0")" && pwd)
SCRIPTS_DIR=$(cd "$THIS_DIR" && cd ../.. && pwd)
MAVEN_DIR=$(cd "$SCRIPTS_DIR" && cd ../java && pwd)

if [ "$#" -ne 4 ]; then
echo "Usage: $0 <repo-path> <private-key-pem-file> <app-id> <installation-id>"
exit 1
fi

REPO_PATH=$1
PRIVATE_KEY=$2
APP_ID=$3
INSTALLATION_ID=$4

pushd "$MAVEN_DIR"
echo "Compiling build module..."
mvn compile -Pquick -q -pl build -am

pushd build
echo "Generating access token..."
ACCESS_TOKEN_FILE=$(mktemp)
mvn exec:java -q \
-Dexec.mainClass="sleeper.build.github.app.GenerateGitHubAppInstallationAccessToken" \
-Dexec.args="$PRIVATE_KEY $APP_ID $INSTALLATION_ID $ACCESS_TOKEN_FILE"
popd

ACCESS_TOKEN=$(<"$ACCESS_TOKEN_FILE")
git remote set-url origin "https://x-access-token:$ACCESS_TOKEN@github.com/$REPO_PATH.git"
git switch --discard-changes -C main origin/main
git pull
git merge develop
git push

popd
31 changes: 5 additions & 26 deletions scripts/test/nightly/updateAndRunTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ set -e
unset CDPATH

THIS_DIR=$(cd "$(dirname "$0")" && pwd)
SCRIPTS_DIR=$(cd "$THIS_DIR" && cd ../.. && pwd)
MAVEN_DIR=$(cd "$SCRIPTS_DIR" && cd ../java && pwd)

if [ "$#" -ne 8 ]; then
echo "Usage: $0 <vpc> <subnet> <results-bucket> <test-type> <repo-path> <private-key-pem-file> <app-id> <installation-id>"
Expand All @@ -44,32 +42,13 @@ git remote set-url origin "https://github.com/$REPO_PATH.git"
git fetch
git switch --discard-changes -C develop origin/develop

popd

set +e
"$THIS_DIR/runTests.sh" "$VPC" "$SUBNETS" "$RESULTS_BUCKET" "$TEST_TYPE"
./runTests.sh "$VPC" "$SUBNETS" "$RESULTS_BUCKET" "$TEST_TYPE"
EXIT_CODE=$?
set -e

if [ $EXIT_CODE -eq 0 ]; then

pushd "$MAVEN_DIR"
echo "Compiling build module..."
mvn compile -Pquick -q -pl build -am

pushd build
echo "Generating access token..."
ACCESS_TOKEN_FILE=$(mktemp)
mvn exec:java -q \
-Dexec.mainClass="sleeper.build.github.app.GenerateGitHubAppInstallationAccessToken" \
-Dexec.args="$PRIVATE_KEY $APP_ID $INSTALLATION_ID $ACCESS_TOKEN_FILE"
popd

popd

ACCESS_TOKEN=$(<"$ACCESS_TOKEN_FILE")
git remote set-url origin "https://x-access-token:$ACCESS_TOKEN@github.com/$REPO_PATH.git"
git switch --discard-changes -C main origin/main
git pull
git merge develop
git push
./mergeToMain.sh "$REPO_PATH" "$PRIVATE_KEY" "$APP_ID" "$INSTALLATION_ID"
fi

popd

0 comments on commit 82d483c

Please sign in to comment.