Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github worker does not find python script

I wanted to setup a website hosted by Github Pages. To do that, I wanted to run a python script, that generates html-files from jinja (I know this is probably terrible, but it is the best I have)

My app.py is in the root of the project. For the worker, after setting up python and installing the libraries I go:

- name: run python script
  run: python3 app.py

However the build fails with the message:

python3: can't open file '/home/runner/work/sty"rix560.github.io/styrix560.github.io/app.py': [Errno 2] No such file or directory

So it is looking exactly where it should, but does not find the file. Where is my file?

like image 898
styrix358 Avatar asked Jan 24 '26 08:01

styrix358


1 Answers

To access files at the repository root in your github actions workflow, you need to use the actions/checkout action first.

This action checks-out your repository under $GITHUB_WORKSPACE, so your workflow can access it.

Here is a full example:

name: Python Script Workflow

on:
  push:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository content
        uses: actions/[email protected] # Checkout the repository content to github runner.

      - name: Setup Python Version
        uses: actions/setup-python@v2
        with:
          python-version: 3.8 # Install the python version needed

      - name: Install Python dependencies
        run: python -m pip install --upgrade pip requests # Install the dependencies (if needed)

      - name: Execute Python script # Run the script.py file to get the latest data
        run: python script.py
  • Here is a personal workflow implementation as example.
  • You can find the workflow runs of this workflow here.
like image 73
GuiFalourd Avatar answered Jan 26 '26 23:01

GuiFalourd