Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the CI with PR from a fork #4454

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: Install dependencies
run: yarn --immutable

test:
ui-unit-tests:
needs: install
timeout-minutes: 60
strategy:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 }}