Skip to content

test: goreleaser

test: goreleaser #14

name: Smart Contract CI
# Smart Contract CI workflow runs CI test for checking if smart contract works well
# This workflow is run on pushes to main & every Pull Requests where a .go, .mod, .sum, ci_test/**.sh, and this file have been changed
on:
pull_request:
push:
branches:
- main
env:
TEST_DOCKER_IMAGE: finschianode:smartcontractci
GO_VERSION: "1.20"
jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"
check-diffs:
runs-on: ubuntu-latest
outputs:
get_diff: ${{ steps.diff.outputs.diff }}
steps:
- uses: actions/checkout@v3
- name: Get diff
id: diff
uses: technote-space/get-diff-action@v6.1.2
with:
PATTERNS: |
**/**.go
go.mod
go.sum
.github/workflows/ci-smart-contract.yml
ci_test/**
get-cosmwasm-releases:
runs-on: ubuntu-latest
outputs:
cosmwasm_versions: ${{ steps.releases.outputs.versions }}
steps:
- uses: actions/checkout@v3
- name: Get cosmwasm releases
id: releases
run: |
response=$(curl -s "https://api.github.com/repos/Finschia/cosmwasm/releases")
versions=$(echo "$response" | jq -r '[.[].tag_name]' | jq -c .)
echo "versions=${versions}" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
needs: check-diffs
if: ${{ needs.check-diffs.outputs.get_diff }}
strategy:
matrix:
go-arch: ["amd64"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false LINK_STATICALLY=true make build
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: fnsad
path: ./build/fnsad
test-smart-contract-on-local-node:
runs-on: ubuntu-latest
needs: [build, get-cosmwasm-releases]
strategy:
fail-fast: false
matrix:
versions: ${{ fromJson(needs.get-cosmwasm-releases.outputs.cosmwasm_versions) }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Download smart contracts
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'Finschia/cosmwasm'
version: tags/${{ matrix.versions }}
regex: true
file: '.*'
target: 'contracts/'
- name: Download build
uses: actions/download-artifact@v3
with:
name: fnsad
path: ./build
- name: Build install
run: make install
- name: Set configure file
run: ./init_single.sh
shell: bash
# sleep 1 second to wait for finschia to start up
- name: Start local node
id: start
run: |
fnsad start &
sleep 1
- name: CI test
run: bash ./ci_test/queue_ci.sh
shell: bash
- name: Stop local node
if: ${{ always() && steps.start.conclusion == 'success' }}
run: kill $(ps -ef | grep "fnsad start" | grep -v grep | awk '{print $2}')
build-finschia-docker-image:
runs-on: ubuntu-latest
needs: check-diffs
if: ${{ needs.check-diffs.outputs.get_diff }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: Build and export
uses: docker/build-push-action@v4
with:
file: Dockerfile
context: .
tags: ${{ env.TEST_DOCKER_IMAGE }}
outputs: type=docker,dest=/tmp/finschia-ci-test.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: finschia-ci-test
path: /tmp/finschia-ci-test.tar
test-smart-contract-in-docker-container:
runs-on: ubuntu-latest
needs: [build-finschia-docker-image, get-cosmwasm-releases]
strategy:
fail-fast: false
matrix:
versions: ${{ fromJson(needs.get-cosmwasm-releases.outputs.cosmwasm_versions) }}
steps:
- uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: Download smart contracts
uses: dsaltares/fetch-gh-release-asset@master
with:
repo: 'Finschia/cosmwasm'
version: tags/${{ matrix.versions }}
regex: true
file: '.*'
target: 'contracts/'
- name: Download docker image
uses: actions/download-artifact@v3
with:
name: finschia-ci-test
path: /tmp
- name: Load image
run: |
docker load --input /tmp/finschia-ci-test.tar
docker image ls -a
- name: Set configure file
run: |
export FNSAD="docker run -i --rm -p 26656:26656 -p 26657:26657 -v ${pwd}/.finschia:/root/.finschia ${{ env.TEST_DOCKER_IMAGE }} fnsad"
./init_single.sh
shell: bash
# sleep 5 seconds to wait for finschia to start up
- name: Start docker container
id: docker_start
run: |
container_id=$(docker run -d \
-p 26656:26656 -p 26657:26657 \
-v ${pwd}/.finschia:/root/.finschia \
-v $(pwd)/ci_test:/root/ci_test \
-v $(pwd)/contracts:/root/contracts \
${{ env.TEST_DOCKER_IMAGE }} fnsad start)
echo "container_id=$container_id" >> "$GITHUB_OUTPUT"
sleep 5
- name: CI test
run: |
docker exec ${{ steps.docker_start.outputs.container_id }} apk add --no-cache jq bash && \
docker exec ${{ steps.docker_start.outputs.container_id }} bash ./ci_test/queue_ci.sh
- name: Stop docker container
if: ${{ always() && steps.docker_start.conclusion == 'success' }}
run: docker stop ${{ steps.docker_start.outputs.container_id }}