Git Product home page Git Product logo

pipeline_test's Introduction

GitHub stars Last Commit Pull Requests


๐Ÿš€ Elevate Your Development.

"CI/CD Solution For Building Dapps on The Internet Computer Protocol"


pipeline_test

This Repo is a working example of a ci/cd pipeline for Dapps using motoko built on the Internet Computer

Convert your identity into a base64

base64 -i identity.pem

Add your base64 Identity to your repository secrets and name the secrets for each relevant env

For example DEVELOPEMNT, STAGING and PROD would be the name of your repository secrets and the workflow would access them using secrets.DEVELOPEMNT, secrets.STAGING and secrets.PROD

Continuous Integration with GitHub Actions

This repository uses GitHub Actions to automate testing and building of the project. The CI workflow is triggered on pull requests to the main, master, and development branches.

Workflow Configuration

The GitHub Actions workflow is defined in the .github/workflows/ci.yml file. Below is an explanation of the workflow configuration:

Trigger Events

The workflow is triggered on pull_request events targeting the following branches:

  • main
  • master
  • development

Jobs

The workflow defines a single job named test that uses a matrix strategy to run tests in parallel with different versions of Node.js, MOPS, and the Motoko compiler.

Job Strategy

The job strategy specifies the following:

  • Max Parallel: 2 (Runs a maximum of 2 jobs in parallel)
  • Matrix:
    • moc-version: [latest]
    • mops-version: [ic-mops@latest]
    • node-version: [20]

Job Steps

The job runs on an ubuntu-latest runner and includes the following steps:

  1. Checkout Repository:

    - uses: actions/checkout@v4
  2. Setup Node.js:

    - uses: actions/setup-node@v4
        with:
            node-version: ${{ matrix.node-version }}
            cache: 'npm'
  3. Install DFX:

    - name: Install dfx
        uses: dfinity/setup-dfx@main
  4. Confirm DFX Installation:

    - name: Confirm successful installation
        run: dfx --version
  5. Install DFX Cache:

    - name: Installing dfx cache
        run: dfx cache install
  6. Cache MOPS Packages:

    - name: Cache mops packages
        uses: actions/cache@v4
            with:
                key: mops-packages-${{ hashFiles('mops.toml') }}
                restore-keys: |
                mops-packages-${{ hashFiles('mops.toml') }}
                mops-packages-
                path: |
                ~/.cache/mops
  7. Install NPM Packages for CLI (Conditionally):

    - name: Install npm packages
        if: ${{ matrix.mops-version == './cli' }}
        run: cd cli && npm install
  8. Build Local CLI (Conditionally):

    - name: Build local cli
        if: ${{ matrix.mops-version == './cli' }}
        run: cd cli && npm run prepare
  9. Install MOPS:

    - name: Install mops
        run: npm i -g ${{ matrix.mops-version }}
  10. Install MOPS Packages:

    - name: Install mops packages
        run: mops install
  11. Select Moc Version:

    - name: Select moc version
        run: mops toolchain use moc ${{ matrix.moc-version }}
  12. Run Tests:

    - name: Run tests
        run: mops test    

Usage Instructions

  1. Add Workflow File: Save the provided YAML content into a file named ci.yml in the .github/workflows/ directory of your repository.

  2. Push to Repository: Commit and push the workflow file to your GitHub repository.

  3. Create Pull Requests: Create pull requests targeting the main, master, or development branches to trigger the CI workflow.

Continuous Deployment with GitHub Actions

This repository uses GitHub Actions to automate the deployment of the project. The CD workflow is triggered on closed pull requests to the main, master, staging, and development branches.

Workflow Configuration

The GitHub Actions workflow is defined in the .github/workflows/cd.yml file. Below is an explanation of the workflow configuration:

Trigger Events

The workflow is triggered on pull_request events with the closed type, targeting the following branches:

  • main
  • master
  • staging
  • development

Jobs

The workflow defines a single job named check-branch that runs if the pull request is merged. It includes steps for setting up the environment, caching packages, installing dependencies, and deploying to the appropriate network.

Job Steps

The job runs on an ubuntu-latest runner and includes the following steps:

  1. Checkout Repository:

    - uses: actions/checkout@v4
  2. Setup Node.js:

    - uses: actions/setup-node@v4
         with:
             node-version: 20
             cache: 'npm'
  3. Cache MOPS Packages:

    - name: Cache mops packages
         uses: actions/cache@v4
         with:
             key: mops-packages-${{ hashFiles('mops.toml') }}
             restore-keys: |
             mops-packages-${{ hashFiles('mops.toml') }}
             mops-packages-
             path: |
             ~/.cache/mops
  4. Install DFX:

    - name: Install dfx
         uses: dfinity/setup-dfx@main
  5. Confirm DFX Installation:

    - name: Confirm successful installation
         run: dfx --version
  6. Install DFX Cache:

    - name: Installing dfx cache
         run: dfx cache install
  7. Install MOPS:

    - name: Install mops
         run: npm i -g ic-mops@latest
  8. Install MOPS Packages:

    - name: Install mops packages
        run: mops install
  9. Deploy to Development:

    - name: Deploy to development
     if: github.base_ref == 'development'
     run: |
         echo ${{ secrets.DEVELOPMENT }} | base64 --decode > development.pem
         dfx identity import --storage-mode=plaintext development development.pem
         dfx identity use development
         dfx deploy --network development -y
    
  10. Deploy to Staging:

    - name: Deploy to staging
        if: github.base_ref == 'staging'
        run: |
            if [[ "${{ github.head_ref }}" != "development" ]]; then
                echo "Only changes from the development branch can be merged into staging."
                exit 1
            else
                echo ${{ secrets.STAGING }} | base64 --decode > staging.pem
                dfx identity import --storage-mode=plaintext staging staging.pem
                dfx identity use staging
                dfx deploy --network staging -y
            fi
  11. Check Source for Master:

    - name: Check source for master
        if: github.base_ref == 'master'
        run: |
                if [[ "${{ github.head_ref }}" != "staging" ]]; then
                    echo "Only changes from the staging branch can be merged into master."
                    exit 1
                else
                    echo ${{ secrets.PROD }} | base64 --decode > prod.pem
                    dfx identity import --storage-mode=plaintext prod prod.pem
                    dfx identity use prod
                    dfx deploy --network ic -y
                fi

Conclusion

By following these steps, you'll set up a robust CI pipeline that automatically tests your code using the specified matrix of Node.js, MOPS, and Motoko versions aswell as a robust CD pipeline that automatically deploys your code to different environments, ensuring higher reliability and consistency in your deployment process.

pipeline_test's People

Contributors

allidoizcode avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.