feat: update install and publish process #731
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Main | |
on: | |
pull_request: | |
push: | |
branches: | |
- master | |
env: | |
# When building the bundle for npm we only want to include the prebuilds for | |
# the current node version we are supporting for Lodestar. The makeRelease | |
# script that builds the release and builds the npm package will select ONLY | |
# the version of node in this setup for publishing to npm. The rest will be | |
# added to the release on github and will be downloaded by the install script | |
# if they are using a version of node that is different then the one in this | |
# setup action. | |
NPM_PREBUILT_NODE_VERSION: 20 | |
jobs: | |
build: | |
strategy: | |
fail-fast: false | |
matrix: | |
node: | |
- 16 | |
- 18 | |
- 20 | |
- 21 | |
os: | |
- ubuntu-22.04 # linux x64 | |
- macos-12 # osx x64 | |
- macos-14 # osx arm | |
- windows-latest # windows x64 | |
runs-on: ${{matrix.os}} | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Setup Node.js ${{matrix.node}} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{matrix.node}} | |
- uses: actions/setup-python@v5 | |
with: | |
# More recent versions of python require more recent node-gyp | |
# See https://github.com/nodejs/node-gyp/issues/2869 | |
python-version: "3.11" | |
- name: Install && Build TS + bindings | |
run: yarn | |
- name: Run Unit Tests | |
run: yarn test:unit | |
- name: Run Memory Tests | |
run: yarn test:memory | |
# Attempt to pull spec-tests from cache | |
- name: Restore spec tests cache | |
id: cache-restore | |
if: matrix.os != 'windows-latest' | |
uses: actions/cache/restore@v4 | |
with: | |
path: spec-tests | |
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }} | |
# Download spec tests if not persisted | |
- name: Download spec tests | |
if: matrix.os != 'windows-latest' | |
run: yarn download-spec-tests | |
# Cache Spec Tests if not already cached | |
- name: Save spec tests to cache | |
if: matrix.os != 'windows-latest' && steps.cache-restore.outputs.cache-hit != 'true' | |
uses: actions/cache/save@v4 | |
with: | |
path: spec-tests | |
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }} | |
- name: Run spec tests | |
if: matrix.os != 'windows-latest' | |
run: yarn test:spec | |
- name: Upload binding.node | |
uses: actions/upload-artifact@v4 | |
if: github.repository_owner == 'chainsafe' && github.event_name != 'pull_request' | |
with: | |
name: binding.node | |
path: prebuild/*.node | |
if-no-files-found: error | |
# Required as current base images do not support arm64 | |
# https://resources.github.com/devops/accelerate-your-cicd-with-arm-and-gpu-runners-in-github-actions/ | |
# https://github.com/actions/runner-images/issues/5631 | |
build-arm: | |
strategy: | |
fail-fast: false | |
matrix: | |
node: | |
- 16 | |
- 18 | |
- 20 | |
- 21 | |
runs-on: ubuntu-22.04 | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
# Download spec tests with cache | |
- name: Restore spec tests cache | |
uses: actions/cache@v4 | |
with: | |
path: spec-tests | |
key: spec-test-data-${{ hashFiles('test/spec/specTestVersioning.ts') }} | |
# https://github.com/docker/setup-qemu-action | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build arm64 Binding, Run Tests and Copy Build Artifact to Host | |
run: | | |
docker buildx build --build-arg NODE_VERSION=${{matrix.node}} --platform linux/arm64 -t blst-ts-temp-armbuild:${{matrix.node}} --load --progress=plain . | |
docker create --name temp-container blst-ts-temp-armbuild:${{matrix.node}} | |
docker cp temp-container:/usr/src/blst-ts/prebuild ./prebuild | |
- name: Upload binding.node | |
uses: actions/upload-artifact@v4 | |
if: github.repository_owner == 'chainsafe' && github.event_name != 'pull_request' | |
with: | |
name: binding.node | |
path: prebuild/*.node | |
if-no-files-found: error | |
benchmark: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: Install | |
run: yarn | |
- name: Run Perf Tests | |
run: yarn test:perf | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
publish: | |
needs: ["build", "build-arm"] | |
if: github.ref == 'refs/heads/master' | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
# When building the bundle for npm we only want to include the prebuilds for | |
# the current node version we are supporting for Lodestar. The script below | |
# that builds the release and builds the npm package will select ONLY the | |
# version of node in this setup for publishing to npm. The rest will be | |
# added to the release on github and will be downloaded by the install script | |
# if they are using a version of node that is different then the one in this | |
# setup action. | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: ${{env.NPM_PREBUILT_NODE_VERSION}} | |
registry-url: "https://registry.npmjs.org" | |
- name: Create tag | |
id: tag | |
uses: butlerlogic/action-autotag@stable | |
with: | |
strategy: package | |
tag_prefix: "v" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Exit if no version change | |
if: steps.tag.outputs.tagcreated == 'no' | |
uses: actions/github-script@v3 | |
with: | |
script: core.setFailed('package.json version not changed. not creating release') | |
- name: Get pre-built binding.node files | |
uses: actions/download-artifact@v4 | |
with: | |
name: binding.node | |
path: prebuild/ | |
- name: Install | |
run: yarn | |
- name: Build TS | |
run: yarn build:ts | |
# Moves all prebuilds to the `release` folder and then only moves the | |
# prebuilds for the current node version into the `prebuild` folder for | |
# publishing to npm. Goal is to reduce bundle size and to also provide | |
# faster install time for the most common version that Lodestar is supporting | |
- name: Prepare for Release and Publishing | |
run: yarn ts-node scripts/makeRelease | |
- name: Create Github release with prebuilds | |
if: steps.tag.outputs.tagcreated == 'yes' | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: release/* | |
tag_name: ${{ steps.tag.outputs.tagname }} | |
fail_on_unmatched_files: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to NPM | |
if: steps.tag.outputs.tagcreated == 'yes' | |
run: yarn publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |