Skip to content

Commit

Permalink
Simplify docker container params (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjthieme authored Oct 19, 2024
1 parent aa5b2eb commit cf73888
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# anchor-build

Docker image for building Anchor programs.
Docker image and GitHub Actions step for building Anchor/Solana programs.

### Usage

No inputs are required.

```yaml
- uses: wjthieme/anchor-build@v1
- uses: wjthieme/anchor-build@v2
```
#### Run a different command
By default, `anchor build` is run. You can specify a different command with the `run` input.

```yaml
- uses: wjthieme/anchor-build@v1
- uses: wjthieme/anchor-build@v2
with:
run: "cargo build-sbf"
```
Expand All @@ -25,7 +25,7 @@ By default, `anchor build` is run. You can specify a different command with the
By default, the latest version of Anchor is used. You can specify a different version with the `anchor-version` input.

```yaml
- uses: wjthieme/anchor-build@v1
- uses: wjthieme/anchor-build@v2
with:
anchor-version: "v0.29.0"
```
Expand All @@ -35,15 +35,7 @@ By default, the latest version of Anchor is used. You can specify a different ve
By default, you'll get a generated keypair to which 1 SOL is airdropped (devnet only). If you want to use your own keypair, you can supply it with the `solana-key` input.

```yaml
- uses: wjthieme/anchor-build@v1
- uses: wjthieme/anchor-build@v2
with:
solana-key: ${{ secrets.SOLANA_PRIVATE_KEY }}
```

### Local Testing

Install `docker` and `act` and run:

```sh
act workflow_dispatch
```
16 changes: 8 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ branding:
color: blue

inputs:
solana-key:
description: 'The private key to use for the solana sdk.'
required: false
run:
description: 'The command(s) to run.'
default: 'anchor build'
solana-cluster:
description: 'The cluster to use for the solana sdk.'
required: false
default: 'devnet'
solana-key:
description: 'The private key to use for the solana sdk.'
required: false
anchor-version:
description: 'The version of anchor to use.'
default: 'latest'
run:
description: 'The command(s) to run.'
default: 'anchor build'

runs:
using: "docker"
image: "ghcr.io/wjthieme/anchor-build:${{ inputs.anchor-version }}"
args:
- ${{ inputs.solana-key }}
- ${{ inputs.solana-cluster }}
- ${{ inputs.run }}
- ${{ inputs.solana-cluster }}
- ${{ inputs.solana-key }}
17 changes: 12 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/bin/bash
set -xeo pipefail

# Set default network to devnet if $2 is empty or not defined
if [ -z "$2" ]; then
NETWORK="devnet"
else
NETWORK="$2"
fi

# Configure Solana
solana config set --url "$2"
solana config set --url "$NETWORK"

# Configure Solana Key
if [ -z "$1" ]; then
if [ -z "$3" ]; then
solana-keygen new --no-bip39-passphrase
else
echo "$1" > ~/.config/solana/id.json
echo "$3" > ~/.config/solana/id.json
fi

# Airdrop Solana if on devnet
if [ "$2" == "devnet" ]; then
if [ "$NETWORK" == "devnet" ]; then
solana airdrop 1 || true
fi

# Run the provided commands
eval "$3"
eval "$1"

0 comments on commit cf73888

Please sign in to comment.