CI CD Pipeline - green-ecolution/backend GitHub Wiki

CI/CD & GitHub Actions

CI/CD (Continuous Integration & Continuous Deployment/Delivery) is a software development approach that uses automation to quickly and reliably deliver code changes to production.

  • Continuous Integration (CI) ensures that code changes are automatically tested and integrated as soon as they are pushed to the repository.
  • Continuous Deployment/Delivery (CD) automates the release of tested code to testing or production environments.

GitHub Actions is an automation platform within GitHub that enables CI/CD workflows. It allows developers to manage build, test, and deployment processes directly in their repositories.

In this section provides an overview of specific GitHub Actions workflows that are used in this project. Below you will find details on the specific workflows:

Used Workflows

build-and-push-develop.yaml

  • Use: Automates the build, deployment, and API documentation process for the develop branch
  • Trigger: Activated with every push to the develop branch.
  • Tasks:
    • Updates the test coverage badge
    • Builds the project
    • Builds and pushes the Docker image to GitHub Container Registry (GHCR)
    • Notifies the management repository to update submodules
    • Checks if the API documentation is up-to-date and uploads if necessary
    • Creates a pull request in the frontend repository if API docs need to be updated

build-and-push-production.yaml

  • Use: Automates the build and push process for production releases
  • Trigger: Activated when a pull request from a release or hotfix branch is merged into main
  • Tasks:
    • Extracts the version from the branch name
    • Creates a GitHub release
    • Merges main into develop
    • Builds and pushes the Docker image to GitHub Container Registry (GHCR)
    • Notifies the management repository to update submodules

build-and-push-stage.yaml

  • Use: Automates the build and push process for the staging environment
  • Trigger: Activated on push to release or hotfix branches, or manually via workflow dispatch.
  • Tasks:
    • Extracts the version from the branch name
    • Builds and pushes the Docker image to GitHub Container Registry (GHCR)
    • Notifies the management repository to update submodules

build-and-test-on-pr.yaml

  • Use: Ensures that pull requests (PRs) are built and tested before they are merged
  • Trigger: Activated when a new pull request is created against the develop branch
  • Tasks:
    • Builds the state of the PR
    • Executes all defined tests to ensure the integrity of the code
    • Tests the pkg/client module

generate-client-pkg.yaml

  • Use: Automates the process of generating and committing updates to the Green Ecolution client package when changes are pushed to the develop branch
  • Trigger: Activated when changes are pushed to the develop branch.
  • Tasks:
    • Generates the client package using a make command.
    • Commits and pushes any updates to the pkg/client directory.
    • Initializes Git configuration for the commit

linter-on-pr.yaml

  • Use: Runs linting checks on the codebase to enforce code quality standards for both the develop and main branches
  • Trigger: Activated on push to develop and main branches, as well as on pull requests targeting these branches
  • Tasks:
    • Installs necessary dependencies
    • Sets up the Go environment
    • Generates necessary files or code using the make generate command
    • Runs the golangci-lint tool to perform static analysis and identify issues in the Go codebase.

notify-on-new-issue.yaml

  • Use: Sends notifications in Discord when a new issue is created
  • Trigger: Activated when a new issue is created.
  • Tasks:
    • Sends a notification in Discord to a channel to inform about the new issue

notify-on-reviewer-needed.yaml

  • Use: Sends notifications in Discord when a pull request requires a reviewer. Is triggered when the need-reviewer tag is set in the PR.
  • Trigger: Activated when a pull request is created and the need-reviewer tag is set.
  • Tasks:
    • Sends a notification in Discord to a channel to inform about the review

test-migrations-on-pr.yaml

  • Use: Verifies the integrity of PostgreSQL migrations and seed data to ensure the database schema is correctly modified and seeded
  • Trigger: Activated on pull requests targeting the develop branch
  • Tasks:
    • Spins up a PostgreSQL service with the necessary environment variables
    • Sets up dependencies and installs Goose (a database migration tool)
    • Tests PostgreSQL migrations in multiple stages (up, down, reset)
    • Tests the application of seed data in the database to ensure proper initialization and validation
    • Verifies that seed data can also be correctly rolled back