Skip to content

Commit

Permalink
feat: deploy storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
asvishnyakov committed Oct 4, 2023
1 parent 1f25377 commit 2e59247
Show file tree
Hide file tree
Showing 11 changed files with 420 additions and 2,293 deletions.
105 changes: 53 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# v1.0.0.vst
name: VST Theme CI
# v1.1.0
name: Theme CI

on:
workflow_dispatch:
push:
Expand All @@ -25,15 +26,21 @@ on:

jobs:
ci:
if: ${{ github.actor != 'dependabot[bot]' &&
(github.event.pull_request.head.repo.full_name == github.repository ||
github.event.pull_request.head.repo.full_name == '') }} # Check that PR not from forked repo and not from Dependabot
runs-on: ubuntu-latest
env:
FORCE_COLOR: true
CLOUD_INSTANCE_BASE_URL: ${{secrets.CLOUD_INSTANCE_BASE_URL}}
CLIENT_ID: ${{secrets.CLIENT_ID}}
CLIENT_SECRET: ${{secrets.CLIENT_SECRET}}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
BLOB_SAS: ${{ secrets.BLOB_TOKEN }}
VERSION_SUFFIX: ""
VERSION_SUFFIX: ''
REPOSITORY_OWNER: ''
REPOSITORY_NAME: ''
BUILD_STATE: 'failed'
RELEASE_STATUS: 'false'
outputs:
Expand All @@ -42,6 +49,11 @@ jobs:

steps:

- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Set RELEASE_STATUS
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}
run: |
Expand All @@ -51,86 +63,79 @@ jobs:
with:
fetch-depth: 0

- name: Install Node.js 18
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Get Image Version
uses: VirtoCommerce/vc-github-actions/get-image-version@master
id: image

- name: Set release variables
- name: Get changelog
id: changelog
uses: VirtoCommerce/vc-github-actions/changelog-generator@master

- name: Set release VERSION_SUFFIX
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.suffix }}" >> $GITHUB_ENV
- name: Set release-alpha variables
- name: Set release-alpha VERSION_SUFFIX
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.fullSuffix }}" >> $GITHUB_ENV
- name: Set PR variables
- name: Set PR VERSION_SUFFIX
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.suffix }}-${{ steps.image.outputs.SHA }}" >> $GITHUB_ENV
- name: Get changelog
id: changelog
uses: VirtoCommerce/vc-github-actions/changelog-generator@master

- name: Build
id: build
uses: VirtoCommerce/vc-github-actions/build-vue-theme@master
with:
versionSuffix: ${{ env.VERSION_SUFFIX }}
- name: Install dependencies
run: |
yarn install
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false

- name: Publish
- name: Build
run: |
yarn build
- name: BUILD_STATE::successful
if: success()
run: echo "BUILD_STATE=successful" >> $GITHUB_ENV

- name: Packaging
run: |
yarn compress ${{ github.event.repository.name }}-${{ steps.image.outputs.prefix }}-${{ env.VERSION_SUFFIX }}
- name: Publish to Blob
if: ${{ github.ref == 'refs/heads/demo' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')}}
id: publish
uses: VirtoCommerce/vc-github-actions/publish-theme@master
id: blobRelease
uses: VirtoCommerce/vc-github-actions/publish-blob-release@master
with:
artifactPath: ${{ steps.build.outputs.artifactPath }}
artifactName: ${{ steps.build.outputs.artifactName }}
blobSAS: ${{ secrets.BLOB_TOKEN }}
blobUrl: ${{ vars.BLOB_URL }}

- name: Add link to PR
if: ${{ github.event_name == 'pull_request' }}
uses: VirtoCommerce/vc-github-actions/publish-artifact-link@master
with:
artifactUrl: ${{ steps.publish.outputs.blobUrl }}
artifactUrl: ${{ steps.blobRelease.outputs.packageUrl }}
repoOrg: ${{ github.repository_owner }}
downloadComment: 'Artifact URL:'

- name: Create Release
- name: Publish Github Release
if: ${{ github.ref == 'refs/heads/master' }}
id: create_release
uses: actions/create-release@v1
id: githubRelease
with:
tag_name: ${{ steps.image.outputs.prefix }}
release_name: ${{ steps.image.outputs.prefix }}
draft: false
prerelease: false
body: ${{ steps.changelog.outputs.changelog }}
changelog: ${{ steps.changelog.outputs.changelog }}
organization: ${{ github.repository_owner }}
uses: VirtoCommerce/vc-github-actions/publish-github-release@master

- name: Upload Release Asset
if: ${{ github.ref == 'refs/heads/master' }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ steps.build.outputs.artifactPath }}
asset_name: ${{ steps.build.outputs.artifactName }}
asset_content_type: application/zip

- name: Set download artifactUrl
- name: Set artifactUrl value
id: artifactUrl
run: |
if [ '${{ github.ref }}' = 'refs/heads/master' ]; then
echo ::set-output name=download_url:: ${{ steps.upload-release-asset.outputs.browser_download_url }}
echo "download_url=${{ steps.githubRelease.outputs.downloadUrl }}" >> $GITHUB_OUTPUT
else
echo ::set-output name=download_url::${{ steps.publish.outputs.blobUrl }}
echo "download_url=${{ steps.blobRelease.outputs.packageUrl }}" >> $GITHUB_OUTPUT
fi;
- name: Parse Jira Keys from All Commits
uses: VirtoCommerce/vc-github-actions/get-jira-keys@master
if: always()
Expand All @@ -140,10 +145,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: BUILD_STATE::successful
if: success()
run: echo "BUILD_STATE=successful" >> $GITHUB_ENV

- name: Push Build Info to Jira
if: ${{ env.CLOUD_INSTANCE_BASE_URL != 0 && env.CLIENT_ID != 0 && env.CLIENT_SECRET != 0 && steps.jira_keys.outputs.jira-keys != '' && always() }}
id: push_build_info_to_jira
Expand Down
198 changes: 198 additions & 0 deletions .github/workflows/storybook-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# v1.0.1
name: Storybook CI

on:
workflow_dispatch:
push:
branches:
[master, dev, demo]
paths-ignore:
- '.github/**'
- 'docs/**'
- 'build/**'
- 'README.md'
- 'LICENSE'
- '**/argoDeploy.json'
pull_request:
branches:
[master, dev, demo]
paths-ignore:
- '.github/**'
- 'docs/**'
- 'build/**'
- 'README.md'
- 'LICENSE'
- '**/argoDeploy.json'

jobs:
ci:
if: ${{ github.actor != 'dependabot[bot]' &&
(github.event.pull_request.head.repo.full_name == github.repository ||
github.event.pull_request.head.repo.full_name == '') }} # Check that PR not from forked repo and not from Dependabot
runs-on: ubuntu-latest
env:
FORCE_COLOR: true
CLOUD_INSTANCE_BASE_URL: ${{secrets.CLOUD_INSTANCE_BASE_URL}}
CLIENT_ID: ${{secrets.CLIENT_ID}}
CLIENT_SECRET: ${{secrets.CLIENT_SECRET}}
SONAR_TOKEN: ${{secrets.SONAR_TOKEN}}
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
BLOB_SAS: ${{ secrets.BLOB_TOKEN }}
VERSION_SUFFIX: ''
BUILD_STATE: 'failed'
RELEASE_STATUS: 'false'
REPOSITORY_OWNER: ''
REPOSITORY_NAME: ''
DOCKER_URL: ''
DOCKER_REPOSITORY: 'ghcr.io'
DOCKER_IMAGE: 'vc-theme-b2b-vue-storybook'
DOCKER_TAG: 'dev-linux-latest'
outputs:
artifactUrl: '${{ steps.artifactUrl.outputs.DOCKER_URL }}'
jira-keys: ${{ steps.jira_keys.outputs.jira-keys }}
version: ${{ steps.image.outputs.shortVersion }}
tag: ${{ env.DOCKER_TAG }}

steps:

- name: Set up Node 18
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Set RELEASE_STATUS
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}
run: |
echo "RELEASE_STATUS=true" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get Image Version
uses: VirtoCommerce/vc-github-actions/get-image-version@master
id: image

- name: Set release VERSION_SUFFIX
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.suffix }}" >> $GITHUB_ENV
- name: Set release-alpha VERSION_SUFFIX
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.fullSuffix }}" >> $GITHUB_ENV
- name: Set PR VERSION_SUFFIX
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "VERSION_SUFFIX=${{ steps.image.outputs.suffix }}-${{ steps.image.outputs.SHA }}" >> $GITHUB_ENV
- name: Set DOCKER_TAG variable
run: |
if [ '${{ github.ref }}' = 'refs/heads/master' ]; then
echo "DOCKER_TAG=${{ steps.image.outputs.shortVersion }}" >> $GITHUB_ENV
else
echo "DOCKER_TAG=${{ steps.image.outputs.taggedVersion }}" >> $GITHUB_ENV
fi;
- name: Install dependencies
run: |
yarn install
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false

- name: Build
run: |
yarn storybook:build
- name: BUILD_STATE::successful
if: success()
run: echo "BUILD_STATE=successful" >> $GITHUB_ENV

- name: Packaging
run: |
yarn storybook:compress ${{ github.event.repository.name }}-storybook-${{ steps.image.outputs.prefix }}-${{ env.VERSION_SUFFIX }}
- name: Publish to Blob
if: ${{ github.ref == 'refs/heads/demo' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')}}
id: blobRelease
uses: VirtoCommerce/vc-github-actions/publish-blob-release@master
with:
blobSAS: ${{ secrets.BLOB_TOKEN }}
blobUrl: ${{ vars.BLOB_URL }}

- name: Set artifactUrl value
id: artifactUrl
run: |
echo "DOCKER_URL=${{ env.DOCKER_REPOSITORY }}/${GITHUB_REPOSITORY_OWNER,,}/${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }}" >> $GITHUB_OUTPUT
echo "BLOB_URL=${{ steps.blobRelease.outputs.packageUrl }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REPOSITORY }}
username: $GITHUB_ACTOR
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: true
context: .
file: .storybook/Dockerfile
tags: ${{ steps.artifactUrl.outputs.DOCKER_URL }}

- name: Add link to PR
if: ${{ github.event_name == 'pull_request' }}
uses: VirtoCommerce/vc-github-actions/publish-artifact-link@master
with:
artifactUrl: ${{ steps.artifactUrl.outputs.BLOB_URL }}
repoOrg: ${{ github.repository_owner }}
downloadComment: 'Artifact URL:'

- name: Parse Jira Keys from All Commits
uses: VirtoCommerce/vc-github-actions/get-jira-keys@master
if: always()
id: jira_keys
with:
release: ${{ env.RELEASE_STATUS }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Push Build Info to Jira
if: ${{ env.CLOUD_INSTANCE_BASE_URL != 0 && env.CLIENT_ID != 0 && env.CLIENT_SECRET != 0 && steps.jira_keys.outputs.jira-keys != '' && always() }}
id: push_build_info_to_jira
uses: HighwayThree/jira-upload-build-info@master
with:
cloud-instance-base-url: '${{ secrets.CLOUD_INSTANCE_BASE_URL }}'
client-id: '${{ secrets.CLIENT_ID }}'
client-secret: '${{ secrets.CLIENT_SECRET }}'
pipeline-id: '${{ github.repository }} ${{ github.workflow }}'
build-number: ${{ github.run_number }}
build-display-name: 'Workflow: ${{ github.workflow }} (#${{ github.run_number }})'
build-state: '${{ env.BUILD_STATE }}'
build-url: '${{github.event.repository.url}}/actions/runs/${{github.run_id}}'
update-sequence-number: '${{ github.run_id }}'
last-updated: '${{github.event.head_commit.timestamp}}'
issue-keys: '${{ steps.jira_keys.outputs.jira-keys }}'
commit-id: '${{ github.sha }}'
repo-url: '${{ github.event.repository.url }}'
build-ref-url: '${{ github.event.repository.url }}/actions/runs/${{ github.run_id }}'

- name: Confirm Jira Build Output
if: success()
run: |
echo "Jira Upload Build Info response: ${{ steps.push_build_info_to_jira.outputs.response }}"
deploy-cloud:
if: ${{ (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/demo' || github.ref == 'refs/heads/master') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }}
needs: ci
uses: ./.github/workflows/deploy-cloud.yml
with:
artifactUrl: ${{ needs.ci.outputs.artifactUrl }}
environmentId: ${{ github.ref == 'refs/head/dev' && 'dev' || 'prod' }}
jiraKeys: ${{ needs.ci.outputs.jira-keys }}
secrets: inherit
3 changes: 3 additions & 0 deletions .storybook/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx

COPY storybook-static /usr/share/nginx/html
1 change: 1 addition & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const storybookConfig: StorybookConfig = {
resolve(__dirname, "../vite.config.ts"),
))!;
return mergeConfig(storybookViteConfig, {
mode: "development",
envPrefix: config.envPrefix,
plugins: [splitVendorChunkPlugin()],
resolve: config.resolve,
Expand Down
Loading

0 comments on commit 2e59247

Please sign in to comment.