11

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

CyberPunk
  • 1,297
  • 5
  • 18
  • 35
  • 1
    Easiest work-around - dockerize the whole process, then only use docker command on the CI (GitHub Actions) side. If you dockerize, it becomes inter-operable between any CI and you don't need to adjust for a specific environment. This is generally a best practice for all issues like smth doesn't work in the CI environment. – taleodor Apr 02 '21 at 13:47
  • Yes indeed I would dockerize it make build would eventually run test and build the docker – CyberPunk Apr 03 '21 at 10:48
  • I think the comment from @taledor is very interesting. I don't like the fact I can't build locally with GH actions, and being able to have a Dockerfile for my build rather than a GH .yaml for actions, seems like it might be a win. – Cameron Aug 20 '21 at 17:23

1 Answers1

29

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.

GuiFalourd
  • 15,523
  • 8
  • 44
  • 71
  • And how to parse Github Action Variables in the Makefile? The targets do not seem to parse the variables as how these are configured on the repository, the Github Action log stays empty. – Rvanlaak Jul 05 '23 at 14:03
  • Did you try using something as specified in [this thread](https://stackoverflow.com/questions/2826029/passing-additional-variables-from-command-line-to-make) through shell commands, using those Github Actions variables? (before running the `make build`) – GuiFalourd Jul 05 '23 at 14:11
  • 1
    It seemed that Github requires manually setting all environment variables on the specific job, and does not by default set all variables / secrets inside the job's execution context. – Rvanlaak Jul 06 '23 at 10:12