Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GitHub Action #23

Merged
merged 19 commits into from
Oct 8, 2024
46 changes: 46 additions & 0 deletions .github/workflows/pocket-ic-server-action-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
push:
branches:
- 'main'
pull_request:

jobs:
test_pocket_ic_server_action:
runs-on: ${{ matrix.os }}
name: Test the PocketIC server action (action.yml)
strategy:
fail-fast: false
matrix:
include:
- version: '5.0.0'
expected-version: '5.0.0'
os: ubuntu-latest
- version: '5.0.0'
expected-version: '5.0.0'
os: macos-latest

- version: 'latest'
expected-version: '6.0.0'
os: ubuntu-latest
- version: 'latest'
expected-version: '6.0.0'
os: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install PocketIC server and check its version
uses: ./
with:
pocket-ic-server-version: ${{ matrix.version }}
- name: Check if the proper PocketIC server version is installed
run: |
actual_pocket_ic_server_ver="$(${POCKET_IC_BIN} --version)"

expected_pocket_ic_server_ver="pocket-ic-server ${{ matrix.expected-version }}"

if [ "$actual_pocket_ic_server_ver" != "$expected_pocket_ic_server_ver" ]; then
echo "Error: expected PocketIC server version '$expected_pocket_ic_server_ver', but '$actual_pocket_ic_server_ver' found"
exit 1
fi
echo "PocketIC server version '$actual_pocket_ic_server_ver' was installed correctly"
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,39 @@

PocketIC is a canister smart contract testing solution for the [Internet Computer](https://internetcomputer.org/).

## GitHub Action
This repository provides a GitHub Action to set up the PocketIC server.

### Usage
To use this action in your GitHub workflow, include it as a step in your workflow configuration:

```yml
jobs:
example-job:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install PocketIC server
uses: dfinity/pocketic@main
- name: Confirm successful installation
run: "${POCKET_IC_BIN}" --version
```

The action is designed to run on both ubuntu- and macos- runners.

### Specifying a PocketIC server version
You can specify a particular version of the PocketIC server to install using the `pocket-ic-server-version` input:

```yml
- name: Install PocketIC server
uses: dfinity/pocketic@main
with:
pocket-ic-server-version: "6.0.0"
```

## Download the PocketIC Server
You can find the versions of the PocketIC server under the [Releases](https://github.com/dfinity/pocketic/releases) tab on the right.
Alternatively to using the GitHub Action, you can download the PocketIC server binary for a particular version in the [Releases](https://github.com/dfinity/pocketic/releases) tab on the right.
For macOS, choose `pocket-ic-x86_64-darwin.gz`, for Linux, choose `pocket-ic-x86_64-linux.gz`.

Save the downloaded file as `pocket-ic.gz`, decompress it, and make it executable:
Expand All @@ -14,6 +44,12 @@ gzip -d pocket-ic.gz
chmod +x pocket-ic
```

Finally, export the `POCKET_IC_BIN` environment variable to point to the (absolute) path of the PocketIC server binary:

```bash
export POCKET_IC_BIN="$(pwd)/pocket-ic"
```

On **macOS**, you might have to additionally run:
```bash
xattr -dr com.apple.quarantine pocket-ic
Expand All @@ -22,7 +58,6 @@ to bypass the developer verification from Apple.
Alternatively, you can open the `pocket-ic` binary by right clicking on it in the Finder and selecting "Open" from the drop-down menu.
Then, confirm opening this application by clicking "Open" in the dialog that pops up.


## Using PocketIC
After completion of above steps, you can verify that everything works by running:
```bash
Expand Down
48 changes: 48 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'Install PocketIC server'
description: 'Install the PocketIC server at a particular version'
inputs:
pocket-ic-server-version:
description: >
The PocketIC server version to install.
If "latest" is provided, the latest version will be installed.
default: 'latest'

runs:
using: composite
steps:
- name: Install PocketIC server
shell: sh
run: |
if [ "${{ inputs.pocket-ic-server-version }}" = "latest" ]; then
export POCKET_IC_VERSION="6.0.0"
else
export POCKET_IC_VERSION="${{ inputs.pocket-ic-server-version }}"
fi

echo "POCKET_IC_VERSION is $POCKET_IC_VERSION"

if [ "${{ runner.os }}" = 'Linux' ]; then
export OS="linux"
elif [ "${{ runner.os }}" = 'macOS' ]; then
export OS="darwin"
else
echo "Unsupported OS."
exit 1
fi

echo "OS is $OS"

# Retry up to 10 times. Each attempt has 20 seconds total to complete, 5 seconds of which is to connect.
# This uses the default retry delay, which starts at 1s and doubles each time, up to 10 min.
if $(curl --fail --silent --show-error --location --retry 10 --connect-timeout 5 --max-time 20 --retry-connrefused https://github.com/dfinity/pocketic/releases/download/${POCKET_IC_VERSION}/pocket-ic-x86_64-${OS}.gz -o pocket-ic.gz); then
echo "Successfully downloaded PocketIC server."
else
echo "Failed to download PocketIC server."
exit 1
fi

gzip -d pocket-ic.gz
chmod +x pocket-ic

export POCKET_IC_BIN="$(pwd)/pocket-ic"
echo "POCKET_IC_BIN=$POCKET_IC_BIN" >> $GITHUB_ENV