-
Notifications
You must be signed in to change notification settings - Fork 31
192 lines (165 loc) · 7.01 KB
/
storybook-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# v1.0.1.vcst
name: Storybook CI
on:
workflow_dispatch:
push:
branches:
[master, dev]
paths-ignore:
- '.idea'
- '.vscode'
- 'README.md'
- 'LICENSE'
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}}
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
BLOB_SAS: ${{ secrets.BLOB_TOKEN }}
VERSION: ''
VERSION_SUFFIX: ''
BUILD_STATE: 'failed'
RELEASE_STATUS: 'false'
DOCKER_URL: ''
DOCKER_REPOSITORY: 'ghcr.io'
DOCKER_IMAGE: 'vc-theme-b2b-vue-storybook'
DOCKER_TAG: ''
outputs:
jira-keys: ${{ steps.jira_keys.outputs.jira-keys }}
version: ${{ steps.image.outputs.shortVersion }}
tag: ${{ env.DOCKER_TAG }}
steps:
- name: Set up Node 22
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Enable corepack
run: |
corepack enable
- name: Set RELEASE_STATUS
if: ${{ github.ref == 'refs/heads/master' && github.event_name == 'push' }}
run: |
echo "RELEASE_STATUS=true" >> $GITHUB_ENV
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Image Version
uses: VirtoCommerce/vc-github-actions/get-image-version@master
with:
projectType: theme
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 VERSION
run: |
echo "VERSION=${{ steps.image.outputs.prefix }}${{ env.VERSION_SUFFIX && '-' || '' }}${{ env.VERSION_SUFFIX }}" >> $GITHUB_ENV
- name: Update package.json Version
run: |
yarn version ${{ env.VERSION }}
- 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
- name: Build
run: |
yarn storybook:build
- name: BUILD_STATE::successful
if: success()
run: echo "BUILD_STATE=successful" >> $GITHUB_ENV
- name: Add files to zip
run: |
mkdir ./artifacts
cd ./storybook-static
zip -r ../artifacts/$(jq -r .name ../package.json)-$(jq -r .version ../package.json).zip ./*
- name: Publish to Blob
if: ${{ github.ref == 'refs/heads/master' || 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 URLs
id: urls
run: |
echo "DOCKER_URL=${{ env.DOCKER_REPOSITORY }}/${GITHUB_REPOSITORY_OWNER,,}/${{ env.DOCKER_IMAGE }}:" >> $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: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/master')}}
context: .
file: .storybook/Dockerfile
tags: ${{ steps.urls.outputs.DOCKER_URL }}${{ env.DOCKER_TAG }},${{ steps.urls.outputs.DOCKER_URL }}${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/dev' && 'dev-latest' || 'latest'}}
- 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: VirtoCommerce/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.event_name == 'pull_request'}}
needs: ci
uses: ./.github/workflows/deploy-cloud.yml
with:
cmPath: 'storybook/image.json'
artifactKey: 'Tag'
artifactUrl: ${{ needs.ci.outputs.tag }}
environmentId: ${{ github.ref == 'refs/heads/master' && 'qa' || 'dev' }}
jiraKeys: ${{ needs.ci.outputs.jira-keys }}
forceCommit: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/dev' }}
secrets: inherit