Skip to content

should deploy to EMEA #16

should deploy to EMEA

should deploy to EMEA #16

Workflow file for this run

# Copyright 2020 Google LLC
#
# 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.
name: "Continuous Integration - Pull Request"
on:
pull_request:
branches:
- main
jobs:
code-tests:
runs-on: [self-hosted, runners-v2]
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: License Check
run: |
set -x
if [[ -d ".git" ]]; then
rm -rf .git
fi
git init
git add --all
git -c user.name="CI Bot" -c user.email="<>" commit -m "initial state"
addlicense ./
if [[ -n $(git status -s) ]]; then
exit 1
fi
- name: Java Checkstyle
timeout-minutes: 20
run: |
source /etc/profile.d/java.sh
mvn checkstyle:check
- name: Python Checkstyle
timeout-minutes: 20
run: |
pylint --rcfile=./.pylintrc ./src/*/*.py
- name: Java Unit Tests
timeout-minutes: 20
run: |
source /etc/profile.d/java.sh
mvn test
- name: Java Code Coverage
timeout-minutes: 20
run: |
source /etc/profile.d/java.sh
for SERVICE in "balancereader" "ledgerwriter" "transactionhistory"; do
echo "checking $SERVICE..."
# save current working dir to memory and cd to src/$SERVICE
pushd src/$SERVICE
mvn jacoco:report
echo "Coverage for $SERVICE:"
awk -F, \
'{ instructions += $4 + $5; covered += $5 } END \
{ print covered, "/", instructions, " instructions covered"; \
print int(100*covered/instructions), "% covered" }' \
target/site/jacoco/jacoco.csv
# return to previously saved path
popd
done
- name: Python Unit Tests
timeout-minutes: 20
run: |
set -x
for SERVICE in "contacts" "userservice"; do
echo "testing $SERVICE..."
# save current working dir to memory and cd to src/$SERVICE
pushd src/$SERVICE
python3 -m venv $HOME/venv-$SERVICE
source $HOME/venv-$SERVICE/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python -m pytest -v -p no:warnings
deactivate
# return to previously saved path
popd
done
- name: Python Code Coverage
timeout-minutes: 20
run: |
for SERVICE in "contacts" "userservice"; do
echo "testing $SERVICE..."
# save current working dir to memory and cd to src/$SERVICE
pushd src/$SERVICE
python3 -m venv $HOME/venv-$SERVICE
source $HOME/venv-$SERVICE/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
python -m pytest --cov=./ tests/
deactivate
# return to previously saved path
popd
done
deployment-tests:
runs-on: [self-hosted, runners-v2]
needs: code-tests
strategy:
matrix:
profile: ["local-code"]
fail-fast: true
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Build + Deploy PR images to GKE
timeout-minutes: 20
run: |
source /etc/profile.d/java.sh
NAMESPACE="pr${PR_NUMBER}"
echo "::set-env name=NAMESPACE::$NAMESPACE"
gcloud container clusters get-credentials $PR_CLUSTER --zone $ZONE --project $PROJECT_ID
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Namespace
metadata:
name: $NAMESPACE
EOF
echo Deploying application
skaffold config set --global local-cluster false
skaffold run --default-repo=gcr.io/$PROJECT_ID/refs/$PR_NUMBER --tag=$GITHUB_SHA --namespace=$NAMESPACE
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
PROJECT_ID: "bank-of-anthos-ci"
PR_CLUSTER: "bank-of-anthos-prs"
ZONE: "us-central1-c"
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Wait For Pods
timeout-minutes: 20
run: |
set -x
kubectl config set-context --current --namespace=$NAMESPACE
kubectl wait --for=condition=available --timeout=300s deployment/frontend
kubectl wait --for=condition=available --timeout=300s deployment/contacts
kubectl wait --for=condition=available --timeout=300s deployment/userservice
kubectl wait --for=condition=available --timeout=300s deployment/ledgerwriter
kubectl wait --for=condition=available --timeout=300s deployment/transactionhistory
kubectl wait --for=condition=available --timeout=300s deployment/balancereader
kubectl wait --for=condition=available --timeout=300s deployment/loadgenerator
kubectl wait --for=condition=ready --timeout=300s pod/accounts-db-0
kubectl wait --for=condition=ready --timeout=300s pod/ledger-db-0
- name: Query EXTERNAL_IP for staging
timeout-minutes: 5
run: |
set -x
NAMESPACE="pr${PR_NUMBER}"
get_externalIP() {
kubectl get service frontend --namespace $NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
}
until [[ -n "$(get_externalIP)" ]]; do
echo "Querying for external IP for frontend on namespace: $NAMESPACE{}"
sleep 3
done
EXTERNAL_IP=$(get_externalIP)
echo "::set-env name=EXTERNAL_IP::$EXTERNAL_IP"
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
PR_NUMBER: ${{ github.event.pull_request.number }}
- name: Comment EXTERNAL_IP
timeout-minutes: 5
env:
COMMENTS_URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-X POST \
$COMMENTS_URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data '{ "body": "🚀 PR staged at '"http://${EXTERNAL_IP}"'"}'
sleep 60
- name: Run UI tests (Cypress)
run: |
docker run -t -v $PWD/.github/workflows/ui-tests:/e2e -w /e2e -e CYPRESS_baseUrl=http://$EXTERNAL_IP -u node cypress/included:5.0.0
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: ${{ github.workspace }}/.github/workflows/ui-tests/cypress/screenshots