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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With