From 3662b8f407edc35dddd4cfff177b6b9851e0e05c Mon Sep 17 00:00:00 2001 From: h3rt <94856309+SecretSaturn@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:39:44 +0200 Subject: [PATCH] Make docker image build dependent on passing test --- .github/workflows/CI.yml | 210 +++++++++++++++++++++ .github/workflows/Docker_image.yml | 54 ------ .github/workflows/Foundry_tests.yml | 42 ----- .github/workflows/Secret_gateway_tests.yml | 114 ----------- 4 files changed, 210 insertions(+), 210 deletions(-) create mode 100644 .github/workflows/CI.yml delete mode 100644 .github/workflows/Docker_image.yml delete mode 100644 .github/workflows/Foundry_tests.yml delete mode 100644 .github/workflows/Secret_gateway_tests.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..cc175ec --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,210 @@ +name: Continuous Integration + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "TNLS-Relayers/**" + - "TNLS-Gateways/public-gateway/**" + - "TNLS-Gateways/secret/**" + - ".github/workflows/ci.yml" + pull_request: + branches: + - main + paths: + - "TNLS-Relayers/**" + - "TNLS-Gateways/public-gateway/**" + - "TNLS-Gateways/secret/**" + - ".github/workflows/ci.yml" + +jobs: + foundry_tests: + name: Foundry Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Install forge dependencies + working-directory: TNLS-Gateways/public-gateway + run: forge install + + - name: Run tests + working-directory: TNLS-Gateways/public-gateway + run: forge test -vvv + + - name: Check gas snapshots + working-directory: TNLS-Gateways/public-gateway + run: forge snapshot --check --tolerance 1 + + secret_gateway_tests: + name: Secret Gateway Tests + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + target: + - x86_64-unknown-linux-gnu + - wasm32-unknown-unknown + env: + CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - uses: mozilla-actions/sccache-action@v0.0.5 + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + + - name: Build + working-directory: TNLS-Gateways/secret + run: cargo build --target ${{ matrix.target }} --no-default-features --release + + secret_unit_tests: + name: Secret Gateway Unit Tests + runs-on: ubuntu-latest + needs: secret_gateway_tests + strategy: + matrix: + rust: + - stable + env: + CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - uses: mozilla-actions/sccache-action@v0.0.5 + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Run Unit Tests + working-directory: TNLS-Gateways/secret + run: cargo test --release + + secret_integration_tests: + name: Secret Gateway Integration Tests + runs-on: ubuntu-latest + needs: secret_unit_tests + services: + secret: + image: ghcr.io/scrtlabs/localsecret:v1.13.3 + ports: + - 1317:1317 + - 5000:5000 + - 9091:9091 + - 26657:26657 + env: + CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + steps: + - uses: actions/checkout@v4 + + - uses: actions/cache@v4 + with: + path: | + ~/.cargo + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + + - uses: mozilla-actions/sccache-action@v0.0.5 + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + target: wasm32-unknown-unknown + + - name: Install dependencies + working-directory: TNLS-Gateways/secret + run: npm --prefix tests/ install + + - name: Install latest Binaryen + run: | + BINARYEN_VERSION=version_118 + wget https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz + tar -xzf binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz + sudo mv binaryen-${BINARYEN_VERSION} /usr/local/binaryen + echo "/usr/local/binaryen/bin" >> $GITHUB_PATH + + - name: Verify installation + run: wasm-opt --version + + - name: Build wasm contract + working-directory: TNLS-Gateways/secret + run: make build-mainnet + + - name: Run integration tests + working-directory: TNLS-Gateways/secret + run: make integration-test + + build_and_push: + name: Build and Push Docker Image + runs-on: ubuntu-latest + needs: + - foundry_tests + - secret_integration_tests + env: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + IMAGE_NAME: secretpath + IMAGE_TAG: latest + DOCKER_BUILDKIT: 1 + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and Push Docker Image + working-directory: TNLS-Relayers + run: | + docker compose build --pull + docker compose push diff --git a/.github/workflows/Docker_image.yml b/.github/workflows/Docker_image.yml deleted file mode 100644 index f21ae8e..0000000 --- a/.github/workflows/Docker_image.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Build and Push Docker Image - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - "TNLS-Relayers/**" - - ".github/workflows/Docker_image.yml" - pull_request: - branches: - - main - paths: - - "TNLS-Relayers/**" - - ".github/workflows/Docker_image.yml" - -jobs: - build_and_push: - runs-on: ubuntu-latest - - env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - IMAGE_NAME: secretpath - IMAGE_TAG: latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and Push Docker Image - working-directory: TNLS-Relayers - run: | - docker compose build --pull - docker compose push - env: - DOCKER_BUILDKIT: 1 diff --git a/.github/workflows/Foundry_tests.yml b/.github/workflows/Foundry_tests.yml deleted file mode 100644 index c38707b..0000000 --- a/.github/workflows/Foundry_tests.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Foundry Tests - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - "TNLS-Gateways/public-gateway/**" - - ".github/workflows/Foundry_tests.yml" - pull_request: - branches: - - main - paths: - - "TNLS-Gateways/public-gateway/**" - - ".github/workflows/Foundry_tests.yml" - -jobs: - tests: - name: TNLS Ethereum gateway - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Install Foundry - uses: foundry-rs/foundry-toolchain@v1 - with: - version: nightly - - - name: Install forge dependencies - working-directory: TNLS-Gateways/public-gateway - run: forge install - - - name: Run tests - working-directory: TNLS-Gateways/public-gateway - run: forge test -vvv - - - name: Check gas snapshots - working-directory: TNLS-Gateways/public-gateway - run: forge snapshot --check --tolerance 1 diff --git a/.github/workflows/Secret_gateway_tests.yml b/.github/workflows/Secret_gateway_tests.yml deleted file mode 100644 index 8c323f7..0000000 --- a/.github/workflows/Secret_gateway_tests.yml +++ /dev/null @@ -1,114 +0,0 @@ -name: Secret Gateway Tests - -on: - workflow_dispatch: - push: - branches: - - main - paths: - - "TNLS-Gateways/secret/**" - - ".github/workflows/Secret_gateway_tests.yml" - pull_request: - branches: - - main - paths: - - "TNLS-Gateways/secret/**" - - ".github/workflows/Secret_gateway_tests.yml" - -defaults: - run: - working-directory: TNLS-Gateways/secret - -env: - CARGO_TERM_COLOR: always - # RUSTFLAGS: -Dwarnings - # RUSTDOCFLAGS: -Dwarnings - SCCACHE_GHA_ENABLED: "true" - RUSTC_WRAPPER: "sccache" - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - target: - - x86_64-unknown-linux-gnu - - wasm32-unknown-unknown - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 - with: - path: | - ~/.cargo - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- - - uses: mozilla-actions/sccache-action@v0.0.5 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - - run: cargo build --target ${{ matrix.target }} --no-default-features --release - - unit-tests: - runs-on: ubuntu-latest - strategy: - matrix: - rust: - - stable - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 - with: - path: | - ~/.cargo - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- - - uses: mozilla-actions/sccache-action@v0.0.5 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} - - run: cargo test --release - - integration_tests: - runs-on: ubuntu-latest - services: - secret: - image: ghcr.io/scrtlabs/localsecret:v1.13.3 - ports: - - 1317:1317 - - 5000:5000 - - 9091:9091 - - 26657:26657 - steps: - - uses: actions/checkout@v4 - - uses: actions/cache@v4 - with: - path: | - ~/.cargo - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- - - uses: mozilla-actions/sccache-action@v0.0.5 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: stable - target: wasm32-unknown-unknown - - name: Install dependencies - run: npm --prefix tests/ install - - name: Install latest Binaryen - run: | - BINARYEN_VERSION=version_118 - wget https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VERSION}/binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz - tar -xzf binaryen-${BINARYEN_VERSION}-x86_64-linux.tar.gz - sudo mv binaryen-${BINARYEN_VERSION} /usr/local/binaryen - echo "/usr/local/binaryen/bin" >> $GITHUB_PATH - - name: Verify installation - run: wasm-opt --version - - name: Build wasm contract - run: make build-mainnet - - name: Run integration tests - run: make integration-test