Skip to content

Commit

Permalink
add github ci
Browse files Browse the repository at this point in the history
  • Loading branch information
m1dnight committed Dec 13, 2024
1 parent cf628ce commit 3543b9f
Show file tree
Hide file tree
Showing 14 changed files with 699 additions and 1 deletion.
30 changes: 30 additions & 0 deletions .github/actions/elixir_setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Install Elixir
#
# I install the Elixir and OTP versions specified in the inputs.
#
# I take two parameters:
# - elixir-version: The version of Elixir to install.
# - otp-version: The version of OTP to install.

name: Install Elixir
description: Install Elixir
inputs:
elixir-version:
description: "elixir version"
required: true
otp-version:
description: "otp version"
required: true
runs:
using: "composite"
steps:
# setup the beam
- name: configure beam
uses: erlef/setup-beam@v1
with:
otp-version: ${{ inputs.otp-version }}
elixir-version: ${{ inputs.elixir-version }}
# install protobuf package
- name: Install Protobuf Elixir dependencies
shell: bash
run: mix escript.install hex protobuf --force
18 changes: 18 additions & 0 deletions .github/actions/os_setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# OS Setup
#
# I install the necessary packages at the OS level.
name: OS Setup
description: OS Setup
runs:
using: "composite"
steps:
- name: install apt packages
shell: bash
run: sudo apt-get install -y libsodium-dev protobuf-compiler

- name: install new protobuf
shell: bash
run: |
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v29.0/protoc-29.0-linux-x86_64.zip && \
unzip protoc-29.0-linux-x86_64.zip -d $HOME/.local
echo "$HOME/.local" >> $GITHUB_PATH
68 changes: 68 additions & 0 deletions .github/workflows/build_release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Build Release
#
# I build a release of the project on GitHub.
#
# I take three parameters:
# - mix-env: The environment to build the release for.
# - elixir-version: The version of Elixir to use.
# - otp-version: The version of OTP to use.
name: Build Release
on:
workflow_call:
inputs:
mix-env:
required: true
type: string
elixir-version:
required: true
type: string
otp-version:
required: true
type: string
release_name:
required: true
type: string
jobs:
build_release:
runs-on: ubuntu-latest
steps:
- name: checkout the repository
uses: actions/checkout@v4

- name: setup deps and _build cache
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: ${{ runner.os }}-build-${{ inputs.mix-env }}-${{ hashFiles('mix.lock') }}

- name: setup elixir
uses: ./.github/actions/elixir_setup
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: install apt packages
uses: ./.github/actions/os_setup

#---------------------------------------------------------------------------
# Create binaries
#
# This part of the action generates all the binaries that are necessary
# for a release.
# If these need to be compiled for different elixir versions, the matrix
# should be put in the on_release.yml file.

# - name: create the client binary
# continue-on-error: false
# shell: bash
# run: |
# MIX_ENV=prod mix do --app anoma_client escript.build
# mv "apps/anoma_client/anoma_client" "apps/anoma_client/anoma_client-elixir-${{ inputs.elixir-version }}-otp-${{ inputs.otp-version }}"

# - name: create artifact of the client binary
# uses: actions/upload-artifact@v4
# with:
# name: anoma_client-elixir-${{ inputs.elixir-version }}-otp-${{ inputs.otp-version }}
# path: "apps/anoma_client/anoma_client-elixir-${{ inputs.elixir-version }}-otp-${{ inputs.otp-version }}"
54 changes: 54 additions & 0 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Compile
#
# I compile the Elixir project.
#
# I take three parameters:
# - mix-env: The environment to compile the project for.
# - elixir-version: The version of Elixir to use.
# - otp-version: The version of OTP to use.
name: Compile
on:
workflow_call:
inputs:
mix-env:
required: true
type: string
elixir-version:
required: true
type: string
otp-version:
required: true
type: string
jobs:
compile:
runs-on: ubuntu-latest
steps:
- name: checkout the repository
uses: actions/checkout@v4

- name: setup deps and _build cache
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: ${{ runner.os }}-build-${{ inputs.mix-env }}-${{ hashFiles('mix.lock') }}

- name: setup elixir
uses: ./.github/actions/elixir_setup
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: install apt packages
uses: ./.github/actions/os_setup

- name: fetch elixir dependencies
run: MIX_ENV=${{ inputs.mix-env }} mix deps.get

- name: print protobuf information
shell: bash
run: protoc --version

- name: compile elixir project
run: MIX_ENV=${{ inputs.mix-env }} mix compile
92 changes: 92 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Generate Docs
#
# I generate the documentation for the project.
# I compile the documentation and publish it on GitHub pages.
#
# I take three parameters:
# - mix-env: The environment to build the release for.
# - elixir-version: The version of Elixir to use.
# - otp-version: The version of OTP to use.
name: Generate Docs
on:
workflow_call:
inputs:
mix-env:
required: true
type: string
elixir-version:
required: true
type: string
otp-version:
required: true
type: string
jobs:
compile-docs:
runs-on: ubuntu-latest
steps:
- name: checkout the repository
uses: actions/checkout@v4

- name: setup deps and _build cache
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: ${{ runner.os }}-build-${{ inputs.mix-env }}-${{ hashFiles('mix.lock') }}

- name: setup elixir
uses: ./.github/actions/elixir_setup
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: install apt packages
uses: ./.github/actions/os_setup

# - name: compile docs
# shell: bash
# run: make docs-release
- name: generate docs
run: MIX_ENV=${{ inputs.mix-env }} mix docs

publish-docs:
environment:
name: github-pages
needs: compile-docs
runs-on: ubuntu-latest
steps:
- name: checkout the repository
uses: actions/checkout@v4

- name: setup deps and _build cache
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: ${{ runner.os }}-build-${{ inputs.mix-env }}-${{ hashFiles('mix.lock') }}

- name: setup elixir
uses: ./.github/actions/elixir_setup
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: install apt packages
uses: ./.github/actions/os_setup

- name: generate docs
run: MIX_ENV=${{ inputs.mix-env }} mix docs

- name: setup github pages
uses: actions/configure-pages@v5

- name: upload docs to github pages
uses: actions/upload-pages-artifact@v3
with:
path: "./doc"

- name: deploy github pages
id: deployment
uses: actions/deploy-pages@v4
80 changes: 80 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Lint
#
# I lint the codebase.
#
# I take three parameters:
# - mix-env: The environment to build the release for.
# - elixir-version: The version of Elixir to use.
# - otp-version: The version of OTP to use.
#
# Linting means the following.
# - Check if the code if formatted
# - Check if the code has trailing whitespaces
# - Check if the code has any issues reported by credo
# - Check if the code has any issues reported by dialyzer
name: Lint
on:
workflow_call:
inputs:
mix-env:
required: true
type: string
elixir-version:
required: true
type: string
otp-version:
required: true
type: string
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout the repository
uses: actions/checkout@v4

- name: setup deps and _build cache
uses: actions/cache@v4
with:
path: |
${{ github.workspace }}/deps
${{ github.workspace }}/_build
key: ${{ runner.os }}-build-${{ inputs.mix-env }}-${{ hashFiles('mix.lock') }}

- name: setup plt cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/plts
key: ${{ runner.os }}-plt-${{ inputs.mix-env }}-${{ hashFiles('**/*.ex') }}

- name: setup elixir
uses: ./.github/actions/elixir_setup
with:
elixir-version: ${{ inputs.elixir-version }}
otp-version: ${{ inputs.otp-version }}

- name: install apt packages
uses: ./.github/actions/os_setup

# strict credo may fail
- name: mix credo
shell: bash
continue-on-error: true
run: MIX_ENV=${{inputs.mix-env}} mix credo --strict

# non strict credo should be blocking
- name: mix credo
shell: bash
continue-on-error: false
run: MIX_ENV=${{inputs.mix-env}} mix credo

- name: mix format
shell: bash
run: MIX_ENV=${{inputs.mix-env}} mix format --check-formatted

- name: mix dialyzer
shell: bash
run: MIX_ENV=${{inputs.mix-env}} mix dialyzer --format github

- name: trailing whitespaces
shell: bash
run: git diff-tree --check 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD
42 changes: 42 additions & 0 deletions .github/workflows/on_main_or_next_or_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Push On Main/Next/Base
#
# This is the pipeline that will run for every push on main or next or base.
#
# The pipeline does the following.
# 1. Compile the source code for all environments (dev, test, prod)
# 2. Run the linter on the source code.
# 3. Run the entire test suite

name: Push On Main/Next/Base
run-name: Push on `${{ github.ref_name }}`

on:
push:
branches: ["main", "next", "base"]

jobs:
compile:
strategy:
matrix:
target: [dev, test, prod]
uses: ./.github/workflows/compile.yaml
with:
mix-env: ${{ matrix.target }}
elixir-version: "1.17"
otp-version: "27.1"

lint:
needs: compile
uses: ./.github/workflows/lint.yaml
with:
mix-env: "dev"
elixir-version: "1.17"
otp-version: "27.1"

test:
needs: compile
uses: ./.github/workflows/test.yaml
with:
mix-env: "test"
elixir-version: "1.17"
otp-version: "27.1"
Loading

0 comments on commit 3543b9f

Please sign in to comment.