Skip to content

Commit

Permalink
Enhance CI (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
clangenb authored May 25, 2024
1 parent 11ab733 commit e17dd0e
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 297 deletions.
47 changes: 0 additions & 47 deletions .github/scripts/free_disk_space.sh

This file was deleted.

216 changes: 195 additions & 21 deletions .github/workflows/check-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
push:
branches:
- develop
tags:
- v[0-9]+.[0-9]+.[0-9]
# Matches tags containing an arbitrary suffix starting with '-'.
- v[0-9]+.[0-9]+.[0-9]+-*

# Ensures only one build is run per branch, unless pushing to develop
concurrency:
Expand Down Expand Up @@ -42,11 +46,9 @@ jobs:
continue-on-error: false
steps:
- uses: actions/checkout@v4
- run: ./.github/scripts/free_disk_space.sh
- run: sudo apt-get install -y protobuf-compiler

- name: Fetch cache
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0
uses: Swatinem/rust-cache@v2
with:
# consistent cache across jobs
shared-key: "bajun-cache-cargo-debug"
Expand All @@ -71,28 +73,98 @@ jobs:
run: cargo install --locked -q zepter && zepter --version

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0 # Don't clone historic commits.

- name: Check features
run: zepter run check

build-runtimes:
name: Build Runtimes
runs-on: ubuntu-latest
strategy:
matrix:
runtime: [ "bajun" ]
steps:
- uses: actions/checkout@v4

- name: Cache target dir
uses: actions/cache@v4
with:
save-always: true
path: "${{ github.workspace }}/runtime/${{ matrix.runtime }}/target"
key: srtool-target-${{ matrix.runtime }}-${{ github.sha }}
restore-keys: |
srtool-target-${{ matrix.runtime }}-
srtool-target-
- name: Build ${{ matrix.runtime }}
id: srtool_build
uses: chevdor/srtool-actions@v0.9.2
with:
image: paritytech/srtool
chain: ${{ matrix.runtime }}
runtime_dir: runtime/${{ matrix.runtime }}
profile: "production"

- name: Store ${{ matrix.runtime }} srtool digest to disk
run: |
echo '${{ steps.srtool_build.outputs.json }}' | jq > ${{ matrix.runtime }}_srtool_output.json
- name: Upload ${{ matrix.runtime }} srtool json
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.runtime }}-srtool-json
path: ${{ matrix.runtime }}_srtool_output.json

- name: Upload ${{ matrix.runtime }}-runtime
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.runtime }}-runtime-${{ github.sha }}
path: |
${{ steps.srtool_build.outputs.wasm_compressed }}
build-binary:
name: Build Release Binary
runs-on: ubuntu-latest
continue-on-error: false

steps:
- uses: actions/checkout@v4

- name: Install Protoc
uses: arduino/setup-protoc@v3

- name: Fetch cache
uses: Swatinem/rust-cache@v2
with:
# consistent cache across jobs
shared-key: "bajun-cache-cargo-release"
cache-on-failure: true

- name: Build release binary
run: cargo build --release --locked

- name: Upload bajun-node
uses: actions/upload-artifact@v4
with:
name: bajun-node-${{ github.sha }}
path: target/release/bajun-node

test:
name: Cargo test (all features)
runs-on: ubuntu-latest
continue-on-error: false

steps:
- uses: actions/checkout@v4
- run: ./.github/scripts/free_disk_space.sh
- run: sudo apt-get install -y protobuf-compiler

- name: Fetch cache
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0
uses: Swatinem/rust-cache@v2
with:
# consistent cache across jobs
shared-key: "bajun-cache-cargo-release"
shared-key: "bajun-cache-cargo-test"
cache-on-failure: true

- run: cargo test --release --all-features --all-targets
Expand All @@ -103,6 +175,7 @@ jobs:
zombienet-tests:
name: Zombienet tests
runs-on: ubuntu-latest
needs: [ build-binary ]
strategy:
matrix:
binary: [ bajun-node ]
Expand All @@ -128,22 +201,123 @@ jobs:
- name: Copy network config and tests
run: cp .maintain/zombienet-* zombienet-tests/

- name: Install Protoc
uses: arduino/setup-protoc@v1
- uses: actions/download-artifact@v4
with:
version: "3.6.1"
name: bajun-node-${{ github.sha }}

- name: Fetch cache
uses: Swatinem/rust-cache@a95ba195448af2da9b00fb742d14ffaaf3c21f43 # v2.7.0
with:
# consistent cache across jobs
shared-key: "bajun-cache-zombienet"
cache-on-failure: true

- name: Build and copy collator binary to zombienet binaries
- name: 'Setup Bajun-Node'
run: |
cargo build --release
cp target/release/${{ matrix.binary }} zombienet-tests/bin/collator
chmod +x ./bajun-node
cp ./bajun-node zombienet-tests/bin/collator
- name: Run zombienet tests
run: ./zombienet-tests/bin/zombienet -l "text" -p native test ./zombienet-tests/zombienet-tests.zndsl

publish-release:
name: Publish Release
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
needs: [ build-binary ]
outputs:
release_url: ${{ steps.create-release.outputs.html_url }}
asset_upload_url: ${{ steps.create-release.outputs.upload_url }}
steps:
- uses: actions/checkout@v4

- name: Download Bajun Collator
uses: actions/download-artifact@v4
with:
name: bajun-node-${{ github.sha }}

- name: Download srtool json output
uses: actions/download-artifact@v4

- name: Archive context output
uses: actions/upload-artifact@v4
with:
name: release-notes-context
path: |
**/*_srtool_output.json
# Adapted version from fellowship runtimes
- name: Add runtime info to changelog
run: |
CONTEXT=$(find . -name '*_srtool_output.json')
SRTOOL() { <$(<<<$CONTEXT head -n1) jq -r .$1; }
WASM() { <${JSON} jq -r ".runtimes.compressed.subwasm.$1"; }
touch DRAFT
tee -a DRAFT <<-EOF
# Runtime info
*These runtimes were built with **$(SRTOOL rustc)** using **[$(SRTOOL gen)](https://github.com/paritytech/srtool)***
\`\`\`sh
srtool build
--root --profile production
--package CRATE_NAME --runtime-dir PATH_TO_CRATE
\`\`\`
EOF
for JSON in $(<<<$CONTEXT sort -sr)
do
SPEC_NAME=$(WASM 'core_version.specName')
HEADING=$(WASM 'core_version.specName / "-" | map(. / "" | first |= ascii_upcase | add) | join(" ")')
tee -a DRAFT <<-EOF
## $HEADING
~~~
🏋️ Runtime Size: $(numfmt --to iec-i --format "%.2f" $(WASM size)) ($(WASM size) bytes)
🗜 Compressed: $(WASM 'compression | if .compressed then "Yes: \(1 - .size_compressed / .size_decompressed | . * 10000 | round / 100)%" else "No" end')
🔥 Core Version: $(WASM 'core_version | "\(.specName)-\(.specVersion) \(.implName)-\(.implVersion).tx\(.transactionVersion).au\(.authoringVersion)"')
🎁 Metadata version: V$(WASM metadata_version)
🗳️ Blake2-256 hash: $(WASM blake2_256)
📦 IPFS: $(WASM ipfs_hash)
~~~
EOF
done
- name: Release
id: create-release
uses: softprops/action-gh-release@v2
# Generate relase notes with commit history and append srtool output from above.
with:
draft: true
generate_release_notes: true
append_body: true
body_path: DRAFT
files: |
bajun-node
publish-runtimes:
name: Publish Runtimes
needs: [ publish-release ]
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
runtime: [ bajun ]
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v4

- name: Get runtime info
env:
JSON: release-notes-context/${{ matrix.runtime }}-srtool-json/${{ matrix.runtime }}_srtool_output.json
run: |
>>$GITHUB_ENV echo SPEC=$(<${JSON} jq -r .runtimes.compact.subwasm.core_version.specVersion)
- name: Upload compressed ${{ matrix.runtime }} v${{ env.SPEC }} wasm
uses: shogo82148/actions-upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.publish-release.outputs.asset_upload_url }}
asset_path: "${{ matrix.runtime }}-runtime-${{ github.sha }}/${{ matrix.runtime }}_runtime.compact.compressed.wasm"
asset_name: ${{ matrix.runtime }}_runtime-v${{ env.SPEC }}.compact.compressed.wasm
asset_content_type: application/wasm
74 changes: 74 additions & 0 deletions .github/workflows/publish-docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Publish Docker image for new releases

on:
release:
types:
- published

jobs:
main:
name: Push to Dockerhub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Download bajun-node from release
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "tags/${{ github.event.release.tag_name }}"
file: "bajun-node"
target: "bajun-node"
token: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- 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: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
push: true
context: .
file: docker/Dockerfile
tags: |
ajuna/parachain-bajun:latest
ajuna/parachain-bajun:${{ github.event.release.tag_name }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}

release-onf:
needs: release-docker
runs-on: ubuntu-latest
strategy:
matrix:
runtime: [ bajun ]
include:
- runtime: bajun
network_key: ONF_BAJUN_NETWORK_KEY
steps:
- uses: OnFinality-io/action-onf-release@v1
with:
onf-access-key: ${{ secrets.ONF_ACCESS_KEY }}
onf-secret-key: ${{ secrets.ONF_SECRET_KEY }}
onf-workspace-id: ${{ secrets.ONF_WORKSPACE_ID }}
onf-network-key: ${{ secrets[matrix.network_key] }}
onf-sub-command: image
onf-action: add
image-version: ${{ github.event.release.tag_name }}
Loading

0 comments on commit e17dd0e

Please sign in to comment.