Skip to content

Commit

Permalink
Chore: Use reusable workflows for GitHub actions (#2345)
Browse files Browse the repository at this point in the history
* reusable workflows

* fix name

* fix syntax

* fix syntax again

* update install solana

* rename stuff

* fix naming

* Update test names once more
  • Loading branch information
stegaBOB committed Jan 3, 2023
1 parent a97d04a commit d055c89
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 461 deletions.
3 changes: 1 addition & 2 deletions .github/actions/setup-solana/action.yaml
Expand Up @@ -12,15 +12,14 @@ runs:
~/.local/share/solana/
key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}
- uses: nick-fields/retry@v2
if: steps.cache-solana.outputs.cache-hit != 'true'
with:
retry_wait_seconds: 300
timeout_minutes: 2
max_attempts: 10
retry_on: error
shell: bash
command: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
- run: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
shell: bash
- run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- run: solana-keygen new --no-bip39-passphrase
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/no-caching-tests.yaml
@@ -0,0 +1,17 @@
name: No Caching Tests

on:
push:
branches:
- master

jobs:
no-caching-tests:
name: Reusable
uses: ./.github/workflows/reusable-tests.yaml
with:
cache: false
solana_cli_version: 1.14.11
node_version: 17.0.1
cargo_profile: release
anchor_binary_name: anchor-binary-no-caching
@@ -1,12 +1,35 @@
name: No Cashing Tests
name: Reusable Tests

on:
push:
branches:
- master
workflow_call:
inputs:
cache:
required: true
type: boolean
solana_cli_version:
required: true
type: string
node_version:
required: true
type: string
cargo_profile:
required: true
type: string
anchor_binary_name:
required: true
type: string
env:
SOLANA_CLI_VERSION: 1.14.11
NODE_VERSION: 17.0.1
CACHE: inputs.cache
SOLANA_CLI_VERSION: ${{ inputs.solana_cli_version }}
NODE_VERSION: ${{ inputs.node_version }}
CARGO_PROFILE: ${{ inputs.cargo_profile }}
ANCHOR_BINARY_NAME: ${{ inputs.anchor_binary_name }}
CARGO_CACHE_PATH: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./target/
jobs:
test-core:
Expand All @@ -19,6 +42,13 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-cargo-build
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
- run: cargo build
- run: cargo fmt -- --check
- run: cargo clippy --all-targets -- -D warnings
Expand All @@ -43,12 +73,23 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup/
- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-anchor
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}

- run: cargo install --path cli anchor-cli --locked --force --debug
if: env.CARGO_PROFILE == 'debug'
- run: cargo install --path cli anchor-cli --locked --force
if: env.CARGO_PROFILE != 'debug'

- run: chmod +x ~/.cargo/bin/anchor
- uses: actions/upload-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/anchor

- uses: ./.github/actions/git-diff/
Expand All @@ -62,13 +103,54 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +rwx ~/.cargo/bin/anchor

- uses: ./.github/actions/setup/
- uses: ./.github/actions/setup-solana/
- uses: ./.github/actions/setup-ts/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: basic-0 cache
id: cache-basic-0
with:
path: ./examples/tutorial/basic-0/target
key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-0/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: basic-1 cache
id: cache-basic-1
with:
path: ./examples/tutorial/basic-1/target
key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-1/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: basic-2 cache
id: cache-basic-2
with:
path: ./examples/tutorial/basic-2/target
key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-2/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: basic-3 cache
id: cache-basic-3
with:
path: ./examples/tutorial/basic-3/target
key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-3/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: basic-4 cache
id: cache-basic-4
with:
path: ./examples/tutorial/basic-4/target
key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-4/**/Cargo.toml') }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- run: cd examples/tutorial && yarn workspaces run test
- uses: ./.github/actions/git-diff/

Expand Down Expand Up @@ -98,7 +180,7 @@ jobs:

- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +rwx ~/.cargo/bin/anchor

Expand All @@ -121,7 +203,7 @@ jobs:

- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor

Expand All @@ -145,6 +227,13 @@ jobs:
with:
name: composite.so
path: tests/composite/target/deploy/
- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache client/example target
id: cache-test-target
with:
path: client/example/target
key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}
- uses: ./.github/actions/setup-solana/
- run: cd client/example && ./run-test.sh
- uses: ./.github/actions/git-diff/
Expand All @@ -160,12 +249,28 @@ jobs:
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-anchor
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache tests/bpf-upgradeable-state target
id: cache-test-target
with:
path: tests/bpf-upgradeable-state/target
key: cargo-${{ runner.os }}-tests/bpf-upgradeable-state-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- run: solana-test-validator -r --quiet &
name: start validator
- run: cd tests/bpf-upgradeable-state && yarn --frozen-lockfile
Expand All @@ -190,6 +295,14 @@ jobs:
# - uses: actions/checkout@v3
# - uses: ./.github/actions/setup/
# - uses: ./.github/actions/setup-ts/
# - uses: actions/cache@v3
# name: Cache Solana Tool Suite
# id: cache-solana
# with:
# path: |
# ~/.cache/solana/
# ~/.local/share/solana/
# key: solana-${{ runner.os }}-v0000-1.8.14
# # using an outdated validator but that
# # is ok as long as the test doesn't
# # include newer incompatible features
Expand All @@ -203,10 +316,17 @@ jobs:
# shell: bash
# - uses: actions/download-artifact@v3
# with:
# name: anchor-binary-no-caching
# name: ${{ env.ANCHOR_BINARY_NAME }}
# path: ~/.cargo/bin/
# - run: chmod +x ~/.cargo/bin/anchor

# - uses: actions/cache@v3
# name: Cache tests/misc target
# id: cache-test-target
# with:
# path: tests/misc/target
# key: cargo-${{ runner.os }}-tests/misc-${{ env.ANCHOR_VERSION }}-1.8.14-${{ hashFiles('**/Cargo.lock') }}

# - run: cd tests/misc && yarn --frozen-lockfile
# - run: cd tests/misc
# - run: cd tests/misc && chmod +x ci.sh && ./ci.sh
Expand All @@ -223,9 +343,17 @@ jobs:
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-anchor
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor

Expand Down Expand Up @@ -259,6 +387,8 @@ jobs:
path: tests/escrow
- cmd: cd tests/pyth && anchor test --skip-lint && npx tsc --noEmit
path: tests/pyth
- cmd: cd tests/realloc && anchor test --skip-lint && npx tsc --noEmit
path: tests/realloc
- cmd: cd tests/system-accounts && anchor test --skip-lint
path: tests/system-accounts
- cmd: cd tests/misc && anchor test --skip-lint && npx tsc --noEmit
Expand Down Expand Up @@ -293,10 +423,10 @@ jobs:
path: tests/cpi-returns
- cmd: cd tests/multiple-suites && anchor test --skip-lint && npx tsc --noEmit
path: tests/multiple-suites
- cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
path: tests/optional
- cmd: cd tests/multiple-suites-run-single && anchor test --skip-lint --run tests/should-run && npx tsc --noEmit
path: tests/multiple-suites-run-single
- cmd: cd tests/optional && anchor test --skip-lint && npx tsc --noEmit
path: tests/optional
- cmd: cd tests/pda-derivation && anchor test --skip-lint && npx tsc --noEmit
path: tests/pda-derivation
- cmd: cd tests/relations-derivation && anchor test --skip-lint && npx tsc --noEmit
Expand All @@ -311,12 +441,28 @@ jobs:
- uses: ./.github/actions/setup-ts/
- uses: ./.github/actions/setup-solana/

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache Cargo registry + index
id: cache-anchor
with:
path: ${{ env.CARGO_CACHE_PATH }}
key: cargo-${{ runner.os }}-${{ env.CARGO_PROFILE }}-anchor-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/download-artifact@v3
with:
name: anchor-binary-no-caching
name: ${{ env.ANCHOR_BINARY_NAME }}
path: ~/.cargo/bin/
- run: chmod +x ~/.cargo/bin/anchor

- uses: actions/cache@v3
if: ${{ env.CACHE != 'false' }}
name: Cache ${{ matrix.node.path }} target
id: cache-test-target
with:
path: ${{ matrix.node.path }}/target
key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}-${{ env.SOLANA_CLI_VERSION }}-${{ hashFiles('**/Cargo.lock') }}

- run: ${{ matrix.node.cmd }}
name: ${{ matrix.node.path }} program test

Expand Down

1 comment on commit d055c89

@vercel
Copy link

@vercel vercel bot commented on d055c89 Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

anchor-docs – ./

www.anchor-lang.com
anchor-lang.com
anchor-docs-200ms.vercel.app
anchor-docs-git-master-200ms.vercel.app

Please sign in to comment.