Skip to content

Commit

Permalink
Include add_service + tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwcarlson committed Oct 27, 2023
1 parent b83d5fb commit 522a9db
Showing 1 changed file with 121 additions and 22 deletions.
143 changes: 121 additions & 22 deletions .github/workflows/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:

################################################################################################
# A. Setting up tools and authentication to test project/organization.
- name: "[SETUP] 1. Checkout repo"
- name: "[setup] 1. Checkout repo"
run: |
git clone -b $TEST_PROJECT_DEFAULT_BRANCH \
https://github.com/$TEST_PROJECT_REPO.git \
Expand All @@ -59,23 +59,23 @@ jobs:
# uses: actions/checkout@v4
# with:
# ref: ${{ github.event.pull_request.head.sha }}
- name: "[SETUP] 2. Set up Homebrew"
- name: "[setup] 2. Set up Homebrew"
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: "[SETUP] 3. Install Upsun CLI"
- name: "[setup] 3. Install Upsun CLI"
run: |
echo "::notice::Installing Upsun CLI via HomeBrew."
brew install platformsh/tap/upsun-cli
- name: "[SETUP] 4. Verify Upsun CLI installation"
- name: "[setup] 4. Verify Upsun CLI installation"
run: |
echo "::notice::Verifying CLI is installed correctly."
upsun org:info -h
- name: "[SETUP] 5. Verify Upsun CLI authentication"
- name: "[setup] 5. Verify Upsun CLI authentication"
run: |
echo "::notice::Verifying CLI is authenticated correctly."
# upsun auth:api-token-login
upsun org:info -o $TEST_ORG_NAME name
- name: "[SETUP] 6. Authenticate Upsun CLI for pushes"
- name: "[setup] 6. Authenticate Upsun CLI for pushes"
run: |
upsun ssh-cert:load --new -y
touch ~/.ssh/known_hosts
Expand All @@ -85,7 +85,7 @@ jobs:
################################################################################################
# B. Setting up test project.
- name: "[PROJECT] 1. Create a project in the test org, update prod branch title."
- name: "[create_project] 1. Create a project in the test org, update prod branch title."
run: |
echo "::notice::Create a project in the test org."
upsun project:create -o "$TEST_ORG_NAME" \
Expand All @@ -99,15 +99,15 @@ jobs:
upsun environment:info title "Production ($TEST_PROJECT_DEFAULT_BRANCH)" \
-e $TEST_PROJECT_DEFAULT_BRANCH \
-p $TEST_PROJECT_ID
- name: "[PROJECT] 2. Verify local repo and branch."
- name: "[create_project] 2. Verify local repo and branch."
run: |
echo "::notice::Verifying local repo."
ls -a
cd $TEST_PROJECT_LOCALDIR
git config --global user.email "$TEST_USER_EMAIL"
git config --global user.name "$TEST_USER_NAME"
git branch
- name: "[PROJECT] 3. Set remote."
- name: "[create_project] 3. Set remote."
run: |
echo "::notice::Setting remote for the project locally."
TEST_PROJECT_ID=$(upsun project:list -o "$TEST_ORG_NAME" --title "$TEST_PROJECT_TITLE" --pipe)
Expand All @@ -118,22 +118,22 @@ jobs:
################################################################################################
# C. First deploy.
- name: "[FIRST DEPLOY] 1. Deploy the demo application to Upsun."
- name: "[first_deploy] 1. Deploy the demo application to Upsun."
run: |
echo "::notice::First push to project."
cd $TEST_PROJECT_LOCALDIR
git branch
# Push through Git, not the CLI, so the exit doesn't break the workflow.
git push --force upsun $TEST_PROJECT_DEFAULT_BRANCH
# upsun push -f -y
- name: "[FIRST DEPLOY] 2. Verify first failure."
- name: "[first_deploy] 2. Test: Verify first failure."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list --type push -e $TEST_PROJECT_DEFAULT_BRANCH --no-header --columns=id --format plain)
ACTIVITY_STATE=$(upsun activity:get $INIT_ACTIVITY_ID -P state)
echo "::notice::Attempting to retrieve first push activity state. Current state is: ${INIT_ACTIVITY_STATE}"
if [ "${INIT_ACTIVITY_STATE}" = "complete" ]; then
ACTIVITY_STATE=$(upsun activity:get $ACTIVITY_ID -P state)
echo "::notice::Attempting to retrieve first push activity state. Current state is: ${ACTIVITY_STATE}"
if [ "${ACTIVITY_STATE}" = "complete" ]; then
echo "::notice::Activity is complete."
fi
Expand All @@ -145,11 +145,11 @@ jobs:
else
echo "::notice::First push failed as expected."
fi
- name: "[FIRST DEPLOY] 3. Set initial resources."
- name: "[first_deploy] 3. Set initial resources."
run: |
cd $TEST_PROJECT_LOCALDIR
upsun resources:set --size '*:0.1' -y
- name: "[FIRST DEPLOY] 4. Test: verify activity completed."
- name: "[first_deploy] 4. Test: verify activity completed."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list -e $TEST_PROJECT_DEFAULT_BRANCH --type environment.resources.update --no-header --columns=id --format plain)
Expand All @@ -158,18 +158,18 @@ jobs:
if [ "${ACTIVITY_STATE}" = "complete" ]; then
echo "::notice::Activity is complete."
fi
- name: "[FIRST DEPLOY] 5. Test: verify activity has succeeded."
- name: "[first_deploy] 5. Test: verify activity has succeeded."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list -e $TEST_PROJECT_DEFAULT_BRANCH --type environment.resources.update --no-header --columns=id --format plain)
ACTIVITY_RESULT=$(upsun activity:get $ACTIVITY_RESOURCES_INIT_PROD_ID -P result)
ACTIVITY_RESULT=$(upsun activity:get $ACTIVITY_ID -P result)
if [ "$ACTIVITY_RESULT" != "success" ]; then
echo "::notice::Resources set on production has failed. Exiting."
exit 1
else
echo "::notice::Resources set on production successful."
fi
- name: "[FIRST DEPLOY] 6. Test: production URLS & endpoint data."
- name: "[first_deploy] 6. Test: production URLS & endpoint data."
run: |
cd $TEST_PROJECT_LOCALDIR
TEST_PROJECT_PROD_URL_FRONTEND=$(upsun url --primary --pipe)
Expand Down Expand Up @@ -210,11 +210,15 @@ jobs:
################################################################################################
# D. Create staging environment.
- name: "[BRANCH] 1. Create preview environment"
- name: "[branch] 1. Create preview environment"
run: |
cd $TEST_PROJECT_LOCALDIR
upsun branch $TEST_PROJECT_STAGING_ENV --type staging
- name: "[BRANCH] 2. Test: Verify branch activity success."
TEST_PROJECT_ID=$(upsun project:list -o "$TEST_ORG_NAME" --title "$TEST_PROJECT_TITLE" --pipe)
upsun environment:info title "Staging ($TEST_PROJECT_STAGING_ENV)" \
-e $TEST_PROJECT_STAGING_ENV \
-p $TEST_PROJECT_ID
- name: "[branch] 2. Test: Verify branch activity success."
run: |
cd $TEST_PROJECT_LOCALDIR
Expand All @@ -234,7 +238,7 @@ jobs:
else
echo "::notice::Branching successful."
fi
- name: "[BRANCH] 3. Test: staging URLS & endpoint data."
- name: "[branch] 3. Test: staging URLS & endpoint data."
run: |
cd $TEST_PROJECT_LOCALDIR
Expand Down Expand Up @@ -276,6 +280,101 @@ jobs:
################################################################################################
# E. Add a service.
- name: "[add_service] 1. Uncomment service configuration block. Commit & push new service."
run: |
cd $TEST_PROJECT_LOCALDIR
./utils/uncomment.sh .upsun/config.yaml add_service
git commit -am "Create a redis service."
# Push through Git, not the CLI, so the exit doesn't break the workflow.
git push --force upsun $TEST_PROJECT_STAGING_ENV
# upsun push -f -y
- name: "[add_service] 2. Test: Verify first failure."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list --type push -e $TEST_PROJECT_STAGING_ENV --no-header --columns=id --format plain)
ACTIVITY_STATE=$(upsun activity:get $ACTIVITY_ID -P state)
echo "::notice::Attempting to retrieve new service push activity state. Current state is: ${ACTIVITY_STATE}"
if [ "${ACTIVITY_STATE}" = "complete" ]; then
echo "::notice::Activity is complete."
fi
ACTIVITY_RESULT=$(upsun activity:get $ACTIVITY_ID -P result)
echo "::notice::Result retrieved: ${ACTIVITY_RESULT}"
if [ "$ACTIVITY_RESULT" != "failure" ]; then
echo "::notice::First push did not fail as expected. Exiting."
exit 1
else
echo "::notice::First push failed as expected."
fi
- name: "[add_service] 3. Set Redis' resources."
run: |
cd $TEST_PROJECT_LOCALDIR
upsun resources:set --size redis_persistent:0.1 --disk redis_persistent:512
- name: "[add_service] 4. Test: verify activity completed."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list -e $TEST_PROJECT_STAGING_ENV --type environment.resources.update --no-header --columns=id --format plain)
ACTIVITY_STATE=$(upsun activity:get $ACTIVITY_ID -P state)
echo "::notice::Attempting to retrieve staging resources.set activity state. Current state is: ${ACTIVITY_STATE}"
if [ "${ACTIVITY_STATE}" = "complete" ]; then
echo "::notice::Activity is complete."
fi
- name: "[add_service] 5. Test: verify activity has succeeded."
run: |
cd $TEST_PROJECT_LOCALDIR
ACTIVITY_ID=$(upsun activity:list -e $TEST_PROJECT_STAGING_ENV --type environment.resources.update --no-header --columns=id --format plain)
ACTIVITY_RESULT=$(upsun activity:get $ACTIVITY_ID -P result)
if [ "$ACTIVITY_RESULT" != "success" ]; then
echo "::notice::Resources set on staging has failed. Exiting."
exit 1
else
echo "::notice::Resources set on staging successful."
fi
- name: "[add_service] 6. Test: staging URLS & endpoint data."
run: |
cd $TEST_PROJECT_LOCALDIR
TEST_PROJECT_STAGING_URL_FRONTEND=$(upsun url --primary --pipe)
STATUS=$(curl --silent --head $TEST_PROJECT_STAGING_URL_FRONTEND | awk '/^HTTP/{print $2}')
if [ "$STATUS" != "200" ]; then
echo "::notice::Frontend deployment did not succeed. Exiting."
exit 1
else
echo "::notice::Frontend deployment successful."
fi
TEST_PROJECT_STAGING_URL_BACKEND=$TEST_PROJECT_STAGING_URL_FRONTEND$TEST_PROJECT_BACKEND_PATH
STATUS=$(curl --silent --head $TEST_PROJECT_STAGING_URL_BACKEND | awk '/^HTTP/{print $2}')
if [ "$STATUS" != "200" ]; then
echo "::notice::Backend deployment did not succeed. Exiting."
exit 1
else
echo "::notice::Backend deployment successful."
fi
EXPECTED_STATUS="redis"
STATUS_DATA=$(curl -s $TEST_PROJECT_STAGING_URL_BACKEND | jq -r '.session_storage')
if [ "$STATUS_DATA" != "$EXPECTED_STATUS" ]; then
echo "::notice::Backend data session_storage is not the expected value ($EXPECTED_STATUS/$STATUS_DATA). Exiting."
exit 1
else
echo "::notice::Backend data session_storage as expected."
fi
EXPECTED_STATUS="staging"
STATUS_DATA=$(curl -s $TEST_PROJECT_STAGING_URL_BACKEND | jq -r '.type')
if [ "$STATUS_DATA" != "$EXPECTED_STATUS" ]; then
echo "::notice::Backend data environment type is not the expected value ($EXPECTED_STATUS/$STATUS_DATA). Exiting."
exit 1
else
echo "::notice::Backend data environment type as expected."
fi
################################################################################################
# F. Promote revision to production.
Expand Down

0 comments on commit 522a9db

Please sign in to comment.