Skip to content

[ci] Move CI to GHA #10

[ci] Move CI to GHA

[ci] Move CI to GHA #10

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# common variable is defined in the workflow
# repo env variable doesn't work for PR from forks
env:
CI_IMAGE: "paritytech/ci-unified:bullseye-1.75.0-2024-01-22-v20240222"
jobs:
set-image:
# This workaround sets the container image for each job using 'set-image' job output.
# env variables don't work for PR from forks, so we need to use outputs.
runs-on: ubuntu-latest
outputs:
CI_IMAGE: ${{ steps.set_image.outputs.CI_IMAGE }}
steps:
- id: set_image
run: echo "CI_IMAGE=${{ env.CI_IMAGE }}" >> $GITHUB_OUTPUT
fmt:
name: Cargo fmt
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [set-image]
container:
image: ${{ needs.set-image.outputs.CI_IMAGE }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true
- name: cargo info
run: |
echo "######## rustup show ########"
rustup show
echo "######## cargo --version ########"
cargo --version
- name: Cargo fmt
run: cargo +nightly fmt --all -- --check
build-test-linux:
name: Build Linux
runs-on: parity-large
timeout-minutes: 30
needs: [set-image, fmt]
container:
image: ${{ needs.set-image.outputs.CI_IMAGE }}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true
- name: cargo info
run: |
echo "######## rustup show ########"
rustup show
echo "######## cargo --version ########"
cargo --version
- name: Build and Test Linux
run: |
echo "######## cargo build ########"
cargo build --release
echo "######## cargo test ########"
cargo test --release --all
echo "######## Packing artifacts ########"
mkdir -p ./artifacts/substrate-contracts-node-linux/
cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node
ls -la ./artifacts/substrate-contracts-node-linux/
- name: Upload artifacts
uses: actions/[email protected]
with:
name: build-linux
path: ./artifacts
build-macos:
timeout-minutes: 30
runs-on: parity-macos
needs: [fmt]
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Set rust version from env file
run: |
echo $CI_IMAGE
RUST_VERSION=$(echo $CI_IMAGE | sed -E 's/.*ci-unified:([^-]+)-([^-]+).*/\2/')
echo $RUST_VERSION
echo "RUST_VERSION=${RUST_VERSION}" >> $GITHUB_ENV
- name: Set up Homebrew
uses: Homebrew/actions/setup-homebrew@1ccc07ccd54b6048295516a3eb89b192c35057dc # master from 12.09.2024
- name: Install protobuf
run: brew install protobuf
- name: Install rust ${{ env.RUST_VERSION }}
uses: actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc # v1.9.0
with:
cache: false
toolchain: ${{ env.RUST_VERSION }}
target: wasm32-unknown-unknown, aarch64-apple-darwin, x86_64-apple-darwin
components: cargo, clippy, rust-docs, rust-src, rustfmt, rustc, rust-std
- name: cargo info
run: |
echo "######## rustup show ########"
rustup show
echo "######## cargo --version ########"
cargo --version
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
with:
cache-on-failure: true
cache-all-crates: true
- name: Run cargo build
run: |
echo "######## cargo build aarch64-apple-darwin ########"
cargo build --release --target aarch64-apple-darwin
echo "######## cargo build x86_64-apple-darwin ########"
cargo build --release --target x86_64-apple-darwin
echo "######## Packing artifacts ########"
mkdir -p ./artifacts/substrate-contracts-node-mac/
lipo ./target/x86_64-apple-darwin/release/substrate-contracts-node \
./target/aarch64-apple-darwin/release/substrate-contracts-node \
-create -output ./artifacts/substrate-contracts-node-mac/substrate-contracts-node
ls -la ./artifacts/substrate-contracts-node-mac/
- name: Upload artifacts
uses: actions/[email protected]
with:
name: build-macos
path: ./artifacts
publish:
name: Publish release
runs-on: ubuntu-latest
needs: [build-test-linux, build-macos]
permissions:
contents: write
steps:
- uses: actions/[email protected]
- uses: actions/download-artifact@v4
with:
name: build-linux
- uses: actions/download-artifact@v4
with:
name: build-mac
- name: Pack artifacts
run: |
tar -czvf ./substrate-contracts-node-linux.tar.gz ./substrate-contracts-node-linux
tar -czvf ./substrate-contracts-node-mac-universal.tar.gz ./substrate-contracts-node-mac
ls -la
- name: Publish release
uses: ghalactic/github-release-from-tag@v5
if: github.ref_type == 'tag'
with:
prerelease: false
draft: true
assets: |
- path: substrate-contracts-node-linux.tar.gz
- path: substrate-contracts-node-mac-universal.tar.gz