Skip to content

Merge pull request #59 from modern-sapien/main #28

Merge pull request #59 from modern-sapien/main

Merge pull request #59 from modern-sapien/main #28

name: Checkly Fail Safe
on:
pull_request:
types:
- closed
env:
CHECKLY_API_KEY: ${{ secrets.CHECKLY_API_KEY }}
CHECKLY_ACCOUNT_ID: ${{ secrets.CHECKLY_ACCOUNT_ID }}
jobs:
test-e2e:
if: github.event.pull_request.merged == true
name: Merge Test Deploy
runs-on: ubuntu-latest
steps:
- name: Set Environment Variables
run: |
echo "GitHub Ref: ${{ github.ref }}"
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
echo "Setting Environment for production"
echo "NEXT_PUBLIC_NODE_PRODUCTION=production" >> $GITHUB_ENV
echo "NEXT_PUBLIC_ENVIRONMENT_URL=https://next-danube-webshop.vercel.app/" >> $GITHUB_ENV
elif [ "${{ github.ref }}" = "refs/heads/staging" ]; then
echo "Setting Environment for staging"
echo "NEXT_PUBLIC_NODE_STAGING=staging" >> $GITHUB_ENV
echo "NEXT_PUBLIC_ENVIRONMENT_URL=https://next-danube-webshop-staging.vercel.app/" >> $GITHUB_ENV
fi
- name: Print Environment Variables
run: |
echo "NEXT_PUBLIC_ENVIRONMENT_URL=${{ env.NEXT_PUBLIC_ENVIRONMENT_URL }}"
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Restore or cache node_modules
id: cache-node-modules
uses: actions/cache@v3
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: cd next-webstore && npm ci
- name: Run checks
id: run-checks
working-directory: next-webstore
run: NEXT_PUBLIC_NODE_ENV=${{ env.NEXT_PUBLIC_NODE_ENV }} npx checkly test -e NEXT_PUBLIC_ENVIRONMENT_URL=${{ env.NEXT_PUBLIC_ENVIRONMENT_URL }} --reporter=github --record
- name: Deploy checks
id: deploy-checks
if: steps.run-checks.outcome == 'success' && contains('main staging', github.ref)
working-directory: next-webstore
run: NEXT_PUBLIC_NODE_ENV=${{ env.NEXT_PUBLIC_NODE_ENV }} npx checkly deploy --force
- name: Rollback
if: steps.run-checks.outcome != 'success' && contains('main staging', github.ref)
run: |
git revert HEAD