Giter Site home page Giter Site logo

action-metadata's Introduction

Action Metadata

Release License

A GitHub Action to expose action metadata of a GitHub Action!

Test Validate Action Readme

Table of Contents

๐Ÿ“– Usage

Use this action as a step in a workflow job and give it an id (action-metadata in the following examples).

- name: action-metadata               # Name of the workflow step
  id: action-metadata                 # Give this step an id to reference it later for outputs
  uses: Shresht7/action-metadata@v1   # Use this action

The action will expose the metadata as an output which you can reference in subsequent steps using an expression ${{ steps.<given_id>.outputs.<output> }}. For a list of all available outputs see Outputs.

- name: some-other-action           
  uses: user/some-other-action@v1     # Not a real user and/or action
  with:
    description: ${{ steps.action-metadata.outputs.description }}
    inputs: ${{ steps.action-metadata.outputs.inputs-md-table }}

The entire metadata object is available as a stringified JSON (i.e. string) as the metadata output. You will need to parse this string to use it as an object using fromJSON in an expression or JSON.parse in your action.

- name: some-other-action
  uses: user/some-other-action@v1     # Not a real user and/or action
  with:
    # Use the fromJSON function in the expression to parse metadata as JSON
    name: ${{ fromJSON(steps.action-metadata.outputs.metadata).author }}

๐Ÿ“‹ Inputs

The action can run on auto-pilot using the default parameters. To change any inputs, pass them along the workflow step.

- name: action-metadata
  id: action-metadata
  uses: Shresht7/action-metadata@v1
  with:
    input-table-alignment: 'c,l,r,l'
Input Description Default Required
input-table-alignment Comma-separated array denoting the alignment of columns ['l' for left, 'c' for center, 'r' for right] l,l,r,c
output-table-alignment Comma-separated array denoting the alignment of columns ['l' for left, 'c' for center, 'r' for right] l,l,r,c

๐Ÿ“‹ Outputs

The action exposes the entire metadata yaml (metadata) as a stringified JSON. To make the most of this output you will need to parse it using fromJSON or JSON.parse functions.

The name, author and description fields, in addition to being available through the parsed metadata, are also exposed on their own.

This action also exposes markdown-tables for the input and output parameters specified in the metadata file. This was the primary motivation for this action.

Output Description
metadata stringified JSON representation of the entire action metadata file
name Name of the GitHub Action
author Name of the action's author
description A short description of the action
inputs-md-table Markdown table of the action inputs
outputs-md-table Markdown table of the action outputs

๐Ÿ“ƒ Workflow Example

The Inputs and Outputs tables you see in this readme were generated using this action in conjunction with markdown-slots. To see the complete workflow, see action-readme.yml.

Action Readme

or click here
# =============
# ACTION README
# =============

name: Action Readme

# Activation Events
# =================

on:
  # When the action.yml or this workflow file changes on the main branch
  push:
    branches:
      - main
    paths:
      - action.yml
      - .github/workflows/action-readme.yml

  # Manual workflow dispatch
  workflow_dispatch:

# Jobs
# ====

jobs:
  update-readme:
    runs-on: ubuntu-latest
    steps:
      # Checkout Repository โœ…
      # ======================

      - name: checkout
        uses: actions/checkout@v3

      # Retrieve Action Metadata ๐Ÿ“œ
      # ===========================

      - name: get action metadata
        id: action-metadata
        uses: Shresht7/action-metadata@v1

      # Read this Workflow File ๐Ÿ“„
      # ==========================

      - name: read workflow file
        id: read-file
        uses: Shresht7/read-file-action@v1
        with:
          path: .github/workflows/action-readme.yml

      # Markdown Slots ๐Ÿ“‹
      # =================

      - name: update readme slots
        id: markdown-slots
        uses: Shresht7/markdown-slots@v1
        with:
          slots: |
            - slot: description
              content: ${{ steps.action-metadata.outputs.description }}
            - slot: inputs
              content: ${{ steps.action-metadata.outputs.inputs-md-table }}
            - slot: outputs
              content: ${{ steps.action-metadata.outputs.outputs-md-table }}
            - slot: action-readme-workflow
              content: ${{ toJSON(steps.read-file.outputs.contents) }}

      # Push Changes ๐ŸŒŽ
      # ===============

      - name: check for changes
        id: git-diff
        run: |
          if git diff --exit-code; then
            echo "::set-output name=changes_exist::false"
          else
            echo "::set-output name=changes_exist::true"
          fi

      - name: commit and push
        if: ${{ steps.git-diff.outputs.changes_exist == 'true' }}
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'
          git add .
          git commit -m 'Update README.md ๐Ÿ“„'
          git push

๐Ÿ“‘ License

MIT License

action-metadata's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar shresht7 avatar

Watchers

 avatar

action-metadata's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.