{"id":4594,"date":"2020-01-14T12:39:30","date_gmt":"2020-01-14T18:39:30","guid":{"rendered":"https:\/\/coderrect.com\/?post_type=docs&p=4594"},"modified":"2021-01-15T00:46:43","modified_gmt":"2021-01-15T06:46:43","slug":"github-actions","status":"publish","type":"docs","link":"https:\/\/coderrect.com\/docs\/github-actions\/","title":{"rendered":"Github Actions"},"content":{"rendered":"\n
If you are already using GitHub Action<\/a> as your CI\/CD<\/a>\u00a0service, it is easy to integrate Coderrect to your\u00a0workflows.<\/p>\n\n\n\n In a nutshell, add the following to your .github\/workflows\/ci.yml:<\/p>\n\n\n\n Continuous Integration\/Continuous Delivery (CI<\/em>\/CD<\/em>) is a common practice now for developing software. In CI, typically tests and checks are run against every pull request and code commit to ensure the new code changes do not break anything or introduce new bugs. CI makes it easier to fix bugs quickly and often.<\/p>\n\n\n\n If your code is hosted on GitHub, you can create custom CI\/CD workflows directly in your GitHub repository with GitHub Actions<\/a>.<\/p>\n\n\n\n In this tutorial, we take memcached<\/a> as an example project to demonstrate how to set up GitHub Actions.<\/p>\n\n\n\n To start, you can click the \u201cAction\u201c tab above your GitHub Repository.<\/p>\n\n\n\n Once you enter the Action tab, GitHub will guide you to create your own CI\/CD script by providing different template scripts based on different building system.<\/p>\n\n\n\n Here we select \u201cset up a workflow yourself<\/strong>\u201c to use the basic template.<\/p>\n\n\n\n GitHub will automatically create a YAML file (main.yml by default) under .github\/workflows and this is the path which you should put your future scripts under. The left-hand side is the script editor and the right-hand side is the place you can search different existing Action scripts published in GitHub Marketplace.<\/p>\n\n\n\n The default template script looks similar as below, we will explain it in detail:<\/p>\n\n\n\n The definition of an action consists of two major parts: on and jobs.<\/p>\n\n\n\n Field on defines when this action will be triggered. The default template only triggers the action when there\u2019s a push or pull request made upon the main branch.<\/p>\n\n\n\n For example, if you want the action to be triggered at any event on any branch, you can simply change the script to:<\/p>\n\n\n\n If you only want to trigger actions manually, then you should specify workflow_dispatch instead. This will create a button in the Action Tab for you to trigger them manually later. Check out this blog<\/a> on how to manually trigger GitHub Actions.<\/p>\n\n\n\n Field job defines the actual workflow of the action. The subfield build is a customized job name, and you can change it to something more meaningful, such as test-build-on-ubuntu.<\/p>\n\n\n\n runs-on specifies the system image on which you want to run your CI\/CD tasks.<\/p>\n\n\n\n steps specifies the detailed sub-tasks performed in a job. You can compose your CI\/CD job using the published Actions from GitHub Marketplace and your own customized scripts.<\/p>\n\n\n\n Coderrect provides a GitHub Action in Marketplace for you to integrate it into your CI\/CD process easily.<\/p>\n\n\n\n In general, integrating Coderrect requires 3 steps:<\/p>\n\n\n\n Step 1 checks out your GitHub repository, using an action provided by GitHub.<\/p>\n\n\n\n Step 2 installs all dependencies required for build the project (\u201cInstall deps\u201d) and does a test build (\u201cBuild\u201c). Note that including task \u201cBuild\u201c is not required for Coderrect to function, but it\u2019s critical to make sure your project can successfully build before applying Coderrect.<\/p>\n\n\n\n Step 3 applies Coderrect to your project. You can search the GitHub Marketplace to obtain the most updated script and all available options.<\/p>\n\n\n\n Once this script is saved, the GitHub Action you just defined will be automatically triggered when you push new commits or merge pull requests. You can review them by entering the \u201cAction\u201c tab.<\/p>\n\n\n\n By clicking the specific task (\u201cUpdate ci.yml\u201c in the example above), you can view its detailed results.<\/p>\n\n\n\n To see Coderrect\u2019s race detection report, you can click task \u201ccoderrect scan\u201c to expand its terminal output. Coderrect will output a list of summary for all executables it analyzes and also attach an report link at the end for you to view them in detail.<\/p>\n\n\n\n If you are using a different building system (e.g., CMake) or a different language or compiler, then you need to properly configure Coderrect. Here we provide instructions for some commonly used configurations, more detailed instructions can be found on our GitHub Action page<\/a> and Coderrect documentation<\/a>.<\/p>\n\n\n\n You will need to install and setup cmake first.<\/p>\n\n\n\n One significant difference for CMake projects is that you need to specify the build path. For example, if you are building your project under .\/build, then you need to specify the build path using following script:<\/p>\n\n\n\n You will need to install the FORTRAN compiler. For example:<\/p>\n\n\n\n Then it is likely that you need to specify the FORTRAN compiler when you use make.<\/p>\n\n\n\n If so, Coderrect provides an optional input called buildCommand to specify your customized build command.<\/p>\n\n\n\n Coderrect\u2019s GitHub Action provides an input called options that allows you to provide arbitrary options supported in Coderrect\u2019s CLI. A common use case is to provide Coderrect with a fully-customized JSON configuration using -conf.<\/p>\n\n\n\n
\n\n\n\n- name: Coderrect Scan\n uses: coderrect-inc\/coderrect-github-action@main <\/pre>\n\n\n\n
Background<\/h2>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
# This is a basic workflow to help you get started with Actions\nname: CI\n\n# Controls when the action will run.\non:\n push:\n branches: [ master ]\n pull_request:\n branches: [ master ]\n\n # Allows you to run this workflow manually from the Actions tab\n workflow_dispatch:\n\n# Defines the workflow of this action.\njobs:\n # This workflow contains a single job called \"build\"\n build:\n # The type of runner that the job will run on\n runs-on: ubuntu-latest \n\n # Steps represent a sequence of tasks that will be executed as part of the job\n steps:\n # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it\n - uses: actions\/checkout@v2\n\n # Runs a single command using the runners shell\n - name: Run a one-line script\n run: echo Hello, world!\n\n # Runs a set of commands using the runners shell\n - name: Run a multi-line script\n run: |\n echo Add other actions to build,\n echo test, and deploy your project.<\/pre>\n\n\n\n
on: [push, pull_request]<\/pre>\n\n\n\n
\n\n\n\nIntegrating Coderrect into Github CI<\/h2>\n\n\n\n
steps: \n# step 1 \n- uses: actions\/checkout@v2 \n# step 2 \n- name: Install deps\n run: |\n sudo apt-get update -y\n sudo apt-get install -y libevent-dev libseccomp-dev git libsasl2-dev \n- name: Build\n run: |\n gcc --version\n .\/autogen.sh\n .\/configure --enable-seccomp --enable-tls --enable-sasl --enable-sasl-pwdb\n make -j \n# step 3 \n- name: coderrect scan\n uses: coderrect-inc\/coderrect-github-action@main<\/pre>\n\n\n\n
<\/figure><\/div>\n\n\n\n
<\/figure><\/div>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nConfigure Coderrect GitHub Action:<\/h2>\n\n\n\n
For CMake projects<\/h3>\n\n\n\n
- name: download cmake\n run: |\n wget https:\/\/cmake.org\/files\/v3.18\/cmake-3.18.2-Linux-x86_64.tar.gz\n tar xf cmake-3.18.2-Linux-x86_64.tar.gz\n mkdir build && cd build\n ..\/cmake-3.18.2-Linux-x86_64\/bin\/cmake .. <\/pre>\n\n\n\n
- name: Coderrect Scan\n uses: coderrect-inc\/coderrect-github-action@main\n with:\n buildPath: \"build\"<\/pre>\n\n\n\n
For FORTRAN projects<\/h3>\n\n\n\n
- name: Install fortran\n run: |\n sudo apt-get update -y\n sudo apt-get install -y gfortran<\/pre>\n\n\n\n
- name: coderrect scan\n uses: coderrect-inc\/coderrect-github-action@v1.2\n with:\n buildCommand: \"make COMPILER=GNU MPI_COMPILER=gfortran C_MPI_COMPILER=gcc\"<\/pre>\n\n\n\n
For customized analysis<\/h3>\n\n\n\n