Skip to content

Commit dc8c0cc

Browse files
committed
Add back CI
1 parent b51c5e6 commit dc8c0cc

1 file changed

Lines changed: 241 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- perm-*
9+
10+
jobs:
11+
set-tags:
12+
runs-on: ubuntu-22.04
13+
outputs:
14+
image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
15+
git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
16+
sha: ${{ steps.get-sha.outputs.sha }}
17+
sha8: ${{ steps.get-sha.outputs.sha8 }}
18+
latest_rt: ${{ steps.get-sha.outputs.latest_rt }}
19+
latest_rt_sha8: ${{ steps.get-sha.outputs.latest_rt_sha8 }}
20+
steps:
21+
- name: Check git ref
22+
id: check-git-ref
23+
# if PR
24+
# else if manual PR
25+
# else (push)
26+
run: |
27+
if [[ -n "${{ github.event.pull_request.head.sha }}" ]]; then
28+
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
29+
echo "git_ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT
30+
elif [[ -n "${{ github.event.inputs.pull_request }}" ]]; then
31+
echo "git_branch=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_OUTPUT
32+
echo "git_ref=refs/pull/${{ github.event.inputs.pull_request }}/head" >> $GITHUB_OUTPUT
33+
else
34+
echo "git_branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
35+
echo "git_ref=$GITHUB_REF" >> $GITHUB_OUTPUT
36+
fi
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
with:
40+
ref: ${{ steps.check-git-ref.outputs.git_ref }}
41+
- name: Get Latest RT Release
42+
id: get-latest-rt
43+
run: |
44+
LATEST_RUNTIME_RELEASE=$(curl -s https://api.github.com/repos/moondance-labs/tanssi/releases | jq -r '.[] | select(.name | test("runtime";"i")) | .tag_name' | head -n 1 | tr -d '[:blank:]') && [[ ! -z "${LATEST_RUNTIME_RELEASE}" ]]
45+
echo $LATEST_RUNTIME_RELEASE
46+
echo "latest_rt=$LATEST_RUNTIME_RELEASE" >> $GITHUB_OUTPUT
47+
- name: Get Sha
48+
id: get-sha
49+
run: |
50+
echo "sha=$(git log -1 --format='%H')" >> $GITHUB_OUTPUT
51+
echo "sha8=$(git log -1 --format='%H' | cut -c1-8)" >> $GITHUB_OUTPUT
52+
53+
ENDPOINT="https://api.github.com/repos/moondance-labs/tanssi/git/refs/tags/${{ steps.get-latest-rt.outputs.latest_rt }}"
54+
RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $ENDPOINT)
55+
TYPE=$(echo $RESPONSE | jq -r '.object.type')
56+
57+
if [[ $TYPE == "commit" ]]
58+
then
59+
LATEST_RT_SHA8=$(echo $RESPONSE | jq -r '.object.sha' | cut -c -8)
60+
elif [[ $TYPE == "tag" ]]
61+
then
62+
URL=$(echo $RESPONSE | jq -r '.object.url')
63+
TAG_RESPONSE=$(curl -s -H "Accept: application/vnd.github.v3+json" $URL)
64+
TAG_RESPONSE_CLEAN=$(echo $TAG_RESPONSE | tr -d '\000-\037')
65+
LATEST_RT_SHA8=$(echo $TAG_RESPONSE_CLEAN | jq -r '.object.sha' | cut -c -8)
66+
fi
67+
68+
echo $LATEST_RT_SHA8
69+
echo "latest_rt_sha8=$LATEST_RT_SHA8" >> $GITHUB_OUTPUT
70+
71+
- name: Check existing docker image
72+
id: check-docker-image
73+
run: |
74+
TAG=sha-${{ steps.get-sha.outputs.sha8 }}
75+
echo "image_exists=$(docker image inspect moondancelabs/tanssi:$TAG > /dev/null && echo "true" || echo "false")" >> $GITHUB_OUTPUT
76+
77+
- name: Display variables
78+
run: |
79+
echo git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
80+
echo sha: ${{ steps.get-sha.outputs.sha }}
81+
echo sha8: ${{ steps.get-sha.outputs.sha8 }}
82+
echo image_exists: ${{ steps.check-docker-image.outputs.image_exists }}
83+
echo latest_rt: ${{ steps.get-latest-rt.outputs.latest_rt }}
84+
echo latest_rt_sha8: ${{ steps.get-sha.outputs.latest_rt_sha8 }}
85+
86+
####### Static Analyses #######
87+
cargo-clippy:
88+
runs-on: ubuntu-22.04
89+
needs: ["set-tags"]
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v3
93+
with:
94+
ref: ${{ needs.set-tags.outputs.git_ref }}
95+
96+
- name: Setup Rust toolchain
97+
run: rustup show
98+
99+
- name: Checkout tanssi repo
100+
run: |
101+
cd ..
102+
git clone --depth 1 https://github.com/moondance-labs/tanssi
103+
cd -
104+
105+
- name: Install protoc
106+
run: |
107+
sudo apt-get update
108+
sudo apt-get install -y protobuf-compiler
109+
110+
- name: Clippy
111+
run: |
112+
cd fuzz
113+
SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo clippy --all-targets --locked --workspace
114+
115+
toml-formatting:
116+
runs-on: ubuntu-22.04
117+
needs: ["set-tags"]
118+
steps:
119+
- name: Checkout
120+
uses: actions/checkout@v3
121+
with:
122+
ref: ${{ needs.set-tags.outputs.git_ref }}
123+
124+
- name: Setup Rust toolchain
125+
run: rustup show
126+
127+
- name: Install toml-maid
128+
run: cargo install --locked -f toml-maid
129+
130+
- name: Run toml-maid
131+
run: toml-maid --check
132+
133+
####### Building and Testing binaries #######
134+
135+
build:
136+
runs-on: ubuntu-22.04
137+
needs: ["set-tags"]
138+
env:
139+
TMP_TARGET: "/tmp/target"
140+
CARGO_TARGET_DIR: "target"
141+
steps:
142+
- name: Checkout
143+
uses: actions/checkout@v3
144+
with:
145+
ref: ${{ needs.set-tags.outputs.git_ref }}
146+
- name: Run sccache-cache
147+
uses: mozilla-actions/sccache-action@v0.0.9
148+
- name: Setup Variables
149+
shell: bash
150+
run: |
151+
echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV
152+
echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV
153+
echo "SCCACHE_CACHE_SIZE=100GB" >> $GITHUB_ENV
154+
- name: Setup Rust toolchain
155+
run: rustup show
156+
- name: Checkout tanssi repo
157+
run: |
158+
cd ..
159+
git clone --depth 1 https://github.com/moondance-labs/tanssi
160+
cd -
161+
- name: Formatter
162+
run: cargo fmt --all --check
163+
- name: Install protoc
164+
run: |
165+
sudo apt-get update
166+
sudo apt-get install -y protobuf-compiler
167+
- name: Install cargo-fuzz
168+
# Use custom version from github because the latest release is too old
169+
run: cargo install cargo-fuzz --git https://github.com/rust-fuzz/cargo-fuzz --rev 65e3279c9602375037cb3aaabd3209c5b746375c
170+
- name: Build
171+
run: |
172+
cd fuzzers/fuzz-dancelight/fuzz
173+
SKIP_WASM_BUILD=1 cargo fuzz build fuzz_live_oneblock --build-std
174+
SKIP_WASM_BUILD=1 cargo fuzz build fuzz_zombie --build-std
175+
176+
#strip target/x86_64-unknown-linux-gnu/release/fuzz_starlight
177+
#strip target/x86_64-unknown-linux-gnu/release/fuzz_starlight_live
178+
#cd ..
179+
#mkdir binaries
180+
#mv fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_starlight binaries/
181+
#mv fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_starlight_live binaries/
182+
- name: Upload binary
183+
uses: actions/upload-artifact@v4
184+
with:
185+
name: binaries
186+
path: binaries
187+
188+
docker-tanssi:
189+
runs-on: ubuntu-22.04
190+
needs: ["set-tags", "build"]
191+
strategy:
192+
matrix:
193+
image: ["tanssi", "container-chain-simple-template", "container-chain-evm-template"]
194+
if: ${{ (needs.set-tags.outputs.image_exists == 'false') && (github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push') }}
195+
steps:
196+
- name: Checkout
197+
uses: actions/checkout@v3
198+
with:
199+
ref: ${{ needs.set-tags.outputs.git_ref }}
200+
- uses: actions/download-artifact@v4
201+
with:
202+
name: binaries
203+
path: build
204+
merge-multiple: true
205+
- name: Prepare
206+
id: prep
207+
run: |
208+
DOCKER_IMAGE=moondancelabs/${{matrix.image}}
209+
TAGS="${DOCKER_IMAGE}:sha-${{ needs.set-tags.outputs.sha8 }}"
210+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
211+
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
212+
- name: Set up QEMU
213+
uses: docker/setup-qemu-action@v2.1.0
214+
- name: Set up Docker Buildx
215+
uses: docker/setup-buildx-action@v2.5.0
216+
with:
217+
version: latest
218+
driver-opts: |
219+
image=moby/buildkit:master
220+
- name: Login to DockerHub
221+
uses: docker/login-action@v2.2.0
222+
with:
223+
username: ${{ secrets.DOCKERHUB_USERNAME }}
224+
password: ${{ secrets.DOCKERHUB_TOKEN }}
225+
- name: Build and push
226+
id: docker_build
227+
uses: docker/build-push-action@v4
228+
with:
229+
context: .
230+
file: ./docker/${{matrix.image}}.Dockerfile
231+
platforms: linux/amd64
232+
push: true
233+
tags: ${{ steps.prep.outputs.tags }}
234+
labels: |
235+
org.opencontainers.image.title=${{ github.event.repository.name }}
236+
org.opencontainers.image.description=${{ github.event.repository.description }}
237+
org.opencontainers.image.url=${{ github.event.repository.html_url }}
238+
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
239+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
240+
org.opencontainers.image.revision=${{ github.sha }}
241+
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}

0 commit comments

Comments
 (0)