Skip to content

Commit

Permalink
🔧 Fix the storybook CI (#4452)
Browse files Browse the repository at this point in the history
* Do not use Vercel CLI

* Temporarily disable the test CI

* Fix shell syntax

* Attempt to fix the branch name

* Fix shell syntax

* Temporarily only run the Vercel URL generation

* Check the CI state

* Fix CI

* Check `github.event.pull_request.head`

* Fix the url generation for forks

* Test push workflows

* Check whether `jq` is available on GH runners

* Fix CI for non fork PRs

* Use `jq` instead of `node` to extract data

* Remove the `branch-names` action

* Restore the full CI

* Rename the jobs

* Improve formatting

* Use GH substitution over shell variables

* Debug waiting step

* Restore full CI again

* Fail when the Vercel URL is wrong

* Fix the hash generation
  • Loading branch information
thesan committed Jun 21, 2023
1 parent a8edd46 commit 06f68ac
Showing 1 changed file with 40 additions and 21 deletions.
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 }}

2 comments on commit 06f68ac

@vercel
Copy link

@vercel vercel bot commented on 06f68ac Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2-storybook – ./

pioneer-2-storybook-git-dev-joystream.vercel.app
pioneer-2-storybook-joystream.vercel.app
pioneer-2-storybook.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 06f68ac Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2-git-dev-joystream.vercel.app
pioneer-2.vercel.app
pioneer-2-joystream.vercel.app

Please sign in to comment.