|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, reopened, ready_for_review] |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +# common variable is defined in the workflow |
| 15 | +# repo env variable doesn't work for PR from forks |
| 16 | +env: |
| 17 | + CI_IMAGE: "paritytech/ci-unified:bullseye-1.75.0-2024-01-22-v20240222" |
| 18 | + |
| 19 | +jobs: |
| 20 | + set-image: |
| 21 | + # This workaround sets the container image for each job using 'set-image' job output. |
| 22 | + # env variables don't work for PR from forks, so we need to use outputs. |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + CI_IMAGE: ${{ steps.set_image.outputs.CI_IMAGE }} |
| 26 | + steps: |
| 27 | + - id: set_image |
| 28 | + run: echo "CI_IMAGE=${{ env.CI_IMAGE }}" >> $GITHUB_OUTPUT |
| 29 | + |
| 30 | + fmt: |
| 31 | + name: Cargo fmt |
| 32 | + runs-on: ubuntu-latest |
| 33 | + timeout-minutes: 5 |
| 34 | + needs: [set-image] |
| 35 | + container: |
| 36 | + image: ${{ needs.set-image.outputs.CI_IMAGE }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 39 | + - name: Rust Cache |
| 40 | + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 |
| 41 | + with: |
| 42 | + cache-on-failure: true |
| 43 | + cache-all-crates: true |
| 44 | + - name: cargo info |
| 45 | + run: | |
| 46 | + echo "######## rustup show ########" |
| 47 | + rustup show |
| 48 | + echo "######## cargo --version ########" |
| 49 | + cargo --version |
| 50 | + - name: Cargo fmt |
| 51 | + run: cargo +nightly fmt --all -- --check |
| 52 | + |
| 53 | + build-test-linux: |
| 54 | + name: Build Linux |
| 55 | + runs-on: parity-large |
| 56 | + timeout-minutes: 50 |
| 57 | + needs: [set-image, fmt] |
| 58 | + container: |
| 59 | + image: ${{ needs.set-image.outputs.CI_IMAGE }} |
| 60 | + steps: |
| 61 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 62 | + - name: Rust Cache |
| 63 | + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 |
| 64 | + with: |
| 65 | + cache-on-failure: true |
| 66 | + cache-all-crates: true |
| 67 | + - name: cargo info |
| 68 | + run: | |
| 69 | + echo "######## rustup show ########" |
| 70 | + rustup show |
| 71 | + echo "######## cargo --version ########" |
| 72 | + cargo --version |
| 73 | + - name: Build and Test Linux |
| 74 | + run: | |
| 75 | + echo "######## cargo build ########" |
| 76 | + cargo build --release |
| 77 | + echo "######## cargo test ########" |
| 78 | + cargo test --release --all |
| 79 | + echo "######## Packing artifacts ########" |
| 80 | + mkdir -p ./artifacts/substrate-contracts-node-linux/ |
| 81 | + cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node |
| 82 | + ls -la ./artifacts/substrate-contracts-node-linux/ |
| 83 | + - name: Upload artifacts |
| 84 | + |
| 85 | + with: |
| 86 | + name: build-linux |
| 87 | + path: ./artifacts |
| 88 | + build-macos: |
| 89 | + timeout-minutes: 30 |
| 90 | + runs-on: parity-macos |
| 91 | + needs: [fmt] |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 94 | + - name: Set rust version from env file |
| 95 | + run: | |
| 96 | + echo $CI_IMAGE |
| 97 | + RUST_VERSION=$(echo $CI_IMAGE | sed -E 's/.*ci-unified:([^-]+)-([^-]+).*/\2/') |
| 98 | + echo $RUST_VERSION |
| 99 | + echo "RUST_VERSION=${RUST_VERSION}" >> $GITHUB_ENV |
| 100 | + - name: Set up Homebrew |
| 101 | + uses: Homebrew/actions/setup-homebrew@1ccc07ccd54b6048295516a3eb89b192c35057dc # master from 12.09.2024 |
| 102 | + - name: Install protobuf |
| 103 | + run: brew install protobuf |
| 104 | + - name: Install rust ${{ env.RUST_VERSION }} |
| 105 | + uses: actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc # v1.9.0 |
| 106 | + with: |
| 107 | + cache: false |
| 108 | + toolchain: ${{ env.RUST_VERSION }} |
| 109 | + target: wasm32-unknown-unknown, aarch64-apple-darwin, x86_64-apple-darwin |
| 110 | + components: cargo, clippy, rust-docs, rust-src, rustfmt, rustc, rust-std |
| 111 | + - name: cargo info |
| 112 | + run: | |
| 113 | + echo "######## rustup show ########" |
| 114 | + rustup show |
| 115 | + echo "######## cargo --version ########" |
| 116 | + cargo --version |
| 117 | + - name: Rust Cache |
| 118 | + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 |
| 119 | + with: |
| 120 | + cache-on-failure: true |
| 121 | + cache-all-crates: true |
| 122 | + - name: Run cargo build |
| 123 | + run: | |
| 124 | + echo "######## cargo build aarch64-apple-darwin ########" |
| 125 | + cargo build --release --target aarch64-apple-darwin |
| 126 | + echo "######## cargo build x86_64-apple-darwin ########" |
| 127 | + cargo build --release --target x86_64-apple-darwin |
| 128 | + echo "######## Packing artifacts ########" |
| 129 | + mkdir -p ./artifacts/substrate-contracts-node-mac/ |
| 130 | + lipo ./target/x86_64-apple-darwin/release/substrate-contracts-node \ |
| 131 | + ./target/aarch64-apple-darwin/release/substrate-contracts-node \ |
| 132 | + -create -output ./artifacts/substrate-contracts-node-mac/substrate-contracts-node |
| 133 | + ls -la ./artifacts/substrate-contracts-node-mac/ |
| 134 | + - name: Upload artifacts |
| 135 | + |
| 136 | + with: |
| 137 | + name: build-macos |
| 138 | + path: ./artifacts |
| 139 | + publish: |
| 140 | + name: Publish release |
| 141 | + runs-on: ubuntu-latest |
| 142 | + needs: [build-test-linux, build-macos] |
| 143 | + permissions: |
| 144 | + contents: write |
| 145 | + steps: |
| 146 | + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 |
| 147 | + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 |
| 148 | + with: |
| 149 | + name: build-linux |
| 150 | + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 |
| 151 | + with: |
| 152 | + name: build-macos |
| 153 | + - name: Pack artifacts |
| 154 | + run: | |
| 155 | + tar -czvf ./substrate-contracts-node-linux.tar.gz ./substrate-contracts-node-linux |
| 156 | + tar -czvf ./substrate-contracts-node-mac-universal.tar.gz ./substrate-contracts-node-mac |
| 157 | + ls -la |
| 158 | + - name: Publish release |
| 159 | + uses: ghalactic/github-release-from-tag@cebdacac0ccd08933b8e7f278f4123723ad978eb # v5.4.0 |
| 160 | + if: github.ref_type == 'tag' |
| 161 | + with: |
| 162 | + prerelease: false |
| 163 | + draft: true |
| 164 | + assets: | |
| 165 | + - path: substrate-contracts-node-linux.tar.gz |
| 166 | + - path: substrate-contracts-node-mac-universal.tar.gz |
0 commit comments