Skip to content

Commit

Permalink
add basic ci workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
d-roak committed Sep 22, 2023
1 parent f01eab8 commit 71397cf
Show file tree
Hide file tree
Showing 14 changed files with 543 additions and 33 deletions.
124 changes: 124 additions & 0 deletions .github/workflows/binaries-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
name: Task - Build binaries and publish

on:
workflow_dispatch:
inputs:
release_tag_name:
description: "Release tag name"
type: string
required: true
workflow_call:
inputs:
release_tag_name:
description: "Release tag name"
type: string
required: true

jobs:
build:
strategy:
fail-fast: false
matrix:
build:
- aarch64-apple-darwin
- aarch64-unknown-linux-gnu
- x86_64-apple-darwin
- x86_64-unknown-linux-gnu
# https://github.com/rust-rocksdb/rust-rocksdb/issues/665
# - x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc
include:
- build: aarch64-apple-darwin
os: macos-latest-xl
bin_name: madara
- build: aarch64-unknown-linux-gnu
os: ubuntu-latest-32-cores
bin_name: madara
- build: x86_64-apple-darwin
os: macos-latest-xl
bin_name: madara
- build: x86_64-unknown-linux-gnu
os: ubuntu-latest-32-cores
bin_name: madara
- build: x86_64-pc-windows-msvc
os: windows-latest
bin_name: madara.exe
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup rust toolchain
run: |
rustup target add ${{ matrix.build }}
- name: Setup build deps (linux)
if:
matrix.build == 'x86_64-unknown-linux-gnu' || matrix.build ==
'aarch64-unknown-linux-gnu'
run: |
sudo apt update
sudo apt install -y clang llvm libudev-dev protobuf-compiler libssl-dev
- name: Setup build deps (aarch64-unknown-linux-gnu)
if: matrix.build == 'aarch64-unknown-linux-gnu'
run: |
sudo apt update
sudo apt install -y g++-aarch64-linux-gnu libc6-dev-arm64-cross
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g+
- name: Setup build deps (x86_64-apple-darwin)
if:
matrix.build == 'x86_64-apple-darwin' || matrix.build ==
'aarch64-apple-darwin'
run: |
brew install protobuf
- name: Setup build deps (x86_64-pc-windows-msvc)
if: matrix.build == 'x86_64-pc-windows-msvc'
run: |
choco install -y protoc llvm
mkdir C:/tmp/madara-libs
(New-Object net.webclient).Downloadfile("https://github.com/keep-starknet-strange/madara-infra/releases/download/win-bins-build-libs/libjemalloc.a", "C:/tmp/madara-libs/libjemalloc.a")
(New-Object net.webclient).Downloadfile("https://github.com/keep-starknet-strange/madara-infra/releases/download/win-bins-build-libs/rocksdb.lib", "C:/tmp/madara-libs/rocksdb.lib")
- name: Build (x86_64 linux and x86_64/aarch64 apple)
if:
matrix.build == 'x86_64-unknown-linux-gnu' || matrix.build ==
'x86_64-apple-darwin' || matrix.build == 'aarch64-apple-darwin'
run: cargo build --release --target ${{ matrix.build }}

- name: Build (aarch64-unknown-linux-gnu)
if: matrix.build == 'aarch64-unknown-linux-gnu'
run: |
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc
export CC_aarch64_unknown_linux_gnu=/usr/bin/aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_gnu=/usr/bin/aarch64-linux-gnu-g++
cargo build --release --target ${{ matrix.build }}
- name: Pre-Build (x86_64-pc-windows-msvc)
if: matrix.build == 'x86_64-pc-windows-msvc'
shell: bash
run: |
cargo fetch --target ${{ matrix.build }}
export reg_folder=$(ls C:/Users/runneradmin/.cargo/registry/src | grep github.com)
export pdb_folder=$(ls C:/Users/runneradmin/.cargo/registry/src/$reg_folder | grep parity-db)
sed -ir 's/madvise_random(_id: TableId, _map: \&mut memmap2::MmapMut)/madvise_random(_map: \&mut memmap2::MmapMut)/g' C:/Users/runneradmin/.cargo/registry/src/$reg_folder/$pdb_folder/src/file.rs
- name: Build (x86_64-pc-windows-msvc)
if: matrix.build == 'x86_64-pc-windows-msvc'
shell: bash
run: |
JEMALLOC_OVERRIDE=C:/tmp/madara-libs/libjemalloc.a ROCKSDB_LIB_DIR=C:/tmp/madara-libs cargo build --release --target ${{ matrix.build }}
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.build }}/release/${{ matrix.bin_name }}
asset_name: ${{ matrix.build}}-${{ matrix.bin_name }}
tag: ${{ inputs.release_tag_name }}
overwrite: true
20 changes: 20 additions & 0 deletions .github/workflows/cron-daily.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Workflow - Daily Cron

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"

jobs:
stale_issues:
name: Stale issues
uses: ./.github/workflows/stale-issues.yml

lock_closed:
name: Lock closed issues/PRs
uses: ./.github/workflows/lock-closed.yml

security_audit:
name: Security audit
uses: ./.github/workflows/security-audit.yml
116 changes: 116 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
name: Task - Build and Push Docker Image

on:
workflow_dispatch:
inputs:
release_tag_name:
description: "Release tag name"
type: string
required: true
workflow_call:
inputs:
release_tag_name:
description: "Release tag name"
type: string
required: true

env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: |
type=raw,value=${{ inputs.release_tag_name }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs:
type=image,name=${{ env.REGISTRY_IMAGE
}},push-by-digest=true,name-canonical=true,push=true

- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
35 changes: 35 additions & 0 deletions .github/workflows/linters-cargo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Task - Linters Cargo

on:
workflow_dispatch:
workflow_call:

jobs:
cargo-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Retrieve cached build
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key:
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
fail-on-cache-miss: true
restore-keys: |
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}-${{
github.run_id }}
${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
${{ runner.os }}-cargo
- name: Format and clippy
run: |
cargo fmt -- --check
cargo clippy --no-deps -- -D warnings
cargo clippy --tests --no-deps -- -D warnings
15 changes: 15 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
name: Task - Linters

on:
workflow_dispatch:
workflow_call:

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run prettier
run: |-
npx prettier --check .
31 changes: 31 additions & 0 deletions .github/workflows/lock-closed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Task - Lock Closed Issues/PRs

on:
workflow_dispatch:
workflow_call:

jobs:
lock:
name: 🔒 Lock closed issues and PRs
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2.0.3
with:
github-token: ${{ github.token }}
issue-lock-inactive-days: "30"
issue-lock-reason: ""
issue-comment: >
Issue closed and locked due to lack of activity.
If you encounter this same issue, please open a new issue and refer
to this closed one.
pr-lock-inactive-days: "1"
pr-lock-reason: ""
pr-comment: >
Pull Request closed and locked due to lack of activity.
If you'd like to build on this closed PR, you can clone it using
this method: https://stackoverflow.com/a/14969986
Then open a new PR, referencing this closed PR in your message.
42 changes: 42 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: Task - Pre-Release

on:
workflow_dispatch:
workflow_call:

jobs:
build:
name: Take Snapshot
runs-on: ubuntu-latest
steps:
- name: Get the tags by date
id: tags
run: |
echo "new=$(date +'weekly-%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "old=$(date -d'1 week ago' +'weekly-%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Checkout branch "main"
uses: actions/checkout@v3
with:
ref: "main"
fetch-depth: 0
- name: Generate changelog
id: changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "# Automatic snapshot pre-release ${{ steps.tags.outputs.new }}" > Changelog.md
echo "" >> Changelog.md
echo "## Changes since last snapshot (${{ steps.tags.outputs.old }})" >> Changelog.md
echo "" >> Changelog.md
- name: Release snapshot
id: release-snapshot
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e # v1.1.4 latest version, repo archived
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tags.outputs.new }}
release_name: ${{ steps.tags.outputs.new }}
draft: false
prerelease: true
body_path: Changelog.md
Loading

0 comments on commit 71397cf

Please sign in to comment.