Skip to content

Commit

Permalink
ci: add dev&release ci workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Aug 4, 2022
1 parent 88b3825 commit a6799aa
Show file tree
Hide file tree
Showing 11 changed files with 460 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Rust
target/

# Test
_test_output_dir
outputs
_datas
_logs
17 changes: 17 additions & 0 deletions .github/actions/setup-cross/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Setup Cross
description: Install cargo cross
inputs:
version:
description: Cross Version
required: false
default: "0.2.4"
runs:
using: "composite"
steps:
- uses: actions-rs/cargo@v1
with:
command: version
- shell: bash
run: |
curl -fsSLo /tmp/cross.tar.gz https://github.com/cross-rs/cross/releases/download/v${{ inputs.version }}/cross-x86_64-unknown-linux-gnu.tar.gz
tar -C ~/.cargo/bin -zxvf /tmp/cross.tar.gz
22 changes: 22 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
changelog:
exclude:
labels:
- pr-chore
authors:
- Mergify
categories:
- title: Exciting New Features ✨
labels:
- pr-feature
- title: Thoughtful Bug Fix 🔧
labels:
- pr-bugfix
- title: Code Refactor 🎉
labels:
- pr-refactor
- title: Build/Testing/CI Infra Changes 🔌
labels:
- pr-build
- title: Documentation 📔
labels:
- pr-doc
77 changes: 77 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: dev

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true

jobs:
test:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -Dwarnings
- uses: actions-rs/cargo@v1
with:
command: build
- uses: actions-rs/cargo@v1
with:
command: test
args: --verbose

build_linux:
timeout-minutes: 30
name: build_linux_${{ matrix.arch }}_${{matrix.platform}}
runs-on: ubuntu-latest
strategy:
matrix:
arch:
- x86_64
- aarch64
platform:
- musl
- gnu
steps:
- uses: actions/checkout@v3
- id: target
run: echo ::set-output name=target::${{ matrix.arch }}-unknown-linux-${{ matrix.platform }}
- uses: ./.github/actions/setup-cross
- uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target=${{ steps.target.outputs.target }}

build_macos:
timeout-minutes: 30
name: build_macos_${{ matrix.arch }}
runs-on: macos-latest
strategy:
matrix:
arch:
- x86_64
- aarch64
steps:
- uses: actions/checkout@v3
- id: target
run: echo ::set-output name=target::${{ matrix.arch }}-apple-darwin
- name: Rust setup
uses: actions-rs/cargo@v1
with:
command: version
- name: Cross setup
if: matrix.arch == 'aarch64'
run: |
rustup target add aarch64-apple-darwin
echo "JEMALLOC_SYS_WITH_LG_PAGE=14" >> $GITHUB_ENV
- name: Build Binary
run: |
cargo build --target=${{ steps.target.outputs.target }}
143 changes: 143 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: release

on:
push:
tags:
- "v*"
schedule:
# Release at 00:00 UTC+8
- cron: '0 16 * * *'
workflow_dispatch:

jobs:
create_release:
name: create release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.generated-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Get latest tag
id: get-latest-tag
run: |
echo "::set-output name=tag::`gh release list -L 1 | cut -f 1`"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Bump version
id: generated-tag
uses: actions/github-script@v6
with:
script: |
if (context.ref.startsWith("refs/tags/")) {
let tag = context.ref.replace("refs/tags/", "");
core.setOutput('tag', tag);
console.log(`This event pushed a tag ${tag}, return directly.`)
return
}
let tag = "${{ steps.get-latest-tag.outputs.tag }}";
let result = /v(\d+)\.(\d+)\.(\d+)/g.exec(tag);
if (result === null) {
throw `The previous tag ${{ steps.get-latest-tag.outputs.tag }} is invalid, ignoring`;
}
let major = result[1];
let minor = result[2];
let patch = (parseInt(result[3]) + 1).toString();
let next_tag = `v${major}.${minor}.${patch}-nightly`;
console.log(`This event is triggered, return generated ${next_tag}.`)
core.setOutput('tag', next_tag)
- name: Create github release if not exist
# Reference: https://cli.github.com/manual/gh_release_create
run: |
echo "Create a release for ${{ steps.generated-tag.outputs.tag }}"
gh release create ${{ steps.generated-tag.outputs.tag }} --generate-notes -p
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

publish_macos:
name: macos assets
runs-on: macos-11
needs: create_release
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- aarch64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get target
id: target
run: echo ::set-output name=target::${{ matrix.arch }}-apple-darwin
- name: Rust setup
uses: actions-rs/cargo@v1
with:
command: version
- name: Cross setup
if: matrix.arch == 'aarch64'
run: |
rustup target add aarch64-apple-darwin
echo "JEMALLOC_SYS_WITH_LG_PAGE=14" >> $GITHUB_ENV
- name: Build Binary
run: |
cargo build --release --target=${{ steps.target.outputs.target }}
- name: Pack binaries
run: |
brew install gnu-tar
sudo /usr/sbin/purge
mkdir -p release/${{ steps.target.outputs.target }}/bin
cp ./target/${{ steps.target.outputs.target }}/release/ethtel release/${{ steps.target.outputs.target }}/bin/
rm -f release/${{ steps.target.outputs.target }}/bin/*.d
cp -r ./schemas release/${{ steps.target.outputs.target }}/schemas
gtar -C ./release/${{ steps.target.outputs.target }} -czvf ethtel-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.tar.gz bin schemas
- name: Update release to github
shell: bash
# Reference: https://cli.github.com/manual/gh_release_upload
run: gh release upload ${{ inputs.version }} ethtel-${{ inputs.version }}-${{ inputs.target }}.* --clobber
env:
GH_TOKEN: ${{ inputs.github_token }}

publish_linux:
name: linux assets
runs-on: ubuntu-latest
needs: create_release
strategy:
fail-fast: false
matrix:
arch:
- x86_64
- aarch64
platform:
- musl
- gnu
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get target
id: target
run: echo ::set-output name=target::${{ matrix.arch }}-unknown-linux-${{ matrix.platform }}
- uses: ./.github/actions/setup-cross
- name: Build Binary
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target=${{ steps.target.outputs.target }}
- name: Pack binaries
run: |
brew install gnu-tar
sudo /usr/sbin/purge
mkdir -p release/${{ steps.target.outputs.target }}/bin
cp ./target/${{ steps.target.outputs.target }}/release/ethtel release/${{ steps.target.outputs.target }}/bin/
rm -f release/${{ steps.target.outputs.target }}/bin/*.d
cp -r ./schemas release/${{ steps.target.outputs.target }}/schemas
gtar -C ./release/${{ steps.target.outputs.target }} -czvf ethtel-${{ needs.create_release.outputs.version }}-${{ steps.target.outputs.target }}.tar.gz bin schemas
- name: Update release to github
shell: bash
# Reference: https://cli.github.com/manual/gh_release_upload
run: gh release upload ${{ inputs.version }} ethtel-${{ inputs.version }}-${{ inputs.target }}.* --clobber
env:
GH_TOKEN: ${{ inputs.github_token }}
17 changes: 0 additions & 17 deletions .github/workflows/rust.yml

This file was deleted.

24 changes: 24 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[build.env]
passthrough = [
"BUILD_DIR",
"CARGO_INCREMENTAL",
"CARGO_PROFILE_RELEASE_OPT_LEVEL",
"CARGO_PROFILE_RELEASE_CODEGEN_UNITS",
"RUST_BACKTRACE",
"RUST_LOG",
"VECTOR_BUILD_DESC",
"JEMALLOC_SYS_WITH_LG_PAGE",
"JEMALLOC_SYS_WITH_LG_HUGEPAGE",
]

[target.aarch64-unknown-linux-gnu]
pre-build = ["dpkg --add-architecture arm64 && apt-get update && apt-get install -y libssl-dev libssl-dev:arm64"]

[target.x86_64-unknown-linux-gnu]
pre-build = ["apt-get update && apt-get install -y libssl-dev"]

[target.aarch64-unknown-linux-musl]
dockerfile = "./docker/cross/Dockerfile.aarch64-unknown-linux-musl"

[target.x86_64-unknown-linux-musl]
dockerfile = "./docker/cross/Dockerfile.x86_64-unknown-linux-musl"
7 changes: 7 additions & 0 deletions docker/cross/Dockerfile.aarch64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ghcr.io/cross-rs/aarch64-unknown-linux-musl:main

COPY docker/cross/openssl.sh /
RUN bash /openssl.sh linux-aarch64 aarch64-linux-musl-
ENV OPENSSL_DIR=/openssl \
OPENSSL_INCLUDE_DIR=/openssl/include \
OPENSSL_LIB_DIR=/openssl/lib
7 changes: 7 additions & 0 deletions docker/cross/Dockerfile.x86_64-unknown-linux-musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ghcr.io/cross-rs/x86_64-unknown-linux-musl:main

COPY docker/cross/openssl.sh /
RUN bash /openssl.sh linux-x86_64 x86_64-linux-musl-
ENV OPENSSL_DIR=/openssl \
OPENSSL_INCLUDE_DIR=/openssl/include \
OPENSSL_LIB_DIR=/openssl/lib
49 changes: 49 additions & 0 deletions docker/cross/openssl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
set -ex

main() {
local version=1.0.2t
local os=$1 \
triple=$2

local dependencies=(
ca-certificates
curl
m4
make
perl
)

# NOTE cross toolchain must be already installed
apt-get update
local purge_list=()
for dep in ${dependencies[@]}; do
if ! dpkg -L $dep; then
apt-get install --no-install-recommends -y $dep
purge_list+=($dep)
fi
done

td=$(mktemp -d)

pushd $td
curl https://www.openssl.org/source/openssl-$version.tar.gz |
tar --strip-components=1 -xz
AR=${triple}ar CC=${triple}gcc ./Configure \
--prefix=/openssl \
no-dso \
$os \
-fPIC \
${@:3}
nice make -j$(nproc)
make install

# clean up
apt-get purge --auto-remove -y ${purge_list[@]}

popd

rm -rf $td
rm $0
}

main "${@}"
Loading

0 comments on commit a6799aa

Please sign in to comment.