Skip to content

build release

build release #663

Workflow file for this run

name: Main
permissions:
contents: read
packages: write
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
env:
CARGO_TERM_COLOR: always
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
RUST_TOOLCHAIN: nightly-2024-03-22
DATABASE_URL: "postgres://postgres:postgres@localhost:5432/postgres"
jobs:
build-linux:
strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-unknown-linux-gnu
command: cargo
# - target: aarch64-unknown-linux-gnu
# command: cross
# - target: x86_64-unknown-linux-musl
# command: cross
# - target: aarch64-unknown-linux-musl
# command: cross
runs-on: ubuntu-latest
env:
CROSS_CONTAINER_OPTS: "--network=host"
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: md5
POSTGRES_INITDB_ARGS: --auth-host=md5
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name postgres
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
- name: Extract target information
id: target
env:
TARGET: ${{ matrix.platform.target }}
run: |
echo "env=${TARGET##*-}" >> "$GITHUB_OUTPUT"
echo "arch=$(echo $TARGET | awk '{print $1}')" >> "$GITHUB_OUTPUT"
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT"
echo "profile=release" >> "$GITHUB_OUTPUT"
echo "output-dir=release" >> "$GITHUB_OUTPUT"
- name: Increase postgres max connection
run: |
docker exec -i postgres bash << EOF
sed -i -e 's/max_connections = 100/max_connections = 1000/' /var/lib/postgresql/data/postgresql.conf
sed -i -e 's/shared_buffers = 128MB/shared_buffers = 2GB/' /var/lib/postgresql/data/postgresql.conf
EOF
docker restart postgres
- name: Setup arm64 environment
run: |
sudo apt install --assume-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/aarch64-linux-gnu-pkg-config
aarch64-linux-gnu-pkg-config --version
if: ${{ matrix.platform.target == 'aarch64-unknown-linux-gnu' }}
- name: Setup x64 musl environment
run: |
sudo apt install --assume-yes musl-tools
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/x86_64-linux-musl-pkg-config
x86_64-linux-musl-pkg-config --version
if: ${{ matrix.platform.target == 'x86_64-unknown-linux-musl' }}
# TODO: Rename binary after https://github.com/microsoft/vcpkg/issues/36094 is fixed
- name: Setup arm64 musl environment
run: |
wget -c https://github.com/xmake-mirror/musl.cc/releases/download/20210202/aarch64-linux-musl-cross.linux.tgz -O - | tar -xz
sudo ln -s ${{ github.workspace }}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-g++ /usr/bin/aarch64-linux-gnu-g++
sudo ln -s ${{ github.workspace }}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc /usr/bin/aarch64-linux-gnu-gcc
aarch64-linux-gnu-gcc --version
aarch64-linux-gnu-g++ --version
sudo ln -s ${{ github.workspace }}/vcpkg/cross-pkg-config /usr/bin/aarch64-linux-gnu-pkg-config
aarch64-linux-gnu-pkg-config --version
if: ${{ matrix.platform.target == 'aarch64-unknown-linux-musl' }}
- name: Install vcpkg build deps
run: sudo apt-get --assume-yes install nasm
- name: Install cargo-vcpkg
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cargo-vcpkg
- name: Build vcpkg dependencies
run: |
cargo vcpkg --verbose build --target ${{ matrix.platform.target }}
- name: Install cross
if: ${{ matrix.platform.command == 'cross' }}
uses: taiki-e/cache-cargo-install-action@v1
with:
tool: cross
git: https://github.com/cross-rs/cross
rev: 085092c
- name: Build and test
run: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.target.outputs.profile }}
${{ matrix.platform.command }} test --locked --target ${{ matrix.platform.target }} --profile ${{ steps.target.outputs.profile }}
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.target.outputs.docker-arch }}-${{ steps.target.outputs.env }}
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.target.outputs.output-dir }}/nghe
retention-days: 1
build-docker:
runs-on: ubuntu-latest
needs: build-linux
if: ${{ vars.BUILD_DOCKER != '' }}
steps:
- uses: actions/checkout@v4
- name: Download build artifact for docker
uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/artifact/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# GNU
- name: Extract metadata for Docker gnu
id: meta-gnu
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ github.repository }}-gnu
tags: |
type=ref,event=pr
type=raw,value=develop,enable={{is_default_branch}}
- name: Build and push gnu
uses: docker/build-push-action@v5
with:
context: .
file: ci/docker/Dockerfile
build-args: |
BASE_IMAGE=debian:12.5-slim
TARGET_ENV=gnu
platforms: linux/amd64
push: true
tags: ${{ steps.meta-gnu.outputs.tags }}
# # Musl
# - name: Extract metadata for Docker musl
# id: meta-musl
# uses: docker/metadata-action@v5
# with:
# images: |
# name=ghcr.io/${{ github.repository }}-musl
# tags: |
# type=ref,event=pr
# type=raw,value=develop,enable={{is_default_branch}}
# - name: Build and push musl
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ci/docker/Dockerfile
# build-args: |
# BASE_IMAGE=alpine:3.19.1
# TARGET_ENV=musl
# platforms: linux/amd64,linux/arm64
# push: true
# tags: ${{ steps.meta-musl.outputs.tags }}
# build-windows:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v4
# - name: Export GitHub Actions cache environment variables
# uses: actions/github-script@v7
# with:
# script: |
# core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
# core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
# - uses: dtolnay/rust-toolchain@master
# with:
# toolchain: ${{ env.RUST_TOOLCHAIN }}
# - name: Install and setup postgres
# run: |
# curl https://get.enterprisedb.com/postgresql/postgresql-16.2-1-windows-x64-binaries.zip --output postgresql.zip
# 7z x postgresql.zip
# $env:PGDATA = "$PWD\pgsql\data"
# $env:PGPASSWORD = "postgres"
# echo $env:PGPASSWORD > pwfile
# pgsql\bin\initdb --username=postgres --encoding="UTF-8" --locale="en_US.UTF-8" --pwfile=pwfile
# pgsql\bin\pg_ctl start
# pgsql\bin\psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = 1000"
# pgsql\bin\psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2GB'"
# pgsql\bin\pg_ctl restart
# echo "$PWD\pgsql\bin" >> $env:GITHUB_PATH
# echo "$PWD\pgsql\lib" >> $env:GITHUB_PATH
# echo "PQ_LIB_DIR=$PWD\pgsql\lib" >> $env:GITHUB_ENV
# - name: Install cargo-vcpkg
# uses: taiki-e/cache-cargo-install-action@v1
# with:
# tool: cargo-vcpkg
# - name: Build vcpkg dependencies
# run: |
# cargo vcpkg --verbose build --target x86_64-pc-windows-msvc
# - name: Build and test
# run: |
# cargo test --locked --target x86_64-pc-windows-msvc
# build-macos:
# strategy:
# fail-fast: false
# matrix:
# platform:
# - target: x86_64-apple-darwin
# os: macos-13
# vcpkg-target: x64-osx-release
# - target: aarch64-apple-darwin
# os: macos-14
# vcpkg-target: arm64-osx-release
# runs-on: ${{ matrix.platform.os }}
# env:
# HOMEBREW_NO_AUTO_UPDATE: 1
# HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
# steps:
# - uses: actions/checkout@v4
# - name: Export GitHub Actions cache environment variables
# uses: actions/github-script@v7
# with:
# script: |
# core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
# core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
# - uses: dtolnay/rust-toolchain@master
# with:
# toolchain: ${{ env.RUST_TOOLCHAIN }}
# - name: Install and setup postgres
# run: |
# brew uninstall --force postgresql
# brew uninstall --force postgresql@14
# brew install postgresql@16
# brew link postgresql@16
# export PGDATA="$RUNNER_TEMP/pgdata"
# initdb --username=postgres --encoding="UTF-8" --locale="en_US.UTF-8" --pwfile=<(echo postgres)
# pg_ctl start
# psql -U postgres -d postgres -c "ALTER SYSTEM SET max_connections = 1000"
# psql -U postgres -d postgres -c "ALTER SYSTEM SET shared_buffers = '2GB'"
# pg_ctl restart
# - name: Install vcpkg build deps
# run: brew install nasm
# - name: Install cargo-vcpkg
# uses: taiki-e/cache-cargo-install-action@v1
# with:
# tool: cargo-vcpkg
# - name: Build vcpkg dependencies
# run: |
# cargo vcpkg --verbose build --target ${{ matrix.platform.target }}
# - name: Build and test
# run: cargo test --locked --target ${{ matrix.platform.target }}