Skip to content

Commit

Permalink
fixup! Move download Storybook artefact script to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
jpveooys committed Apr 12, 2022
1 parent ac7e8b8 commit f698f7d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/post_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,12 @@ jobs:
run: |
yarn install --frozen-lockfile
# Based on
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
- name: Download pre-built Storybook
uses: actions/github-script@v6
with:
script: |
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "storybook-static"
})[0];
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/storybook-static.zip`, Buffer.from(download.data));
const { downloadStorybookArtifact } = await import('${{ github.workspace }}/scripts/github-actions/downloadStorybookArtifact.mjs')
await downloadStorybookArtifact({ github, context })
- name: Unzip pre-built Storybook
run: |
Expand Down
31 changes: 31 additions & 0 deletions scripts/github-actions/downloadStorybookArtifact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs'

/**
* Used by .github/workflows/post_build_and_test.yml
*
* Based on
* https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
*/
export const downloadStorybookArtifact = async ({ github, context }) => {
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
})

const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name === 'storybook-static'
})[0]

const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
})

fs.writeFileSync(
`${process.env.GITHUB_WORKSPACE}/storybook-static.zip`,
Buffer.from(download.data)
)
}

0 comments on commit f698f7d

Please sign in to comment.