Build out testing workflow #37
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upsun Demo CI | |
on: | |
pull_request: | |
branches: | |
- main | |
# on: | |
# pull_request_target: | |
# branches: [main] | |
# types: [labeled,opened,reopened,synchronize] | |
# label: | |
# types: [created, deleted, edited] | |
env: | |
UPSUN_CLI_NO_INTERACTION: 1 | |
UPSUN_CLI_TOKEN: ${{secrets.DEVREL_USER_UPSUN_TOKEN}} | |
TEST_ORG_NAME: demo-test-org | |
TEST_PROJECT_TITLE: "Demo Test Run (pr-${{ github.ref_name }})" | |
TEST_USER_EMAIL: "devrel@internal.platform.sh" | |
TEST_USER_NAME: "DevRel Team Bot" | |
TEST_PROJECT_REGION: "ca-1" | |
TEST_PROJECT_REGION_SUFFIX: "platform.sh" | |
TEST_PROJECT_REPO: "platformsh/demo-project" | |
TEST_PROJECT_LOCALDIR: "upsun-demo" | |
TEST_PROJECT_DEFAULT_BRANCH: ${{ github.event.pull_request.head.ref }} | |
TEST_PROJECT_STAGING_ENV: ${{ github.event.pull_request.head.ref }}-staging | |
TEST_PROJECT_BACKEND_PATH: "api/v1/environment" | |
jobs: | |
# deactivate_forked_environment: | |
# runs-on: ubuntu-latest | |
# if: >- | |
# github.event.pull_request.head.repo.id != 686099066 && | |
# contains(github.event.pull_request.labels.*.name, 'demo-runthrough') | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
################################################################################################ | |
# A. Setting up tools and authentication to test project/organization. | |
- name: "[SETUP] 1. Checkout repo" | |
run: | | |
git clone -b $TEST_PROJECT_DEFAULT_BRANCH \ | |
https://github.com/$TEST_PROJECT_REPO.git \ | |
$TEST_PROJECT_LOCALDIR \ | |
&& cd $TEST_PROJECT_LOCALDIR | |
# uses: actions/checkout@v4 | |
# with: | |
# ref: ${{ github.event.pull_request.head.sha }} | |
- name: "[SETUP] 2. Set up Homebrew" | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- 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" | |
run: | | |
echo "::notice::Verifying CLI is installed correctly." | |
upsun org:info -h | |
- 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" | |
# run: | | |
# upsun ssh-cert:load --new -y | |
# touch ~/.ssh/known_hosts | |
# chmod 644 ~/.ssh/known_hosts | |
# ssh-keyscan ssh.$TEST_PROJECT_REGION.platform.sh -v >> ~/.ssh/known_hosts | |
# ssh-keyscan git.$TEST_PROJECT_REGION.platform.sh -v >> ~/.ssh/known_hosts | |
################################################################################################ | |
# B. Setting up test project. | |
- name: "[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" \ | |
--title "$TEST_PROJECT_TITLE" \ | |
--region "$TEST_PROJECT_REGION.$TEST_PROJECT_REGION_SUFFIX" \ | |
--default-branch $TEST_PROJECT_DEFAULT_BRANCH \ | |
--no-set-remote \ | |
-y | |
TEST_PROJECT_ID=$(upsun project:list -o "$TEST_ORG_NAME" --title "$TEST_PROJECT_TITLE" --pipe) | |
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." | |
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." | |
run: | | |
echo "::notice::Setting remote for the project locally." | |
TEST_PROJECT_ID=$(upsun project:list -o "$TEST_ORG_NAME" --title "$TEST_PROJECT_TITLE" --pipe) | |
cd $TEST_PROJECT_LOCALDIR | |
upsun project:set-remote $TEST_PROJECT_ID | |
git remote remove origin | |
git remote -v | |
- name: "[PROJECT] 4. Deploy the demo application to Upsun." | |
run: | | |
echo "::notice::First push to project." | |
cd $TEST_PROJECT_LOCALDIR | |
git branch | |
# git push --force upsun $TEST_PROJECT_DEFAULT_BRANCH | |
upsun push -f -y | |
################################################################################################ | |
# C. First deploy. | |
################################################################################################ | |
# D. Add a service. | |
################################################################################################ | |
# E. Promote revision to production. | |
################################################################################################ | |
# F. Cleanup. | |
- name: "[CLEANUP] 1. Delete project." | |
run: | | |
sleep 30 | |
echo "::notice::Cleaning up after successful run." | |
echo "::notice::Deleting project: ${TEST_PROJECT_ID}" | |
upsun project:delete -p $TEST_PROJECT_ID -y |