Skip to content

Commit

Permalink
Adds publish CI actions (#545)
Browse files Browse the repository at this point in the history
* Introducing new workflow to release

* Tested version on separate repo

* Restore build on push

* typo

* I'm tired :()

* Fixes PR checkout

* Fixes tag

* Fixes pr ref in ci build

* Split release and docker

* Restire missing git

* Typo in tag

* another typo

* adding docker pull

* adds log
  • Loading branch information
crystalin authored Jun 27, 2021
1 parent 169ad75 commit d2d8be4
Show file tree
Hide file tree
Showing 5 changed files with 809 additions and 298 deletions.
369 changes: 369 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,369 @@
name: Build

# Using a single file workflow is the preferred solution for our CI over workflow_runs.
# 1. It generates only 1 action item in the list making it more readable
# 2. It includes the PR/Commit text in the action item
# 3. Artifacts are not available between workflows.

# This is only allowing pushes on the moonbeam repo for pull requests.
####### DO NOT CHANGE THIS !! #######
on:
push:
workflow_dispatch:
inputs:
pull_request:
description: set to pull_request number to execute on external pr
required: false

jobs:
####### Check files and formatting #######

set-tags:
runs-on: ubuntu-latest
outputs:
git_ref: ${{ steps.check-git-ref.outputs.git_ref }}
steps:
- name: Check git ref
id: check-git-ref
run: |
if [[ -n "${{ github.event.inputs.pull_request }}" ]]; then
echo ::set-output name=git_ref::refs/pull/${{ github.event.inputs.pull_request }}/head
echo "git_ref: refs/pull/${{ github.event.inputs.pull_request }}/head"
fi
check-copyright:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Find un-copyrighted files
run: |
find . -name '*.rs' -exec grep -H -E -o -c Copyright {} \; | grep ':0' || true
FILECOUNT=$(find . -name '*.rs' -exec grep -H -E -o -c 'Copyright' {} \; | grep -c ':0' || true)
if [[ $FILECOUNT -eq 0 ]]; then
true
else
false
fi
check-links:
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: "yes"

check-editorconfig:
name: "Check editorconfig"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Setup editorconfig checker
run: |
ls /tmp/bin/ec-linux-amd64 || \
cd /tmp && \
wget https://github.com/editorconfig-checker/editorconfig-checker/releases/download/2.1.0/ec-linux-amd64.tar.gz && \
tar xvf ec-linux-amd64.tar.gz && \
chmod +x bin/ec-linux-amd64
- name: Check files
run: /tmp/bin/ec-linux-amd64

check-prettier:
name: "Check with Prettier"
runs-on: ubuntu-latest
needs: ["set-tags"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Check with Prettier
run: npx prettier --check --ignore-path .gitignore '**/*.(yml|js|ts|json)'

####### Building and Testing binaries #######

build:
runs-on: self-hosted
needs: ["set-tags"]
env:
CARGO_SCCACHE_VERSION: 0.2.14-alpha.0-parity
RUSTFLAGS: "-C opt-level=3"
# MOONBEAM_LOG: info
# DEBUG: "test*"
outputs:
RUSTC: ${{ steps.get-rust-versions.outputs.rustc }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/cache@v2
with:
path: ${{ runner.tool_cache }}/cargo-sccache
key: ${{ runner.OS }}-sccache-bin-${{ env.CARGO_SCCACHE_VERSION }}-v1

# With rustup's nice new toml format, we just need to run rustup show to install the toolchain
# https://github.com/actions-rs/toolchain/issues/126#issuecomment-782989659
- name: Setup Rust toolchain
run: rustup show
- name: SCCache
run: |
if [ ! -f ${{ runner.tool_cache }}/cargo-sccache/bin/sccache ]; then
cargo install sccache --git https://github.com/paritytech/sccache.git --no-default-features --features=dist-client --root ${{ runner.tool_cache }}/cargo-sccache
fi
if [[ -z `pgrep sccache` ]]; then
chmod +x ${{ runner.tool_cache }}/cargo-sccache/bin/sccache
${{ runner.tool_cache }}/cargo-sccache/bin/sccache --start-server
fi
${{ runner.tool_cache }}/cargo-sccache/bin/sccache -s
echo "RUSTC_WRAPPER=${{ runner.tool_cache }}/cargo-sccache/bin/sccache" >> $GITHUB_ENV
- id: get-rust-versions
run: |
echo "::set-output name=rustc::$(rustc --version)"
- name: Build Node
run: cargo build --release --all
- name: Unit tests
run: cargo test --release --all
- name: Format code with rustfmt
run: cargo fmt -- --check

# We determine whether there are unmodified Cargo.lock files by:
# 1. Asking git for a list of all modified files
# 2. Using grep to reduce the list to only Cargo.lock files
# 3. Counting the number of lines of output
- name: Check Cargo Toml
run: |
# Make sure git is working, and if not abort early. When git is not working it looks like:
# $ git diff-index --name-only HEAD
# fatal: not a git repository (or any of the parent directories): .git
DIFF_INDEX=$(git diff-index --name-only HEAD)
if [[ ${DIFF_INDEX:0:5} == "fatal" ]]; then
echo "There was an error with the git checkout. Can't check Cargo.lock file."
false
fi
FILECOUNT=$(echo $DIFF_INDEX | grep Cargo.lock | wc -l)
if [[ $FILECOUNT -eq 0 ]]; then
echo "All lock files are valid"
else
echo "The following Cargo.lock files have uncommitted changes"
echo $DIFF_INDEX | grep Cargo.lock
false
fi
- name: Check with Clippy
run: cargo clippy --release --workspace
- name: Ensure benchmarking compiles
run: cargo check --release --features=runtime-benchmarks
- name: Save parachain binary
run: |
mkdir -p build
cp target/release/moonbeam build/moonbeam;
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: moonbeam
path: build

typescript-tests:
runs-on: self-hosted
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v2
with:
name: moonbeam
path: build
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Typescript integration tests (against dev service)
env:
BINARY_PATH: ../build/moonbeam
run: |
chmod uog+x build/moonbeam
cd moonbeam-types-bundle
npm install
cd ../tests
npm install
node_modules/.bin/mocha --parallel -j 7 -r ts-node/register 'tests/**/test-*.ts'
####### Prepare and Deploy Docker images #######
generate-parachain-specs:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: ["build", "typescript-tests"]
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v2
with:
name: moonbeam
path: build
- name: Make moonbeam executable
run: |
chmod uog+x build/moonbeam
- name: Generate specs
run: |
MOONBEAM_BINARY=build/moonbeam scripts/generate-parachain-specs.sh
- name: Generate runtimes
run: |
MOONBEAM_BINARY=build/moonbeam scripts/generate-runtimes.sh
- name: Upload parachain specs
uses: actions/upload-artifact@v2
with:
name: moonbeam
path: build

docker-parachain:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v2
with:
name: moonbeam
path: build
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=purestake/moonbase-parachain
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
driver-opts: |
image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push parachain
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/moonbase-parachain.Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
docker-moonbeam:
runs-on: ubuntu-latest
needs: ["build", "generate-parachain-specs"]
if: github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ needs.set-tags.outputs.git_ref }}
- uses: actions/download-artifact@v2
with:
name: moonbeam
path: build
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=purestake/moonbeam
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
driver-opts: |
image=moby/buildkit:master
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push moonbeam
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/moonbeam.Dockerfile
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
Loading

0 comments on commit d2d8be4

Please sign in to comment.