Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
chore: divide workflows into reusable pieces
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher committed Mar 7, 2024
1 parent c732fad commit 83ad925
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 88 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
on:
workflow_call:
secrets: inherit

jobs:
checkout:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
64 changes: 21 additions & 43 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,22 @@ env:
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
checkout:
uses: ./.github/workflows/checkout.yml@main

- name: Install package manager
uses: pnpm/action-setup@v2
with:
version: 8.6.1

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
install-dependencies:
uses: ./.github/workflows/install-dependencies.yml@main

- name: Install dependencies
run: pnpm install

- name: Get Test Validator Latest Release
id: get-test-validator-version
run: |
echo "version=$(./scripts/get-latest-validator-release-version.sh)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Test Validator
id: cache-test-validator
uses: actions/cache@v3
with:
path: .solana
key: ${{ runner.os }}-test-validator-${{ steps.get-test-validator-version.outputs.version }}

- name: Install Test Validator
if: steps.cache-test-validator.outputs.cache-hit != 'true'
run: scripts/setup-test-validator.sh

- name: Start Test Validator
id: test-validator
run: |
./scripts/start-shared-test-validator.sh &
echo "TEST_VALIDATOR_PID=$!" >> "$GITHUB_OUTPUT"
setup-validator:
uses: ./.github/workflows/validator-setup.yml@main

build-and-publish-to-npm:
needs:
- checkout
- install-dependencies
- setup-validator
runs-on: ubuntu-latest
steps:
- name: Publish NPM
run: |
pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}"
Expand All @@ -69,11 +42,16 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Stop Test Validator
run: kill ${{ steps.test-validator.outputs.TEST_VALIDATOR_PID}}

deploy-docs:
needs: build-and-publish-to-npm
steps:
- name: Deploy Github Page
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./packages/library-legacy/doc

validator_teardown:
uses: ./.github/workflows/validator-teardown.yml@main
needs: build-and-publish-to-npm
if: always()
26 changes: 26 additions & 0 deletions .github/workflows/install-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
workflow_call:
secrets: inherit

jobs:
checkout:
uses: ./.github/workflows/checkout.yml@main

install-dependencies:
needs: checkout
runs-on: ubuntu-latest

steps:
- name: Install package manager
uses: pnpm/action-setup@v2
with:
version: 8.6.1

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install
67 changes: 22 additions & 45 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ jobs:
# Needed for grouping check-web3 strategies into one check for mergify
all-web3-checks:
runs-on: ubuntu-latest
needs:
- build-and-test
needs: build-and-test
steps:
- run: echo "Done"

checkout:
uses: ./.github/workflows/checkout.yml@main

install-dependencies:
uses: ./.github/workflows/install-dependencies.yml@main

setup-validator:
uses: ./.github/workflows/validator-setup.yml@main

build-and-test:
runs-on: ubuntu-latest
needs:
- checkout
- install-dependencies
- setup-validator

strategy:
matrix:
Expand All @@ -32,52 +44,12 @@ jobs:

name: Build & Test on Node ${{ matrix.node }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install package manager
uses: pnpm/action-setup@v2
with:
version: 8.6.1

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Get Test Validator Latest Release
id: get-test-validator-version
run: |
echo "version=$(./scripts/get-latest-validator-release-version.sh)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Test Validator
id: cache-test-validator
uses: actions/cache@v3
with:
path: .solana
key: ${{ runner.os }}-test-validator-${{ steps.get-test-validator-version.outputs.version }}

- name: Install Test Validator
if: steps.cache-test-validator.outputs.cache-hit != 'true'
run: scripts/setup-test-validator.sh

- name: Start Test Validator
id: test-validator
run: |
./scripts/start-shared-test-validator.sh &
echo "TEST_VALIDATOR_PID=$!" >> "$GITHUB_OUTPUT"
- name: Build & Test
run: pnpm build --concurrency=100%

- name: Stop Test Validator
run: kill ${{ steps.test-validator.outputs.TEST_VALIDATOR_PID}}

upload-build-artifacts:
needs: build-and-test
steps:
- name: Upload Experimental library build artifacts
if: matrix.node == 'current'
uses: actions/upload-artifact@v3
Expand All @@ -86,3 +58,8 @@ jobs:
path: |
./packages/library/dist/
./packages/library/package.json
validator_teardown:
uses: ./.github/workflows/validator-teardown.yml@main
needs: build-and-test
if: always()
42 changes: 42 additions & 0 deletions .github/workflows/validator-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
on:
workflow_call:
outputs:
pid:
description: The PID of the running test validator
value: ${{ jobs.setup-validator.outputs.pid }}
secrets: inherit

jobs:
checkout:
uses: ./.github/workflows/checkout.yml@main

setup-validator:
needs: checkout
name: Install & Start Test Validator
runs-on: ubuntu-latest

outputs:
pid: ${{ steps.test-validator.outputs.TEST_VALIDATOR_PID }}

steps:
- name: Get Test Validator Latest Release
id: get-test-validator-version
run: echo "version=$(./scripts/get-latest-validator-release-version.sh)" >> $GITHUB_OUTPUT
shell: bash

- name: Cache Test Validator
id: cache-test-validator
uses: actions/cache@v3
with:
path: .solana
key: ${{ runner.os }}-test-validator-${{ steps.get-test-validator-version.outputs.version }}

- name: Install Test Validator
if: steps.cache-test-validator.outputs.cache-hit != 'true'
run: scripts/setup-test-validator.sh

- name: Start Test Validator
id: test-validator
run: |
./scripts/start-shared-test-validator.sh &
echo "TEST_VALIDATOR_PID=$!" >> "$GITHUB_OUTPUT"
16 changes: 16 additions & 0 deletions .github/workflows/validator-teardown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
workflow_call:
inputs:
pid:
required: true
type: string
secrets: inherit

jobs:
teardown_validator:
name: Stop Test Validator
runs-on: ubuntu-latest

steps:
- name: Stop Test Validator
run: kill ${{ inputs.pid }}

0 comments on commit 83ad925

Please sign in to comment.