How to run a script directly from a repository
  • 1 Minute to read
  • Dark
    Light
  • PDF

How to run a script directly from a repository

  • Dark
    Light
  • PDF

Article summary

Running code directly from your repository is easy. Make sure you install the proper build/runtime tools to the Workflow.yml file. This example uses Python which is supported by default.

Our Actions Demo contains an example workflow file that calls Python scripts.

Here is an excerpt that calls two different Python scripts:

# Python-py-allspice demo repository
# This workflow demonstrates how to use Python and py-allspice to interact with the AllSpice API
# AllSpice Actions documentation: https://learn.allspice.io/docs/actions-cicd
name: Python-py-allspice
on: 
  push:
  issues:
    types: [opened, closed, reopened]

jobs:
  py-allspice test:
    runs-on: ubuntu-latest
    steps:
      # Check out repository code
      - name: "[πŸ“š->πŸ–₯️] Check out repository code"
        uses: actions/checkout@v4

      - name: "[πŸ”Ž->πŸ“‚] List files in repo πŸ”Ž"
        run: |
          ls -la ${{ allspice.workspace }}          

      # Installs python requirements from the requirements.txt file
      - name: "[🀼->πŸ–₯️] Install python requirements"
        run: pip install -r .allspice/utils/requirements.txt

      # Call a python script from the .allspice/utils directory
      - name: "[πŸƒ->🐍] Run .allspice/utils/hello-world.py πŸ”Ž"
        run: python .allspice/utils/hello-world.py

      # Run the py-allspice self-test script, this will ping the server and verify the API is working
      # Parameters: ${allspice.server_url} and ${allspice.token} are automatic Workflow variables and are used to authenticate the AllSpice API
      - name: "[πŸ”‘->πŸ•ΈοΈ] Test AllSpice API with py-allspice πŸ”Ž"
        run: python .allspice/utils/py-allspice-BIST.py --allspice_hub_url ${{ allspice.server_url }}  --allspice_token ${{ allspice.token }}

This excerpt demonstrates how easy it is to call a Python script from any folder in the repository.
Simply run python path/to/your/python-script.py

      # Call a python script from the .allspice/utils directory
      - name: "[πŸƒ->🐍] Run .allspice/utils/hello-world.py πŸ”Ž"
        run: python .allspice/utils/hello-world.py

The second example shows how to easily pass data via command line parameters:

run: python .allspice/utils/py-allspice-BIST.py --allspice_hub_url ${{ allspice.server_url }}  --allspice_token ${{ allspice.token }}


Was this article helpful?