Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit c1c1356

Browse files
authored
Add Github Action
1 parent a877576 commit c1c1356

File tree

3 files changed

+124
-9
lines changed

3 files changed

+124
-9
lines changed

.github/actions/setup/action.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: 'iota-sandbox-setup'
2+
description: 'Setup IOTA Sandbox'
3+
inputs:
4+
version:
5+
description: 'Sandbox Version to use'
6+
required: false
7+
default: 'latest'
8+
branch:
9+
description: 'Branch/tag/commit to use'
10+
required: false
11+
protocol_parameters:
12+
description: 'Path to custom protocol parameters file'
13+
required: false
14+
milestone_interval:
15+
description: 'Custom milestone interval'
16+
required: false
17+
runs:
18+
using: "composite"
19+
steps:
20+
- name: Check if a faucet profile is enabled
21+
shell: bash
22+
run: |
23+
IFS=',' read -ra PROFILES <<< "${{ env.COMPOSE_PROFILES }}" # Split by ,
24+
FAUCET_ENABLED=false
25+
for i in "${PROFILES[@]}"; do
26+
i=$(echo "$i" | xargs) # Trim leading and trailing whitespaces
27+
if [[ "$i" == "inx" || "$i" == "inx-faucet" ]]; then # Check if inx or inx-faucet profile is enabled
28+
FAUCET_ENABLED=true
29+
break
30+
fi
31+
done
32+
echo "FAUCET_ENABLED=$FAUCET_ENABLED" >> "$GITHUB_ENV"
33+
- name: Setup iota sandbox using release version
34+
shell: bash
35+
if: ${{ inputs.version && !inputs.branch }}
36+
run: |
37+
mkdir iota-sandbox
38+
cd iota-sandbox
39+
mkdir sandbox
40+
cd sandbox
41+
# Use the output of https://api.github.com/repos/iotaledger/iota-sandbox/releases/
42+
if [[ "${{ inputs.version }}" == "latest" ]]; then
43+
DOWNLOAD_URL=$(curl "https://api.github.com/repos/iotaledger/iota-sandbox/releases/latest" | jq -r '.assets[] | select(.name | contains("iota_sandbox")) | .browser_download_url')
44+
else
45+
DOWNLOAD_URL=$(curl "https://api.github.com/repos/iotaledger/iota-sandbox/releases/tags/${{ inputs.version }}" | jq -r '.assets[] | select(.name | contains("iota_sandbox")) | .browser_download_url')
46+
fi
47+
echo "Downloading sandbox from $DOWNLOAD_URL"
48+
curl -L -o iota_sandbox.tar.gz $DOWNLOAD_URL
49+
tar -xf iota_sandbox.tar.gz
50+
- name: Setup iota sandbox using gitish version
51+
shell: bash
52+
if: ${{ inputs.branch }}
53+
run: |
54+
git clone https://github.com/iotaledger/iota-sandbox --branch ${{ inputs.branch }}
55+
- name: Overwrite protocol parameters
56+
shell: bash
57+
if: ${{ inputs.protocol_parameters }}
58+
run: |
59+
cp -f ${{ inputs.protocol_parameters }} iota-sandbox/sandbox/protocol_parameters.json
60+
- name: Change milestone interval
61+
working-directory: iota-sandbox/sandbox
62+
shell: bash
63+
if: ${{ inputs.milestone_interval }}
64+
run: |
65+
yq eval '.services.inx-coordinator.command += "--coordinator.interval=${{ inputs.milestone_interval }}"' docker-compose.yml > tmp.yml && mv tmp.yml docker-compose.yml
66+
- name: Bootstrap and start sandbox
67+
working-directory: iota-sandbox/sandbox
68+
shell: bash
69+
run: |
70+
sudo ./bootstrap.sh
71+
docker compose up -d
72+
- name: Wait for faucet to start
73+
if: ${{ env.FAUCET_ENABLED == 'true' }}
74+
shell: bash
75+
run: wget -qO- https://raw.githubusercontent.com/iotaledger/wait-for/$WAIT_FOR_VERSION/wait-for | sh -s -- -t 60 http://localhost/faucet/api/info -- echo "Faucet is up"
76+
env:
77+
WAIT_FOR_VERSION: d48601a8a90c3d22fade68d09b4240739fb44a46 # v2.2.4
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 'iota-sandbox-tear-down'
2+
description: 'tear-down a iota sandbox'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Tear down iota sandbox
7+
shell: bash
8+
run: |
9+
cd iota-sandbox/sandbox
10+
docker-compose down
11+
cd ../..
12+
sudo rm -rf iota-sandbox

README.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<a href="#about-the-project">About The Project</a>
5757
</li>
5858
<li><a href="#usage">Usage</a></li>
59-
<li><a href="#roadmap">Roadmap</a></li>
59+
<li><a href="#github-action">Github Action</a></li>
6060
<li><a href="#contributing">Contributing</a></li>
6161
<li><a href="#license">License</a></li>
6262
</ol>
@@ -88,16 +88,42 @@ _For more examples, please refer to the [Documentation](https://example.com)_
8888

8989

9090

91-
<!-- ROADMAP -->
92-
## Roadmap
91+
<!-- GITHUB ACTION -->
92+
## Github Action
9393

94-
- [ ] Add Explorer
95-
- [x] Add Chronicle
96-
- [ ] Add Faucet
97-
- [x] L1
98-
- [ ] L2
94+
The IOTA Sandbox provides two actions to use the sandbox in CI/CD for testing. `setup` and `tear-down`.
9995

100-
See the [open issues](https://github.com/iotaledger/iota-sandbox/issues) for a full list of proposed features (and known issues).
96+
### Usage
97+
98+
You can add those actions to your workflow by simply using it in a step. You can specify a version of the sandbox or a commit-ish ref to use any commit, branch, or tag.
99+
100+
```yml
101+
name: Sandbox
102+
103+
on:
104+
workflow-dispatch
105+
106+
env:
107+
# Specify which profiles you want to enable.
108+
COMPOSE_PROFILES: 'inx-indexer, chronicle'
109+
110+
jobs:
111+
sandbox:
112+
runs-on: ubuntu-latest
113+
steps:
114+
- name: Start iota sandbox
115+
uses: 'iotaledger/iota-sandbox/.github/actions/setup@VERION'
116+
with:
117+
# Optional. Specify an iota-sandbox version. Default is latest
118+
version: 'v1.1.0'
119+
# Optional. In case you want to use a commit-ish ref. If branch is set it will always overrule version
120+
branch: branch-xy
121+
# Optional. In case you want to use your own protocol parameters
122+
protocol_parameters: ./.github/workflows/protocol_parameters.json
123+
124+
- name: Tear down iota sandbox
125+
uses: 'iotaledger/iota-sandbox/.github/actions/setup@VERSION'
126+
```
101127
102128
<p align="right">(<a href="#top">back to top</a>)</p>
103129

0 commit comments

Comments
 (0)