Skip to content

Commit

Permalink
OK-496: Refaktoroitu CI-putkea ja lisätty storybookin julkaisulle oma…
Browse files Browse the repository at this point in the history
… workflow

- Lisätty myös storybookin ajamiselle ja testaamiselle skriptit
  • Loading branch information
pretseli committed Jun 7, 2024
1 parent e19c980 commit 3c2b904
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
15 changes: 15 additions & 0 deletions .github/actions/build-storybook/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Build storybook
description: Install dependencies and build Storybook
runs:
using: 'composite'
steps:
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install dependencies
shell: bash
run: npm ci --no-audit --prefer-offline --ignore-scripts
- name: Build storybook
shell: bash
run: npm run build-storybook -- --quiet
14 changes: 14 additions & 0 deletions .github/actions/deploy-storybook/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Deploy storybook
description: Deploy prebuilt storybook
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
runs:
using: 'composite'
steps:
- name: Deploy storybook
shell: bash
run: |
git clone https://github.com/Opetushallitus/ci-tools.git
source ci-tools/common/setup-tools.sh
sh scripts/deploy-storybook.sh
35 changes: 11 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,22 @@ on:
push:
paths-ignore:
- '**.md'

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: ./.github/actions/build-storybook

- name: Install dependencies
run: npm ci --no-audit --prefer-offline --ignore-scripts

- uses: actions/cache/restore@v4
id: storybook
with:
path: storybook-static
key: ${{ github.sha }}

- name: Lint
run: |
npm run typecheck
Expand All @@ -35,14 +32,8 @@ jobs:
- name: Test running example project with library import
run: npm run start-and-test-example

- name: Build storybook
run: npm run build-storybook -- --quiet

- name: Run storybook
run: npx http-server ./storybook-static -p 6006 &

- name: Test Storybook
run: npm run test-storybook:coverage
- name: Start and test storybook
run: npm run start-built-storybook-and-test

- uses: actions/upload-artifact@v4
if: always()
Expand All @@ -51,9 +42,5 @@ jobs:
path: __snapshots__/__diff_output__/
retention-days: 10
if-no-files-found: ignore

- name: Publish storybook
run: |
git clone https://github.com/Opetushallitus/ci-tools.git
source ci-tools/common/setup-tools.sh
sh scripts/deploy-storybook.sh
- uses: ./.github/actions/deploy-storybook
if: github.ref == 'refs/heads/main'
11 changes: 11 additions & 0 deletions .github/workflows/publish-storybook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Publish storybook
on:
push:
workflow_dispatch:

jobs:
publish:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-storybook
- uses: ./.github/actions/deploy-storybook
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"test-storybook": "test-storybook",
"test-storybook:coverage": "test-storybook --coverage",
"test-storybook:update-snapshots": "test-storybook --updateSnapshot",
"start-built-storybook": "npx http-server ./storybook-static -p 6006",
"start-built-storybook-and-test": "start-server-and-test start-built-storybook 6006 test-storybook:coverage",
"start-example": "cd example; npm run deps-and-dev",
"test-example": "npx playwright test ./example/test/smoke-test.spec.ts",
"start-and-test-example": "start-server-and-test start-example 3000 test-example",
Expand Down
4 changes: 0 additions & 4 deletions scripts/deploy-storybook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -e pipefail

echo "Copying Storybook files to AWS S3 buildnumber (ga-$GITHUB_RUN_NUMBER) directory"
aws s3 sync storybook-static s3://dev-files.ops.opintopolku.fi/storybooks/oph-design-system/builds/ga-$GITHUB_RUN_NUMBER --delete --cache-control max-age=600 --acl public-read
echo "Storybook link (temporary for build): https://dev-files.ops.opintopolku.fi/storybooks/oph-design-system/builds/ci-$GITHUB_RUN_NUMBER/index.html"

echo "Copying Storybook files to AWS S3 branch ($GITHUB_REF_NAME) directory"
aws s3 sync storybook-static s3://dev-files.ops.opintopolku.fi/storybooks/oph-design-system/$GITHUB_REF_NAME --delete --cache-control max-age=600 --acl public-read
echo "Storybook link (permanent for branch): https://dev-files.ops.opintopolku.fi/storybooks/oph-design-system/$GITHUB_REF_NAME/index.html"

0 comments on commit 3c2b904

Please sign in to comment.