predictionmachine / pm-github-actions

Repository for common GitHub Actions workflows for Prediction Machine
MIT License
3 stars 1 forks source link

A Helpful GitHub Actions Workflow

MIT license PM CI workflow codecov Maintainability Code style: black

This repository provides a GitHub Actions workflow to check and nicely comment on pull requests in python code bases.

It will help with:

It also reports to codecov and codeclimate quality to help you have a healthier, easier to evolve codebase.


Folder structure convention

Getting these tools and checks to work together nicely takes some configuration. The expected layout is:

.
├── .github
│   └── workflows              # Workflow directory for your workflow files
│       └── pm-gh-actions.yml
├── projectname                # Project directory - top level directory for project
│   └── example.py
├── .codeclimate.yml           # Configuration file for codeclimate analysis
├── .pre-commit-config.yaml    # pre-commit configuration file, see https://pre-commit.com
├── pyproject.toml             # Configuration file for black, interrogate, mypy & pytest
├── requirements-dev.txt       # Development requirements file
├── requirements.txt           # Requirements file
├── setup.cfg                  # Configuration file for flake8, mypy
└── tests                      # Test directory for project level tests
    └── projectname
        └── test_example.py

Installation:

Take the workflow for a spin by making a PR in your repo.


How it works:

The checks in the work flow include:

Note: For the above checks, the github-actions bot will comment on the issues in the PR and fail the relevant check if it finds problems.


Few screenshots from the PR:

(see more screenshots here)

The GH action from marketplace used are:

FAQ

Question: What's GITHUB_TOKEN and do I need to set it up to run pm-gh-actions.yml?

Answer: No. GitHub automatically creates a GITHUB_TOKEN secret to use in your workflow. You can use the GITHUB_TOKEN to authenticate in a workflow run. When you enable GitHub Actions, GitHub installs a GitHub App on your repository. TheGITHUB_TOKEN secret is a GitHub App installation access token. You can use the installation access token to authenticate on behalf of the GitHub App installed on your repository. The token's permissions are limited to the repository that contains your workflow. Before each job begins, GitHub fetches an installation access token for the job. The token expires when the job is finished. You can read more about this here

Question: How can I add secrets to repo and test them in workflow?

Answer: Yep. Secrets are encrypted environment variables that you create in an organization, repository, or repository environment. To use the secret, simply use an expression: ${{ secrets.YOUR_SECRET_NAME }} in a workflow step. You can read more about how to setup secrets

Question: How do I tweak configurations of the checkers?

Answer: If you want to pass additional args, change location of config file, proceed as follows:

Question: How can I execute an additional workflow after this workflow succeeds?

Answer: If you want to make a conditional run (stage-wise/sequential) for your existing workflow after successful execution of pm-gh-actions.yml workflow then include following yml code in your existing workflow file on top:

```yaml
on:
 workflow_run:
      workflows: ["PM CI Workflow"] # name of the workflow you want to execute after
      types:
        - completed
```

In our case, workflows: ["PM CI Workflow"] - "CI Workflow" is the workflow name of pm-gh-actions.yml

Question: How does hardcoded secrets scan work in the workflow?

Answer: The workflow uses reviewdog/action-detect-secrets action to detect the secrets in code. reviewdog/action-detect-secrets action uses detect-secrets which is a module for detecting secrets within a code base. \ For tweaking the behaviour of secret scan for the workflow run, you can change the configuration of reviewdog/action-detect-secrets in pm-gh-actions.yml. \ For more details please see reviewdog/action-detect-secrets and detect-secrets


Developed and used by Prediction Machine.