Skip to content

Using 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 top-right corner of the Neptune app, click your avatar 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-client
          - name: Run your Python script
            run: python ../your_script.py
          ...
    

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

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

    # Import Neptune
    import neptune.new as 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