2 minute read

Nyx is perfectly suited for use in CI/CD platforms and leverage automation. This page gives you additional information to set up your build pipelines using common CI/CD platforms effectively and work around some caveats.

GitHub Actions

Using the official Nyx GitHub Action

Please refer to the GitHub Action home page.

Check out the entire repository when running jobs

If you’re running your pipelines on GitHub Actions you probably start your build jobs with the checkout action, which, by default, only checks out the latest commit as the fetch-depth parameter defaults to 1.

This prevents Nyx from inferring information from the commit history and you likely end up with the inferred version to always be the initial version (i.e. 0.1.0) as further illustrated here.

To work around this you just have to configure the checkout action to always fetch the entire commit history by setting the fetch-depth parameter to 0 as documented here:

- uses: actions/checkout@v3
  with:
    fetch-depth: 0

Credentials

When configuring the GitHub service to publish releases you need to pass credentials to Nyx.

When running GitHub Actions pipelines you can take advantage of the automatic token authentication that provides the GITHUB_TOKEN environment variable to GitHub Actions jobs so you don’t need to generate a new OAuth or Personal Access Token for this specific purpose. The same token is also available from within the secrets context.

As an example, to read the token and set it as the GH_TOKEN environment variable you can define your GitHub Actions job like in the following snippets.

Running Nyx using the GitHub Action:

release:
  steps:
    - name: Release
      uses: mooltiverse/nyx-github-action@main
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        command: publish

Running Nyx using the Gradle plugin:

release:
  steps:
    - name: Publish
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: ./gradlew nyxPublish

GitLab CI

When running pipelines on GitLab CI you need to override some defaults to make Nyx work correctly. In particular you need to set the values for the GIT_STRATEGY and GIT_DEPTH variables to clone and 0 respectively, so that the entire repository is checked out, like:

variables:
  GIT_STRATEGY: clone
  GIT_DEPTH: "0"

If you don’t override these variables the local repository will only have a shallow copy, which does not contain the information Nyx requires in order to infer the version. In other words, it’s very likely that the inferred version will always be the initial version (i.e. 0.1.0) as further illustrated here.

Credentials

When configuring the GitLab service to publish releases you need to pass credentials to Nyx.

When running GitLab pipelines and you want Nyx to push Git changes or publish releases on your behalf you need to pass a token with api, read_user, read_api, write_repository and write_registry scope as a variable (say GITLAB_TOKEN) and use this environment variable in Nyx configuration in GitLab configuration.