Skip to content
briefcase

GitHub Action

Get info Cargo.toml file

v1 Latest version

Get info Cargo.toml file

briefcase

Get info Cargo.toml file

Github Action to get info in a Cargo.toml file

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Get info Cargo.toml file

uses: rabbitson87/get-cargo-package-info@v1

Learn more about this action in rabbitson87/get-cargo-package-info

Choose a version

Get info Cargo.toml file

GitHub release GitHub marketplace Licence

About

A GitHub Action to get info in a Cargo.toml file. This is useful for getting project versions when working on docker images. The returned value is available in the github action step.

Usage

In the following example, you can learn how to use it, especially you can put the desired key value in the package value, and you can also enter it in an array. Here is an example of it in use:

name: Get info Cargo.toml file 

on: [ push ]

jobs:

  get-cargo-package-info:
 
    runs-on: ubuntu-latest
 
    steps:
    - name: Get package info
      id: info
      uses: rabbitson87/get-cargo-package-info@v1
      with:
        file_name: Cargo.toml
        directory: <directory_name>
        package: |
          name
          version
          edition

Inputs

In the example above, there are several key/value pairs that will be added to output object's values.

Name Description
package These key values are used to obtain values that match the key value of the environment variable corresponding to [package] from the 'Cargo.toml' file
directory (Optional) This key will set the directory in which you want to get info in Cargo.toml file. Important: cannot start with /. Action will fail if the specified directory doesn't exist.
file_name (Optional) Set the name of the 'Cargo.toml' file. Defaults to Cargo.toml

Output

The output value is output in json form according to the value set in the package. The following example shows the expected json form:

{
  "name": "test_toml",
  "version": "0.1.0",
  "edition": "2021"
}

Input Cargo.toml

[package]
name = "test_toml"
version = "0.1.0"
edition = "2021"

Output usage

name: Get info Cargo.toml file 

on: [ push ]

jobs:

  get-cargo-package-info:
 
    runs-on: ubuntu-latest
 
    steps:
    - name: Get package info
      id: info
      uses: rabbitson87/get-cargo-package-info@v1
      with:
        package: |
          version

    - name: Use output
      shell: bash
      run: echo "version is ${{ fromJson(steps.info.outputs.object).package.version }}"

Potential Issues

Warnings