diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0a4f960ef9..bd2384af15 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,7 +34,7 @@ jobs: name: Install dependencies run: yarn --immutable - test: + ui-unit-tests: needs: install timeout-minutes: 60 strategy: @@ -72,7 +72,7 @@ jobs: run: node --max_old_space_size=7000 --expose-gc $(yarn bin jest) --logHeapUsage --silent working-directory: packages/ui - storybook-test: + interaction-tests: needs: install timeout-minutes: 60 strategy: @@ -103,33 +103,52 @@ jobs: - name: Install Playwright run: npx playwright install --with-deps - - name: Install Vercel CLI - run: npm install --global vercel@latest - - name: Get the Storybook preview deployment url run: | - URL=$( \ - vercel list \ - --meta githubCommitSha=$COMMIT_SHA \ - --token=${{ secrets.VERCEL_STORYBOOK_TOKEN }} \ - 2>&1 | tail -n 2 | head -n 1 | awk '{print $2}' \ - ) - echo "VERCEL_DEPLOYMENT_URL=$URL" >> "$GITHUB_ENV" + if [ "$PREFIX" == 'git-fork' ]; then + BRANCH=$(echo -n '${{ env.LABEL }}' | sed 's/:/-/') + else + BRANCH=$(echo -n '${{ env.LABEL }}' | cut -d ':' -f2-) + fi + + URL_BRANCH=$(echo -n "$BRANCH" | tr -d '#' | tr -c '[:alnum:]' '-' | tr '[:upper:]' '[:lower:]') + SUBDOMAIN="${{ env.PROJECT }}-${{ env.PREFIX }}-$URL_BRANCH-joystream" + + if [ ${#SUBDOMAIN} -gt 63 ]; then + HASH=$(echo -n "${{ env.PREFIX }}-${BRANCH}${{ env.PROJECT }}" | sha256sum | head -c 6) + SUBDOMAIN="$(echo -n "$SUBDOMAIN" | head -c 46)-$HASH-joystream" + fi + + echo "VERCEL_DEPLOYMENT_URL=$SUBDOMAIN.vercel.app" >> "$GITHUB_ENV" env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_STORYBOOK_PROJECT_ID }} - COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} + PROJECT: pioneer-2-storybook + PREFIX: ${{ github.event.pull_request.head.repo.fork && 'git-fork' || 'git' }} + LABEL: ${{ github.event.pull_request.head.label || github.ref_name }} - name: Wait for the deployment to complete run: | - vercel inspect "${{ env.VERCEL_DEPLOYMENT_URL }}" \ - --wait --timeout 10m \ - --token=${{ secrets.VERCEL_STORYBOOK_TOKEN }} + while true; do + RES=$(curl -L 'https://api.vercel.com/v13/deployments/${{ env.VERCEL_DEPLOYMENT_URL }}') + STATUS=$(echo -n "$RES" | jq -r '.status') + SHA=$(echo -n "$RES" | jq -r '.meta.githubCommitSha') + + + if [ "$SHA" == 'null' ] || [ "$STATUS" == 'null' ]; then + echo -e "\nError the JSON response is missing expected fields:\n\n$RES\n" >&2 + exit 5 + fi + + if [ "$SHA" == '${{ env.COMMIT_SHA }}' ] && [ "$STATUS" == 'READY' ]; then + exit 0 + fi + + echo -e '\nWait for the Storybook deployment...\n\n' + sleep 20 + done env: - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_STORYBOOK_PROJECT_ID }} + COMMIT_SHA: ${{ github.event.pull_request.head.sha || github.sha }} - name: Run Storybook tests run: yarn workspace @joystream/pioneer test-storybook env: - TARGET_URL: ${{ env.VERCEL_DEPLOYMENT_URL }} + TARGET_URL: https://${{ env.VERCEL_DEPLOYMENT_URL }}