Skip to content

Commit

Permalink
feat: add GitHub Action (#23)
Browse files Browse the repository at this point in the history
This PR adds a GitHub Action for installing the PocketIC server and a
test for this GitHub Action.
  • Loading branch information
mraszyk authored Oct 8, 2024
1 parent 26667a7 commit f95b024
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/pocket-ic-server-action-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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

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

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install latest PocketIC server and check its version
if: "${{ matrix.version == '' }}"
uses: ./
- name: Install PocketIC server and check its version
if: "${{ matrix.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
44 changes: 44 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 omitted, the latest version will be installed.
default: '6.0.0'

runs:
using: composite
steps:
- name: Install PocketIC server
shell: sh
run: |
export POCKET_IC_VERSION="${{ inputs.pocket-ic-server-version }}"
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

0 comments on commit f95b024

Please sign in to comment.