Skip to content

Commit

Permalink
ci: add workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Oct 11, 2024
1 parent b8de0e6 commit 61975ea
Show file tree
Hide file tree
Showing 13 changed files with 758 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/scripts/cargo_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -ex

# --- Declare the following variables for tests
# export TARGET=x86_64-unknown-linux-gnu
# export DEBUG_OR_RELEASE=debug
# export SKIP_SERVICES_TESTS="--skip test_redis"

if [ -z "$TARGET" ]; then
echo "Error: TARGET is not set."
exit 1
fi

if [ "$DEBUG_OR_RELEASE" = "release" ]; then
RELEASE="--release"
fi

if [ -z "$SKIP_SERVICES_TESTS" ]; then
echo "Info: SKIP_SERVICES_TESTS is not set."
unset SKIP_SERVICES_TESTS
fi

rustup target add "$TARGET"

# shellcheck disable=SC2086
cargo build --target $TARGET $RELEASE $FEATURES

# shellcheck disable=SC2086
cargo test --target $TARGET $RELEASE --workspace -- --nocapture $SKIP_SERVICES_TESTS
69 changes: 69 additions & 0 deletions .github/workflows/build_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: Build all

on:
workflow_call:
inputs:
toolchain:
required: true
type: string
debug_or_release:
required: true
type: string

jobs:
# rhel9:
# name: RHEL9
# uses: ./.github/workflows/build_rhel9.yml
# secrets: inherit
# with:
# toolchain: ${{ inputs.toolchain }}
# archive-name: rhel9
# target: x86_64-unknown-linux-gnu
# debug_or_release: ${{ inputs.debug_or_release }}

generic-linux:
strategy:
fail-fast: false
matrix:
include:
- distribution: ubuntu-24.04
archive-name: ubuntu_24_04
target: x86_64-unknown-linux-gnu
name: ${{ matrix.distribution }}
uses: ./.github/workflows/build_generic.yml
secrets: inherit
with:
toolchain: ${{ inputs.toolchain }}
distribution: ${{ matrix.distribution }}
archive-name: ${{ matrix.archive-name }}
target: ${{ matrix.target }}
debug_or_release: ${{ inputs.debug_or_release }}
skip_services_tests: --skip test_redis

generic-macos:
strategy:
fail-fast: false
matrix:
include:
- distribution: macos-14
archive-name: macos_arm
target: aarch64-apple-darwin
name: ${{ matrix.distribution }}
uses: ./.github/workflows/build_generic.yml
secrets: inherit
with:
toolchain: ${{ inputs.toolchain }}
distribution: ${{ matrix.distribution }}
archive-name: ${{ matrix.archive-name }}
target: ${{ matrix.target }}
debug_or_release: ${{ inputs.debug_or_release }}
skip_services_tests: --skip test_redis

cleanup:
needs:
# - rhel9
- generic-linux
- generic-macos
uses: Cosmian/reusable_workflows/.github/workflows/cleanup_cache.yml@develop
secrets: inherit
57 changes: 57 additions & 0 deletions .github/workflows/build_generic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
name: cargo build - no docker

on:
workflow_call:
inputs:
toolchain:
required: true
type: string
distribution:
required: true
type: string
archive-name:
required: true
type: string
target:
required: true
type: string
debug_or_release:
required: true
type: string
skip_services_tests:
required: false
type: string

jobs:
cargo-build:
name: ${{ inputs.archive-name }}
runs-on: ${{ inputs.distribution }}
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ inputs.toolchain }}
components: rustfmt, clippy

- name: Build and tests
env:
# Google variables
TEST_GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_ID }}
TEST_GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_SECRET }}
TEST_GOOGLE_OAUTH_REFRESH_TOKEN: ${{ secrets.TEST_GOOGLE_OAUTH_REFRESH_TOKEN }}

TARGET: ${{ inputs.target }}
DEBUG_OR_RELEASE: ${{ inputs.debug_or_release }}
SKIP_SERVICES_TESTS: ${{ inputs.skip_services_tests }}
run: |
bash .github/scripts/cargo_build.sh
- name: Upload findex-server for ${{ inputs.distribution }}
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.archive-name }}-${{ inputs.debug_or_release }}
path: |
target/${{ inputs.target }}/${{ inputs.debug_or_release }}/findex-server
retention-days: 1
if-no-files-found: error
78 changes: 78 additions & 0 deletions .github/workflows/build_rhel9.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
name: RHEL

on:
workflow_call:
inputs:
toolchain:
required: true
type: string
archive-name:
required: true
type: string
target:
required: true
type: string
debug_or_release:
required: true
type: string
features:
required: false
type: string

jobs:
rhel9-tests:
services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379

name: ${{ inputs.archive-name }}
runs-on: ubuntu-22.04
container:
image: redhat/ubi9

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ inputs.toolchain }}
components: rustfmt, clippy

- name: RHEL 9 prerequisites
run: |
set -ex
yum -y install python-devel
yum -y install wget
yum -y install perl-IPC-Cmd perl-Digest-SHA1 perl-CPAN perl-devel
- name: Build and tests
env:
REDIS_HOST: redis

# Google variables
TEST_GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_ID }}
TEST_GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.TEST_GOOGLE_OAUTH_CLIENT_SECRET }}
TEST_GOOGLE_OAUTH_REFRESH_TOKEN: ${{ secrets.TEST_GOOGLE_OAUTH_REFRESH_TOKEN }}
GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY }}

TARGET: ${{ inputs.target }}
DEBUG_OR_RELEASE: ${{ inputs.debug_or_release }}
run: |
bash .github/scripts/cargo_build.sh
- name: Upload findex-server for RHEL 9
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.archive-name }}-${{ inputs.debug_or_release }}
path: |
target/${{ inputs.target }}/${{ inputs.debug_or_release }}/findex-server
retention-days: 1
if-no-files-found: error
33 changes: 33 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Cargo lint

on:
workflow_call:
inputs:
toolchain:
required: true
type: string

jobs:
lint:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v3

- name: Cache dependencies
id: cargo_cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}

- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ inputs.toolchain }}
components: rustfmt, clippy

- name: Check formatting
run: cargo fmt --all -- --check --color always

- name: Static analysis
run: cargo clippy --workspace --all-targets --all-features --tests -- -D warnings
9 changes: 9 additions & 0 deletions .github/workflows/github_cache_cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Github cache cleanup

on: workflow_dispatch

jobs:
cleanup:
uses: Cosmian/reusable_workflows/.github/workflows/cleanup_cache.yml@develop
secrets: inherit
25 changes: 25 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: CI checks

on:
push:

jobs:
cargo-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

cargo-lint:
uses: ./.github/workflows/clippy.yml
with:
toolchain: nightly-2024-06-09

build_tests:
uses: ./.github/workflows/build_all.yml
secrets: inherit
with:
toolchain: nightly-2024-06-09
debug_or_release: debug
32 changes: 32 additions & 0 deletions .github/workflows/main_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: CI nightly release

on:
push:
# any tags, including tags with / like v1.0/alpha
tags:
- '**'
schedule:
# every day at 1 AM
- cron: 00 1 * * *
workflow_dispatch:

jobs:
cargo-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1

cargo-lint:
uses: ./.github/workflows/clippy.yml
with:
toolchain: nightly-2024-06-09

build:
uses: ./.github/workflows/build_all.yml
secrets: inherit
with:
toolchain: nightly-2024-06-09
debug_or_release: release
Loading

0 comments on commit 61975ea

Please sign in to comment.