1

I have a Python script that scrapes files to search for a regex pattern. I would like to run this script using a Github Action. Furthermore, I want this same action and script to be used in several private GH repos without copying/pasting anything.

I have created a repo with a composite GHA

composite-actions-repo
|.
├── action.yml
└── main.py
### action.yml

name: 'RegEx check'
description: 'Scans files for regex pattern'
inputs:
  python_version:
    description: |
      Python Version
      Default is '3.10'.
    default: '3.10'
runs:
  using: "composite"
  steps:
    - id: setup-python
      name: setup python
      uses: actions/setup-python@v4
      with:
        python-version: ${{ inputs.python_version }}
    - id: regex-check
      name: Find regex pattern
      shell: bash
      run: python main.py

I want the main.py script checks contents of all files in the repo that is running action for a regex pattern.

There are several private repos I want to run this composite action and I'm trying to use this workflow:

### a-private-repo/.github/workflows/main.yml

name: CI

on: [push]

jobs:
  py_job:
    runs-on: ubuntu-latest
    name: Check for RegEx
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: execute py script # run main.py
        uses: company/composite-actions-repo@v1

I'm currently getting an error in GHA logs that it can't find the main.py file

python: can't open file '/home/runner/work/a-private-repo/a-private-repo/main.py': [Errno 2] No such file or directory
Error: Process completed with exit code 2.

The thing I can't wrap my head around is how to reference the main.py in composite-actions-repo from a-private-repo and at the same time use main.py to scan the files in a-private-repo.

2
  • 4
    It should work using run: python ${{ github.action_path }}/main.py instead. Otherwise the action will look for the main.py file at the repository root you fetch with the checkout action. Commented Dec 28, 2023 at 16:44
  • 3
    See runs.steps[*].run for examples. Commented Dec 28, 2023 at 16:45

1 Answer 1

2

Per GuiFalourd's comment, I just had to add ${{ github.action_path }} in action.yml

name: 'RegEx check'
description: 'Scans files for regex pattern'
inputs:
  python_version:
    description: |
      Python Version
      Default is '3.10'.
    default: '3.10'
runs:
  using: "composite"
  steps:
    - id: setup-python
      name: setup python
      uses: actions/setup-python@v4
      with:
        python-version: ${{ inputs.python_version }}
    - id: regex-check
      name: Find regex pattern
      shell: bash
      run: python ${{ github.action_path }}/main.py
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.