Skip to content

How to use Neptune with GitHub Actions#

To leverage Neptune as part of a GitHub Action, take the following steps:

  1. Set your Neptune API token as an environment variable by creating an encrypted secret for your GitHub repository:

    1. In your GitHub repository, go to SettingsSecretsNew repository secret.
    2. In the Name input box, enter NEPTUNE_API_TOKEN.
    3. Enter your Neptune API token as the value.

      How do I find my API token?

      In the bottom-left corner of the Neptune app, open the user menu and select Get your API token.

      You can copy your token from the dialog that opens. It's very long – make sure to copy and paste it in full!

    4. Click Add secret.

    Tip

    You can also add your Neptune project name (NEPTUNE_PROJECT) and other variables. For details, see Environment variables.

  2. Add the Neptune client library to your dependencies:

    In your workflow YAML file under .github/workflows/, add a Neptune installation command to the run: option:

    name: neptune-example
    on: [push]
    jobs:
      set-up-neptune:
        runs-on: ubuntu-latest
        env:
          NEPTUNE_API_TOKEN: ${{ secrets.NEPTUNE_API_TOKEN }}
        steps:
          - uses: actions/checkout@v2
          - uses: actions/setup-python@v2
            with:
              python-version: 3.8
          - name: Install dependencies
            run: pip install neptune
          - name: Run your Python script
            run: python ../your_script.py
          ...
    

    or if you use a requirements.txt file for your dependencies, add neptune:

    requirements.txt
    ...
    neptune
    
  3. To use Neptune in your Python script:

    # Import Neptune
    import neptune
    
    # Initialize the Neptune objects you need
    run = neptune.init_run(
        api_token=os.getenv("NEPTUNE_API_TOKEN"),  # get from your repo secret
        project="workspace-name/project-name",  # replace with your own
    )
    
    # Define and log metadata
    PARAMS = {
        "batch_size": 64,
        "dropout": 0.2,
        "learning_rate": 0.001,
        "optimizer": "Adam",
    }
    
    run["parameters"] = PARAMS
    
    ...
    

Find example jobs in the neptune-ai/autopmation-pipelines repo:

Code examples  Action examples