devol-accounts-kit 0.3.4

SDK for interacting with the DeVol Network option trading platform on the Solana blockchain
Documentation
name: Rust CI

on:
  pull_request:
    branches: [ "master" ]
  workflow_dispatch:

env:
  CARGO_TERM_COLOR: always

jobs:
  check_version_and_changelog:
    runs-on: ubuntu-latest
    permissions: 
      issues: write
      pull-requests: write
      repository-projects: write
    steps:
      - name: Setup SSH
        uses: webfactory/ssh-agent@v0.7.0
        with:
          ssh-private-key: ${{ secrets.SSH_KEY_DEVOL_ACCOUNTS_KIT }}

      - name: Cargo Config to use CLI with Git
        run: |
          mkdir -p .cargo
          echo '[net]' >> .cargo/config.toml
          echo 'git-fetch-with-cli = true' >> .cargo/config.toml
          
      - uses: actions/checkout@v4
      
      - name: Checkout Master Branch
        uses: actions/checkout@v4
        with:
          ref: 'master'

      - name: Get Version from Master Branch
        run: |
          echo "MASTER_VERSION=$(cargo read-manifest | jq -r .version)" >> $GITHUB_ENV

      - name: Checkout Current Branch
        uses: actions/checkout@v4

      - name: Get Version from Current Branch
        run: |
          echo "PR_VERSION=$(cargo read-manifest | jq -r .version)" >> $GITHUB_ENV

      - name: Check if the version in Cargo.toml has been increased
        run: |
          echo "Master version: ${{env.MASTER_VERSION}}"
          echo "PR version: ${{env.PR_VERSION}}"
          IFS='.' read -r -a PR_VERSION_PARTS <<< "$PR_VERSION"
          IFS='.' read -r -a MASTER_VERSION_PARTS <<< "$MASTER_VERSION"
          if ! ([ "${PR_VERSION_PARTS[0]}" -gt "${MASTER_VERSION_PARTS[0]}" ] ||
             ([ "${PR_VERSION_PARTS[0]}" -eq "${MASTER_VERSION_PARTS[0]}" ] &&
              [ "${PR_VERSION_PARTS[1]}" -gt "${MASTER_VERSION_PARTS[1]}" ]) ||
             ([ "${PR_VERSION_PARTS[0]}" -eq "${MASTER_VERSION_PARTS[0]}" ] &&
              [ "${PR_VERSION_PARTS[1]}" -eq "${MASTER_VERSION_PARTS[1]}" ] &&
              [ "${PR_VERSION_PARTS[2]}" -gt "${MASTER_VERSION_PARTS[2]}" ])); then
            echo "ERROR_MESSAGE=The version number (${{env.PR_VERSION}}) in Cargo.toml is not greater than the master branch version (${{env.MASTER_VERSION}})" >> $GITHUB_ENV
            exit 1
          fi
          
      - name: Check Changelog entry
        run: |
          if ! grep -q "## \[${{env.PR_VERSION}}\]" CHANGELOG.md; then
            echo "ERROR_MESSAGE=No changelog entry found for version ${{env.PR_VERSION}} in CHANGELOG.md." >> $GITHUB_ENV
            exit 1
          fi
          
      - name: Post errors to PR on check failure
        if: failure()
        uses: peter-evans/create-or-update-comment@v4
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            :x: **Check Failed!**
            ```
            ${{env.ERROR_MESSAGE}}
            ```
          reactions: eyes

  build_and_test:
    needs: check_version_and_changelog
    runs-on: ubuntu-latest
    permissions: 
      issues: write
      pull-requests: write
      repository-projects: write
    steps:
      - name: Setup SSH
        uses: webfactory/ssh-agent@v0.7.0
        with:
          ssh-private-key: ${{ secrets.SSH_KEY_DEVOL_ACCOUNTS_KIT }}

      - name: Cargo Config to use CLI with Git
        run: |
          mkdir -p .cargo
          echo '[net]' >> .cargo/config.toml
          echo 'git-fetch-with-cli = true' >> .cargo/config.toml
          
      
      - uses: actions/checkout@v4
          
      - name: Build
        id: off_chain_build
        run: cargo build

      - name: Test off-chain
        id: off_chain_test
        if: success() && !cancelled()
        run: cargo test
        
      - name: Test on-chain
        id: on_chain_test
        if: success() && !cancelled()
        run: cargo test --features "on-chain"