Skip to content

Generates a CI file for Github or Gitlab #3

@matheuscamarques

Description

@matheuscamarques

Objective:

Create CI (Continuous Integration) files for GitHub and GitLab that include the basic steps for running code quality and security checks in an Elixir project.

Basic Steps to Run:

  1. mix format --dry-run --check-formatted: Check if the code is formatted according to the defined rules.
  2. mix deps.unlock --check-unused: Check for unused dependencies.
  3. mix deps.audit: Audit dependencies for known vulnerabilities.
  4. mix hex.audit: Audit Hex packages for vulnerabilities.
  5. mix sobelow: Run security checks on the code.
  6. mix credo: Run static analysis and check code for style compliance.
  7. mix doctor: Evaluate code documentation.
  8. mix test --cover: Run unit tests and generate a code coverage report.

Functional Requirements:

  • Generate CI file for GitHub.
  • Generate CI file for GitLab.

See Other Approaches:

  • Generate CI file for BitBucket.
  • Other CI file patterns.

Useful Resources and References

GitHub Actions:

  1. Official GitHub Actions Documentation: GitHub Actions Documentation
  2. Tutorial on GitHub Actions for Elixir: Elixir CI with GitHub Actions

GitLab CI/CD:

  1. Official GitLab CI/CD Documentation: GitLab CI/CD Documentation
  2. Setting Up GitLab CI/CD for Elixir Projects: Setting Up GitLab CI/CD for Elixir Projects

BitBucket Pipelines:

  1. Official BitBucket Pipelines Documentation: BitBucket Pipelines Documentation
  2. Example CI for Elixir on BitBucket: Example CI for Elixir on BitBucket

Other CI File Patterns:

  1. CircleCI for Elixir Projects: CircleCI Configuration for Elixir Projects
  2. Travis CI for Elixir Projects: Travis CI Configuration for Elixir Projects

CI File Examples

GitHub Actions (.github/workflows/ci.yml):

name: CI

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Elixir
      uses: actions/setup-elixir@v1
      with:
        otp-version: '23.0'
        elixir-version: '1.11.2'
    - name: Install dependencies
      run: mix deps.get
    - name: Run format check
      run: mix format --dry-run --check-formatted
    - name: Check unused dependencies
      run: mix deps.unlock --check-unused
    - name: Audit dependencies
      run: mix deps.audit
    - name: Audit Hex packages
      run: mix hex.audit
    - name: Run Sobelow security checks
      run: mix sobelow
    - name: Run Credo code analysis
      run: mix credo
    - name: Evaluate documentation
      run: mix doctor
    - name: Run tests with coverage
      run: mix test --cover

GitLab CI (.gitlab-ci.yml):

stages:
  - check
  - test

check:
  stage: check
  image: elixir:1.11.2
  script:
    - mix local.hex --force
    - mix deps.get
    - mix format --dry-run --check-formatted
    - mix deps.unlock --check-unused
    - mix deps.audit
    - mix hex.audit
    - mix sobelow
    - mix credo
    - mix doctor

test:
  stage: test
  image: elixir:1.11.2
  script:
    - mix local.hex --force
    - mix deps.get
    - mix test --cover

These examples provide a solid foundation for setting up continuous integration using GitHub Actions and GitLab CI/CD for Elixir projects. To adapt these files for BitBucket or other CI tools, consult the specific documentation and adjust accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions