Skip to content

Commit

Permalink
ci(shared-data, components): add github action for publishing package…
Browse files Browse the repository at this point in the history
…s to npm (#14077)

In order to support a single source of truth for applications outside of the monorepo (read:
"Protocol Library") that rely on fundamental components and geometries within the mono repo, add tag
based deploy actions that publish bundled artifacts to NPM.
  • Loading branch information
b-cooper authored Dec 5, 2023
1 parent 3ef9cb5 commit 3c4008d
Show file tree
Hide file tree
Showing 28 changed files with 1,249 additions and 545 deletions.
84 changes: 80 additions & 4 deletions .github/workflows/components-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
files: ./coverage/lcov.info
flags: components

build-components:
build-components-storybook:
name: 'build components artifact'
runs-on: 'ubuntu-22.04'
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -102,11 +102,32 @@ jobs:
with:
name: 'components-artifact'
path: storybook-static

determine-build-type:
runs-on: 'ubuntu-latest'
name: 'Determine build type'
outputs:
type: ${{steps.determine-build-type.outputs.type}}
steps:
- id: determine-build-type
run: |
echo "Determining build type for event ${{github.event_type}} and ref ${{github.ref}}"
if [ "${{ format('{0}', github.ref == 'refs/heads/edge') }}" = "true" ] ; then
echo "storybook s3 builds for edge"
echo 'type=storybook' >> $GITHUB_OUTPUT
elif [ "${{ format('{0}', startsWith(github.ref, 'refs/tags/components')) }}" = "true" ] ; then
echo "publish builds for components tags"
echo 'type=publish' >> $GITHUB_OUTPUT
else
echo "No build for ref ${{github.ref}} and event ${{github.event_type}}"
echo 'type=none' >> $GITHUB_OUTPUT
fi
deploy-components:
name: 'deploy components artifact to S3'
name: 'deploy components storybook artifact to S3'
runs-on: 'ubuntu-22.04'
needs: ['js-unit-test', 'build-components']
if: github.event_name != 'pull_request'
needs: ['js-unit-test', 'build-components-storybook', 'determine-build-type']
if: needs.determine-build-type.outputs.type != 'none'
steps:
- uses: 'actions/checkout@v3'
# https://github.com/actions/checkout/issues/290
Expand Down Expand Up @@ -137,3 +158,58 @@ jobs:
AWS_DEFAULT_REGION: us-east-2
run: |
aws s3 sync ./dist s3://opentrons-components/${{ env.OT_BRANCH}} --acl public-read
publish-components:
name: 'publish components package to npm'
runs-on: 'ubuntu-latest'
needs: ['js-unit-test', 'determine-build-type']
if: needs.determine-build-type.outputs.type == 'publish'
steps:
- uses: 'actions/checkout@v3'
# https://github.com/actions/checkout/issues/290
- name: 'Fix actions/checkout odd handling of tags'
if: startsWith(github.ref, 'refs/tags')
run: |
git fetch -f origin ${{ github.ref }}:${{ github.ref }}
git checkout ${{ github.ref }}
- uses: 'actions/setup-node@v3'
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- name: 'cache yarn cache'
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.yarn-cache
${{ github.workspace }}/.npm-cache
key: js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-
- name: 'setup-js'
run: |
npm config set cache ./.npm-cache
yarn config set cache-folder ./.yarn-cache
yarn config set network-timeout 60000
yarn
- name: 'build library'
run: |
make -C components lib
# replace package.json stub version number with version from tag
- name: 'set version number'
run: |
npm install -g json
VERSION_STRING=$(echo ${{ github.ref }} | sed 's/refs\/tags\/components@//')
json -I -f ./components/package.json -e "this.version=\"$VERSION_STRING\""
json -I -f ./components/package.json -e "this.dependencies['@opentrons/shared-data']=\"$VERSION_STRING\""
- uses: 'actions/setup-node@v3'
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- name: 'publish to npm registry'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ./components && echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ./.npmrc && npm publish --access public
77 changes: 76 additions & 1 deletion .github/workflows/shared-data-test-lint-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ on:
- '*hotfix*'
tags:
- 'v*'
- 'shared-data*'
- 'components*'
pull_request:
paths:
- 'Makefile'
Expand Down Expand Up @@ -127,7 +129,7 @@ jobs:
key: js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-
- name: 'setup-js'
- name: 'js deps'
run: |
npm config set cache ./.npm-cache
yarn config set cache-folder ./.yarn-cache
Expand Down Expand Up @@ -187,3 +189,76 @@ jobs:
project: 'shared-data/python'
repository_url: 'https://upload.pypi.org/legacy/'
password: '${{ secrets.OT_PYPI_PASSWORD }}'

publish-switch:
runs-on: 'ubuntu-latest'
name: 'Determine whether or not to publish artifacts'
outputs:
should_publish: ${{steps.publish-switch.outputs.should_publish}}
steps:
- id: publish-switch
run: |
echo "Determining whether to publish artifacts for event ${{github.event_type}} and ref ${{github.ref}}"
if [ "${{ format('{0}', startsWith(github.ref, 'refs/tags/shared-data')) }}" ] ; then
echo "Publishing builds for shared-data@ tags"
echo 'should_publish=true' >> $GITHUB_OUTPUT
elif [ "${{ format('{0}', startsWith(github.ref, 'refs/tags/components')) }}" ] ; then
echo "Publishing builds for components@ tags"
echo 'should_publish=true' >> $GITHUB_OUTPUT
else
echo "No publish for ref ${{github.ref}} and event ${{github.event_type}}"
echo 'should_publish=false' >> $GITHUB_OUTPUT
fi
publish-to-npm:
name: 'publish shared-data package to npm'
runs-on: 'ubuntu-latest'
needs: ['js-test', 'publish-switch']
if: needs.publish-switch.outputs.should_publish == 'true'
steps:
- uses: 'actions/checkout@v3'
# https://github.com/actions/checkout/issues/290
- name: 'Fix actions/checkout odd handling of tags'
if: startsWith(github.ref, 'refs/tags')
run: |
git fetch -f origin ${{ github.ref }}:${{ github.ref }}
git checkout ${{ github.ref }}
- uses: 'actions/setup-node@v3'
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- name: 'cache yarn cache'
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.yarn-cache
${{ github.workspace }}/.npm-cache
key: js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
js-${{ secrets.GH_CACHE_VERSION }}-${{ runner.os }}-yarn-
- name: 'js deps'
run: |
npm config set cache ./.npm-cache
yarn config set cache-folder ./.yarn-cache
yarn config set network-timeout 60000
yarn
- name: 'build library'
run: |
make -C shared-data lib-js
# replace package.json stub version number with version from tag
- name: 'set version number'
run: |
npm install -g json
VERSION_STRING=$(echo ${{ github.ref }} | sed -E 's/refs\/tags\/(components|shared-data)@//')
json -I -f ./shared-data/package.json -e "this.version=\"$VERSION_STRING\""
cd ./shared-data
- uses: 'actions/setup-node@v3'
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
- name: 'publish to npm registry'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ./shared-data && echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ./.npmrc && npm publish --access public
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ setup-js:
yarn
$(MAKE) -C $(APP_SHELL_DIR) setup
$(MAKE) -C $(APP_SHELL_ODD_DIR) setup
$(MAKE) -C $(SHARED_DATA_DIR) setup-js

PYTHON_SETUP_TARGETS := $(addsuffix -py-setup, $(PYTHON_DIRS))

Expand Down
3 changes: 3 additions & 0 deletions components/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
dist
*.tgz
5 changes: 5 additions & 0 deletions components/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ clean:
dist:
yarn --cwd .. build-storybook

.PHONY: lib
lib: export NODE_ENV := production
lib:
yarn webpack

# development
#####################################################################

Expand Down
17 changes: 0 additions & 17 deletions components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,3 @@ Unit tests live in a `__tests__` directory in the same directory as the module u
[jest-snapshots]: https://facebook.github.io/jest/docs/en/snapshot-testing.html
[contributing]: ../CONTRIBUTING.md
### Flow definitions
While the components library is written in TypeScript, some dependents of the components library are not yet converted. To ease the conversion effort, `components/flow-types` contains automatically generated Flow type definitions from the TypeScript typings generated by `tsc`.
To generate these definitions
```shell
# ensure all TypeScript definitions are built
make build-ts
# build flow definitions (this may take a while!)
make -C components flow-types
# you can also build individual files if you're testing out small changes
make -C components flow-types/buttons/Button.js.flow
```
2 changes: 2 additions & 0 deletions components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"source": "src/index.ts",
"types": "lib/index.d.ts",
"style": "src/index.css",
"main": "lib/opentrons-components.js",
"module": "src/index.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Opentrons/opentrons.git"
Expand Down
23 changes: 0 additions & 23 deletions components/src/legacy-hardware-sim/Labware.css

This file was deleted.

1 change: 1 addition & 0 deletions components/src/legacy-hardware-sim/LabwareNameOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface LabwareNameOverlayProps {
className?: string
}

/** @deprecated use LabwareDisplayName or custom RobotCoordsForeignDiv */
export function LabwareNameOverlay(
props: LabwareNameOverlayProps
): JSX.Element {
Expand Down
Loading

0 comments on commit 3c4008d

Please sign in to comment.