Search code examples
continuous-integrationgithub-actions

How to use your own Makefile in github actions?


I am trying to automate a CI/CD pipeline using github actions. I have a Makefile as below:

.virtualenv:
    virtualenv -p python3 .virtualenv
    . .virtualenv/bin/activate; \
    pip install -r requirements.txt -r requirements_test.txt

clean:
    find . -name __pycache__ -exec rm -rf {} +
    rm -rf *.egg-info
    rm -rf .virtualenv/


test: .virtualenv
    (. .virtualenv/bin/activate; \
    pycodestyle --max-line-length=79 app test; \
    nosetests --with-coverage --cover-tests --cover-min-percentage=80 --cover-package=app test)

build: test clean

.PHONY: test clean

I want to use github actions to automate this workflow. I have setup my github workflow like this:

name: python-app

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: build application
      run: make build

What I want is when there is a push to master or a PR is created against master the workflow should be triggered. I know there is a standard template to test python applications given here: https://docs.github.com/en/actions/guides/building-and-testing-python#testing-your-code but I want to do it via my own Makefile. When I run this I get this error:

every step must define a uses or run key

Any leads in this regard would be helpful. thanks


Solution

  • When you want to execute files from the current repository, you need to use the actions/checkout

    This will allow you to access the repository $github_workspace (one of Github environment variables) in your workflow.

    For example, considering that your Makefile file is at the root of the repository, you would use something like this:

       name: python-app
    
       on:
         push:
           branches: [ master ]
         pull_request:
           branches: [ master ]
    
       jobs:
        build:
          runs-on: ubuntu-latest
          steps:
          - name: checkout repo
            uses: actions/checkout@main
          - name: build application
            run: make build
    

    Here is another workflow example from a personal repository, following the same logic if you want to execute a specific script to perform any operation.