From e871c7e2c54fb6e82b744578145f791ece4fdb9c Mon Sep 17 00:00:00 2001 From: Daniel Sil Date: Wed, 31 Jan 2024 17:45:14 +0100 Subject: [PATCH] chore: change storybook staging URL --- .github/workflows/storybook.yml | 42 +++++++++++++++---- .../config/deploymentUtils.mts | 29 ------------- packages/orbit-components/package.json | 1 - 3 files changed, 33 insertions(+), 39 deletions(-) delete mode 100644 packages/orbit-components/config/deploymentUtils.mts diff --git a/.github/workflows/storybook.yml b/.github/workflows/storybook.yml index ee09b5265f..36da12e0be 100644 --- a/.github/workflows/storybook.yml +++ b/.github/workflows/storybook.yml @@ -34,8 +34,6 @@ jobs: - name: Build Storybook run: yarn components build:storybook - # TODO: find an alternative to using "if" statements for so many steps - - name: Get BRANCH_URL # do not run on master branch if: github.ref != 'refs/heads/master' @@ -45,16 +43,42 @@ jobs: - name: Get DOMAIN if: github.ref != 'refs/heads/master' - run: echo "DOMAIN=https://orbit-mainframev-${BRANCH_URL}.surge.sh" >> $GITHUB_ENV + run: echo "DOMAIN=https://kiwicom-orbit-${BRANCH_URL}.surge.sh" >> $GITHUB_ENV - name: Deploy to staging if: github.ref != 'refs/heads/master' - # we're adding to the domain name the username of the current owner of SURGE_TOKEN - run: | - yarn components deploy:surge ${DOMAIN} --token ${{ secrets.SURGE_TOKEN }} - yarn components deploy:updateURL --pr=${PR_NUMBER} --lastUrl=${DOMAIN} --token=${{ secrets.OCTO_TOKEN }} --urlName=Storybook - env: - PR_NUMBER: ${{ github.event.number }} + run: yarn components deploy:surge ${DOMAIN} --token ${{ secrets.SURGE_TOKEN }} + + - name: Add comment to PR + if: github.ref != 'refs/heads/master' + uses: actions/github-script@v6 + with: + script: | + const commentBody = `Storybook staging is available at ${process.env.DOMAIN}`; + + const commentsList = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + }); + + const comment = commentsList.data.find((comment) => comment.body.includes(commentBody)); + + if (!comment) { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody, + }) + } else { + github.rest.issues.updateComment({ + comment_id: comment.id, + owner: context.repo.owner, + repo: context.repo.repo, + body: commentBody, + }) + } - name: Deploy to production # run on master branch diff --git a/packages/orbit-components/config/deploymentUtils.mts b/packages/orbit-components/config/deploymentUtils.mts deleted file mode 100644 index 1f453820c4..0000000000 --- a/packages/orbit-components/config/deploymentUtils.mts +++ /dev/null @@ -1,29 +0,0 @@ -import { Octokit } from "@octokit/rest"; -import { argv } from "zx"; - -const repo = "orbit"; - -const parseDescription = (body: string | null, str: string) => { - if (body && body.match(str)) return body; - return (body && body.concat(`\n ${str}`)) || ""; -}; - -(async () => { - const { pr, lastUrl, token, urlName = "LiveUrl" } = argv; - if (!pr) throw new Error("Missing PR number"); - - const octokit = new Octokit({ log: console, auth: token }); - - const { data } = await octokit.pulls.get({ - owner: "kiwicom", - repo, - pull_number: pr, - }); - - await octokit.pulls.update({ - owner: "kiwicom", - repo, - pull_number: pr, - body: parseDescription(data.body, `${urlName}: ${lastUrl}`), - }); -})(); diff --git a/packages/orbit-components/package.json b/packages/orbit-components/package.json index 422e1d5929..b0e4e863fe 100644 --- a/packages/orbit-components/package.json +++ b/packages/orbit-components/package.json @@ -29,7 +29,6 @@ "test-ct": "playwright test -c playwright-ct.config.ts", "deploy:storybook": "yarn storybook-to-ghpages -e ./.out", "deploy:surge": "yarn surge .out/", - "deploy:updateURL": "node --loader ts-node/esm config/deploymentUtils.mts updateLiveURL", "docs-gen": "monstra docs" }, "storybook-deployer": {