Skip to content

A GitHub action to extract metadata from commit messages and issue comments.

License

Notifications You must be signed in to change notification settings

stdlib-js/metadata-action

Repository files navigation

Metadata Action

A GitHub action to extract metadata from commit messages and issue comments.

Example Workflow

# Workflow name:
name: Test GitHub Action

# Workflow triggers:
on:
  push:

# Workflow jobs:
jobs:
  test:
    # Define the type of virtual host machine on which to run the job:
    runs-on: ubuntu-latest

    # Define the sequence of job steps...
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: |
          npm install
      - id: extract-metadata
        uses: stdlib-js/metadata-action@v2
      - name: Log output of the previous step
        run: |
          echo "This is the output of the previous step:"   
          echo ${{ steps.extract-metadata.outputs.metadata }}

Outputs

  • metadata: the array of metadata extracted from the commit messages.

Metadata should be supplied as one or more blocks of YAML code in the commit message enclosed with --- characters at the beginning and end of each block. The metadata blocks from all commit messages in a push are parsed and stored in the output metadata array. For example, given the following commit message:

This commit has a metadata block.

---
type: feature
description: This is a description of the feature.
---

the corresponding metadata array may look like the following:

[
    {
        "type": "feature",
        "description": "This is a description of the feature.",
        "author":{
            "email": "pburckhardt@outlook.com",
            "name": "Planeshifter",
            "username": "Planeshifter"
        },
        "id":"762f39accd4d574db3f1c1480304dddc573840d8",
        "url":"https://github.com/stdlib-js/commit-metadata-action/commit/762f39accd4d574db3f1c1480304dddc573840d8"
    }
]

The description field is special insofar as it will be populated with the commit message when the YAML block does not contain a description field. Hence, the following commit message:

This commit has a metadata block.

---
type: feature
---

may lead to the following metadata array:

[
    {
        "type": "feature",
        "description": "This commit has a metadata block.",
        "author":{
            "email": "pburckhardt@outlook.com",
            "name": "Planeshifter",
            "username": "Planeshifter"
        },
        "id":"762f39accd4d574db3f1c1480304dddc573840d8",
        "url":"https://github.com/stdlib-js/commit-metadata-action/commit/762f39accd4d574db3f1c1480304dddc573840d8"
    }
] 

Otherwise, all the fields in the YAML block are copied verbatim. The fields author, id, and url are special in that they are populated with the information from the commit object and, thus, should not be supplied in the metadata block.

License

See LICENSE.

Copyright

Copyright © 2021-2024. The Stdlib Authors.