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

Initial version from github actions workflow #45

Merged
merged 19 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
INCLUDE_CASES=00_00_01-sync.js,01_01_01-pre_orchid_2wp.js
RUN_EACH_TEST_FILE_THESE_TIMES=1
RUN_ALL_TESTS_THESE_TIMES=1

# Amount of time in milliseconds for the `waitForBlock` utility function to wait.
# Configurable because depending on the resources of the machine the tests are running on, the wait time might change.
# In a machine with little resources (CPU, RAM, disk), a small wait time might not be enough because blocks can be mined slow and `waitForBlock`
# might fail with a message like `Block number 800 never reached, last seen was 600`, or `Blockchain not advancing after attempting to find a new block 80 times checking every 200 milliseconds.
# Couldn't reach block number 800. Last block number seen was: 600`. In a machine with enough resources having a high wait time might be a waste of time since the tests would run slower because if this wait time.
# In this case, it can be set to a small value. `200` recommended for most machines with enough resources. `500`, `600`, etc., or more for machine with limited resources.
# Adjust as needed, starting with low values so the tests run as fast as they can.
WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS=

# Max attempts for the `waitForBlock` utility function to 'wait' for the given block, trying to find that block once every `WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS`.
# The same as the `WAIT_FOR_BLOCK_ATTEMPT_TIME_MILLIS` variable, the value for this variable could be updated depending on the machine the tests are running on.
# `80` recommended for most machines with enough resources. `160`, `250` or more for machine with limited resources.
# Adjust as needed, starting with low values so the tests run as fast as they can.
WAIT_FOR_BLOCK_MAX_ATTEMPTS=
127 changes: 127 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: RIT Action Continuous Integration Test

on:
pull_request:
push:
branches:
- main
fmacleal marked this conversation as resolved.
Show resolved Hide resolved

permissions:
contents: read
packages: write
env:
TEST_TAG: ${{ github.event.repository.name }}/rit:test
LATEST_TAG: ghcr.io/rsksmart/${{ github.event.repository.name }}/rit

jobs:
build-push-rit-action-container-action:
name: Test RIT Action docker container-action
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.LATEST_TAG }}
${{ env.TEST_TAG }}

- name: Setup Docker BuildX
id: setup-buildx
uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: network=host
platforms: linux/amd64

- name: Build and export locally Docker
uses: docker/build-push-action@v6
with:
context: container-action/
load: true
tags: ${{ env.TEST_TAG }}

- name: Test the RIT Container Action
id: test-container
env:
INPUT_RSKJ_BRANCH: master
INPUT_POWPEG_NODE_BRANCH: master
INPUT_RIT_BRANCH: main
INPUT_RIT_LOG_LEVEL: info
run: |
docker run \
--env GITHUB_OUTPUT="/github-output" \
--env INPUT_RSKJ_BRANCH="${{ env.INPUT_RSKJ_BRANCH }}" \
--env INPUT_POWPEG_NODE_BRANCH="${{ env.INPUT_POWPEG_NODE_BRANCH }}" \
--env INPUT_RIT_BRANCH="${{ env.INPUT_RIT_BRANCH }}" \
--env INPUT_RIT_LOG_LEVEL="${{ env.INPUT_RIT_LOG_LEVEL }}" \
-v "$GITHUB_OUTPUT:/github-output" \
--rm ${{ env.TEST_TAG }}

- name: GitHub container registry login
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build the RIT Action Container Image
uses: docker/build-push-action@v6
with:
context: container-action/
tags: ${{ env.LATEST_TAG }}
labels: ${{ steps.meta.outputs.labels }}
load: true
push: true

test-rit-action:
needs: build-push-rit-action-container-action
name: GitHub Actions Test
runs-on: ubuntu-latest
timeout-minutes: 60

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test RIT Action
id: test-rit-action
uses: ./container-action/
with:
rskj-branch: master
powpeg-node-branch: master

- name: Print RIT Status and Message
id: output
run: |
echo "RIT Status = ${{ steps.test-rit-action.outputs.status }}"
echo "RIT Message = ${{ steps.test-rit-action.outputs.message }}"

publish-rit-action-tag:
needs: test-rit-action
name: Publish RIT Action tag
runs-on: ubuntu-latest
timeout-minutes: 60
if: github.ref == 'refs/heads/main'

steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: rootstock-integration-tests@v1
release_name: Release rootstock-integration-tests@v1
draft: false
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ config/*.js
logs
.env
.DS_Store
.idea/
fmacleal marked this conversation as resolved.
Show resolved Hide resolved
60 changes: 60 additions & 0 deletions container-action/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
FROM ubuntu:24.04 AS builder

LABEL Description="Custom RSK node image to execute Rootstock Integration Tests"

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates curl git gnupg2 mocha wget \
&& apt clean

# -- nodeJs ---------------------------------------------------------
ENV NODE_VERSION v20.14.0
RUN mkdir -p /usr/local/nvm
ENV NVM_DIR /usr/local/nvm

RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

ENV NODE_PATH $NVM_DIR/$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/$NODE_VERSION/bin:$PATH

# -- java ---------------------------------------------------------
ENV JAVA_VERSION 17

RUN apt-get -y install "openjdk-$JAVA_VERSION-jdk"

ENV JAVA_HOME="/usr/lib/jvm/java-$JAVA_VERSION-openjdk-amd64"

# -- bitcoind ---------------------------------------------------------
ENV BITCOIN_VERSION 0.18.1

RUN cd /tmp \
&& wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz \
&& tar -xzvf bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz -C /opt \
&& mv /opt/bitcoin-${BITCOIN_VERSION} /opt/bitcoin \
&& rm -v /opt/bitcoin/bin/test_bitcoin /opt/bitcoin/bin/bitcoin-qt \
&& ln -sv /opt/bitcoin/bin/* /usr/local/bin

# -- configure entrypoint to run RIT--------------------------------------------

RUN mkdir -p /usr/src/logbacks

WORKDIR /usr/src

COPY entrypoint.sh /usr/src/entrypoint.sh
COPY rit-local-configs/regtest-all-keys.js /usr/src/regtest.js
COPY rit-local-configs/logbacks/* /usr/src/logbacks/
COPY scripts/* /usr/src/

RUN chmod +x /usr/src/entrypoint.sh \
&& chmod +x /usr/src/configure_gradle_powpeg.sh \
&& chmod +x /usr/src/configure_rit_locally.sh \
&& mkdir -p /usr/src/bitcoindata \
&& chmod -R 755 /usr/src/bitcoindata

ENTRYPOINT ["/usr/src/entrypoint.sh"]

EXPOSE 18332
60 changes: 60 additions & 0 deletions container-action/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Rootstock Integration Tests Action

This action provides a containerized environment for running integration tests on Rootstock.
It receives as inputs the branches of `powpeg`, `rskj` and `rootstock-integration-tests` repositories,
checkout at the branches passed as parameters, build the projects and run the integration tests.

The rootstock-integration-tests it's a project that tests the integration between rskj and powpeg-node,
it validates that the peg-in and peg-out processes are working correctly. It's extremely important to both projects,
and should be executed before any release of both projects or any merge to the master/main branch.

To achieve this and make this test more accessible, we created a container-action created to execute this test,
it offers the flexibility to run the tests with any specific tag or branch from *powpeg-node* or *rskj*.
That way, we will add steps on each repository to run the integration tests with the version that we want to test.
No matter if it's a tag, a branch or a specific commit.

## Inputs
By default, all the inputs are pointed to the `master/main` branch of the repositories. But, ideally, the action step
should receive the branches, commit or tag that should be tested by the pipeline execution. If we want to test
a specific tag from `powpeg-node`, the input parameter `powpeg-node-branch` should be the tag number `6.4.0.0-rc` for example.

### `rskj-branch`

The rskj branch to checkout. If no branch or tag passed, it will be used the default `master`.

### `powpeg-node-branch`

The powpeg-node branch to checkout. If no branch or tag passed, it will be used the default `master`.

### `rit-branch`

**Optional** The rootstock-integration-tests branch to checkout. This one it's optional, if it's needed
to use a different branch for the rootstock-integration-test. It's offered the possibility
to use a different one, but the default and most frequently used, should be `main`.

### `rit-log-level`

**Optional** Log level for the rootstock-integration-tests. Default is `info`.

## Outputs
The output of the action are basically two values, one is the status of the integration tests, and the other is the message.
I
### `status`

The status of the integration tests. It would be `0` for success and `1` for failure.

### `message`

The output message of the integration tests. It will be:
- In case of success: `Rootstock Integration Tests Status: PASSED`
- In case of error: `Rootstock Integration Tests Status: FAILED`

## Example usage

```yaml
uses: rootstock-integration-tests@v1
with:
rskj-branch: master
powpeg-node-branch: master
rit-branch: main
```
36 changes: 36 additions & 0 deletions container-action/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Rootstock Integration Tests Action'
description: 'This action provides a containerized environment for running integration tests on Rootstock.'
author: 'Rootstock Labs'

inputs:
rskj-branch:
description: 'The rskj branch to checkout'
required: true
default: 'master'
powpeg-node-branch:
description: 'The powpeg-node branch to checkout'
required: true
default: 'master'
rit-branch:
description: 'The rootstock-integration-tests branch to checkout'
required: false
default: 'main'
rit-log-level:
description: 'Log level for the rootstock-integration-tests'
required: false
default: 'info'

outputs:
status:
description: 'The status of the integration tests'
message:
description: 'The output message of the integration tests'

runs:
using: docker
image: Dockerfile
env:
INPUT_RSKJ_BRANCH: ${{ inputs.rskj-branch }}
INPUT_POWPEG_NODE_BRANCH: ${{ inputs.powpeg-node-branch }}
INPUT_RIT_BRANCH: ${{ inputs.rit-branch }}
INPUT_RIT_LOG_LEVEL: ${{ inputs.rit-log-level }}
65 changes: 65 additions & 0 deletions container-action/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/sh -l

set -e
RSKJ_BRANCH="${INPUT_RSKJ_BRANCH}"
POWPEG_NODE_BRANCH="${INPUT_POWPEG_NODE_BRANCH}"
RIT_BRANCH="${INPUT_RIT_BRANCH}"
LOG_LEVEL="${INPUT_RIT_LOG_LEVEL}"

echo -e "\n\n--------- Input parameters received ---------\n\n"
echo "RSKJ_BRANCH=$RSKJ_BRANCH"
echo "POWPEG_NODE_BRANCH=$POWPEG_NODE_BRANCH"
echo "RIT_BRANCH=$RIT_BRANCH"
echo "LOG_LEVEL=$LOG_LEVEL"

echo -e "\n\n--------- Starting the configuration of rskj ---------\n\n"
cd /usr/src/
git clone https://github.com/rsksmart/rskj.git rskj
cd rskj && git checkout "$RSKJ_BRANCH"
chmod +x ./configure.sh && chmod +x gradlew
./configure.sh

echo -e "\n\n--------- Starting the configuration of powpeg ---------\n\n"
cd /usr/src/
git clone https://github.com/rsksmart/powpeg-node.git powpeg
cp configure_gradle_powpeg.sh powpeg
cd powpeg && git checkout "$POWPEG_NODE_BRANCH"
chmod +x ./configure.sh && chmod +x gradlew
POWPEG_VERSION=$(bash configure_gradle_powpeg.sh)
echo "POWPEG_VERSION=$POWPEG_VERSION"
./configure.sh
./gradlew --info --no-daemon clean build -x test

echo -e "\n\n--------- Starting the configuration of RIT ---------\n\n"
cd /usr/src/
git clone https://github.com/rsksmart/rootstock-integration-tests.git rit
mv configure_rit_locally.sh rit
mv regtest.js rit/config/regtest.js
mv /usr/src/logbacks/* /usr/src/rit/logbacks/
cd rit
git checkout "$RIT_BRANCH"
chmod +x ./configure.sh
./configure.sh
./configure_rit_locally.sh "${POWPEG_VERSION}"
export LOG_LEVEL="$LOG_LEVEL"

echo -e "\n\n--------- Executing Rootstock Integration Tests ---------\n\n"
npm install -y
npm run test-fail-fast
STATUS=$?

echo -e "\n\n--------- RIT Tests Result ---------\n\n"
if [ $STATUS -ne 0 ]; then
MESSAGE="Rootstock Integration Tests Status: FAILED"
else
MESSAGE="Rootstock Integration Tests Status: PASSED"
fi
echo -e "$MESSAGE"

echo "status=${STATUS}" >> "${GITHUB_OUTPUT}"
echo "message=${MESSAGE}" >> "${GITHUB_OUTPUT}"

if [ $STATUS -ne 0 ]; then
exit 1
fi
exit 0
Loading