|
| 1 | +--- |
| 2 | +title: Using the Dependency submission API |
| 3 | +intro: 'You can use the Dependency submission API to submit dependencies for projects, such as the dependencies resolved when a project is built or compiled.' |
| 4 | +shortTitle: Dependency submission API |
| 5 | +topics: |
| 6 | + - API |
| 7 | + - Dependency graph |
| 8 | + - Dependencies |
| 9 | + - REST |
| 10 | +versions: |
| 11 | + feature: dependency-submission-api |
| 12 | +--- |
| 13 | + |
| 14 | +{% data reusables.dependency-submission.dependency-submission-api-beta %} |
| 15 | + |
| 16 | +## About the Dependency submission API |
| 17 | + |
| 18 | +{% data reusables.dependency-submission.about-dependency-submission %} |
| 19 | + |
| 20 | +Dependencies are submitted to the dependency submission API in the form of a snapshot. A snapshot is a set of dependencies associated with a commit SHA and other metadata, that reflects the current state of your repository for a commit. For more information about the Dependency submission API, see the [Dependency submission REST API documentation](/rest/dependency-graph/dependency-submission). |
| 21 | + |
| 22 | +## Submitting dependencies at build-time |
| 23 | + |
| 24 | +You can use the Dependency submission API in a {% data variables.product.prodname_actions %} workflow to submit dependencies for your project when your project is built. |
| 25 | + |
| 26 | +### Using pre-made actions |
| 27 | + |
| 28 | +The simplest way to use the Dependency submission API is by adding a pre-made action to your repository that will gather and convert the list of dependencies to the required snapshot format and submit the list to the API. Actions that complete these steps for various ecosystems are available on {% data variables.product.prodname_marketplace %} and more actions will be created during the course of the beta and beyond. You can find links to the currently available actions in the table below: |
| 29 | + |
| 30 | +Ecosystem | Action | |
| 31 | +--- | --- | |
| 32 | +Go | [Go Dependency Submission](https://github.com/actions/go-dependency-submission) |
| 33 | + |
| 34 | +For example, the following [Go Dependency Submission](https://github.com/actions/go-dependency-submission) workflow calculates the dependencies for a Go build-target (a Go file with a `main` function) and submits the list to the Dependency Submission API. |
| 35 | + |
| 36 | +```yaml |
| 37 | + |
| 38 | +name: Go Dependency Submission |
| 39 | +on: |
| 40 | + push: |
| 41 | + branches: |
| 42 | + - main |
| 43 | + |
| 44 | +# The API requires write permission on the repository to submit dependencies |
| 45 | +permissions: |
| 46 | + contents: write |
| 47 | + |
| 48 | +# Envionment variables to configure Go and Go modules. Customize as necessary |
| 49 | +env: |
| 50 | + GOPROXY: '' # A Go Proxy server to be used |
| 51 | + GOPRIVATE: '' # A list of modules are considered private and not requested from GOPROXY |
| 52 | +jobs: |
| 53 | + go-action-detection: |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: 'Checkout Repository' |
| 57 | + uses: {% data reusables.actions.action-checkout %} |
| 58 | + |
| 59 | + - uses: {% data reusables.actions.action-setup-go %} |
| 60 | + with: |
| 61 | + go-version: ">=1.18.0" |
| 62 | + |
| 63 | + - name: Run snapshot action |
| 64 | + uses: @actions/go-dependency-submission@v1 |
| 65 | + with: |
| 66 | + # Required: Define the repo path to the go.mod file used by the |
| 67 | + # build target |
| 68 | + go-mod-path: go-example/go.mod |
| 69 | + # |
| 70 | + # Optional. Define the repo path of a build target, |
| 71 | + # a file with a `main()` function. |
| 72 | + # If undefined, this action will collect all dependencies |
| 73 | + # used by all build targets for the module. This may |
| 74 | + # include Go dependencies used by tests and tooling. |
| 75 | + go-build-target: go-example/cmd/octocat.go |
| 76 | + |
| 77 | +``` |
| 78 | +### Creating your own action |
| 79 | + |
| 80 | +Alternatively, you can write your own action to submit dependencies for your project at build-time. Your workflow should: |
| 81 | + |
| 82 | + 1. Generate a list of dependencies for your project. |
| 83 | + 2. Translate the list of dependencies into the snapshot format accepted by the Dependency submission API. For more information about the format, see the body parameters for the "Create a repository snapshot" API operation in the [Dependency submission REST API documentation](/rest/dependency-graph/dependency-submission). |
| 84 | + 3. Submit the formatted list of dependencies to the Dependency submission API. |
| 85 | + |
| 86 | +{% data variables.product.product_name %} maintains the [Dependency Submission Toolkit](https://github.com/github/dependency-submission-toolkit), a TypeScript library to help you build your own GitHub Action for submitting dependencies to the Dependency submission API. For more information about writing an action, see "[Creating actions](/actions/creating-actions)". |
0 commit comments