Code Monkey home page Code Monkey logo

g-force's Introduction

G-Force

A set of utilities that interact with the Salesforce.com API

apexcov

A CLI tool that can be used in CI/CD pipelines with Salesforce.

apexcov [-strategy=<value>] [-config=<value>] [-packages=<value>]
  -config
        Path to SF org authentication information (config.json) (default "config.json")
  -package
        Comma-separated list of paths to manifest (package.xml) (default "package.xml")
  -strategy
        Choose the strategy of getting coverage (default "MaxCoverage"):
          - "MaxCoverage" to ouput all tests that provide coverage for the passed in Apex
          - "MaxCoverageWithDeps" to output all tests for the passed in Apex and its dependencies

Installation

The recommended way is to download and decompress an executable from the latest release directly within your CI/CD pipeline.

Alternatively, can be installed on a system with pre-installed Go with the following command:

go install github.com/achere/g-force/cmd/apexcov@latest

Usage

apexcov takes a package.xml manifest as input and returns a string of space-separated list of Apex test class names that provide coverage for the included Apex classes and triggers. This list can then be passed to an sf project deploy start -l RunSpecifiedTests command (or sf project deploy validate ...) as an argument for the -t flag. Since you can also have destructive changes separately, apexcov supports parsing multiple .xml files. Provide a comma-separated list of paths to .xml files via the -packages flag.

The tool connects to an org that must have the coverage information for the metadata specified in the package.xml file which requires the tests to be run prior to apexcov. In case of insufficient coverage (less than 75% for all code to be deployed or any individual class or trigger), apexcov will exit with code 1 and will print the error to the stderr. Currently, the connection supports only the Client Credentials Flow so you have to have the Connected App set up with appropriate settings. Provide the authentication information as a path to a JSON file with the following fields via the -config flag:

{
    "apiVersion":   "60.0",
    "baseUrl":      "https://your-domain.my.salesforce.com",
    "clientId":     "<CONSUMER_KEY>",
    "clientSecret": "<CONSUMER_SECRET>",
}

Tests can be provided using different strategies by passing an appropriate value to the -strategy flag:

  • MaxCoverage: maximum coverage
    Outputs all the tests that cover the provided Apex classes and triggers contained in the passed package.xml files

  • MaxCoverageWithDeps: maximum coverage with dependencies
    First calls the Salesforce Metadata Dependency API to collect all Apex classes the classes and triggers in the package.xml files depend on, then request and parse code coverage for both initial classes and their dependencies. Code coverage requirements are skipped for the dependencies as they are not mandatory for the deployment.

Related

A package that, when installed in an org, can be connected to Gitlab to create a config.json file with authentication information for that org as a CI/CD variable.

g-force's People

Contributors

achere avatar

Watchers

 avatar

g-force's Issues

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.