npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

enhance-ga-workflow-yaml

v1.0.0

Published

Expand a yaml file when the source file is staged in git

Downloads

1

Readme

enhance-ga-workflow-yaml

As of today (October 2020), Github Actions workflow yamls don't support reusable yaml features such as anchors and aliases, or anything that would allow to reuse yaml definitions, like for example CircleCI Orbs.

To workaround this issue, you can use this library. The goal is to generate a plain yaml file for github to consume from another yaml file not read by github, where we can use enhanced features for code reuse.

How-to

The best workflow to make this work is this:

  • in your .github folder, create the standard workflows folder, and another folder called enhanced-workflows
  • create your enhanced workflows in the enhanced-workflows folder (see below)
  • install Husky in your project (or configure a git pre-commit hook if you are not using NPM)
  • configure a pre-commit hook to run the enhance-ga-workflow-yaml cli utility for each of your workflow
  • the utility will update the matching workflow in the .github/workflows folder when the matching workflow is staged in git in enhanced-workflows.

Enhanced workflow

You can use standard yaml anchors and aliases in the enhanced workflow, however, there is a catch. Github will validate your workflows and will reject them if they contain sections not supported by github. This prevent us from addition a generic section not part of the github actions syntax to create reusable content, because this content will stay in the generated yaml and will be rejected.

To work around this, this cli utility supports the yaml-import package, so you can include yaml import statements that will be expanded in the target file.

Running it

Just execute, with -s matching the enhanced workflow and -t matching the generated workflow in the .github/workflows folder.

enhance-ga-workflow-yaml -s my-yaml-file.yaml -t my-plain-expanded-yaml-file.yaml -a

Note that the target file is generated only if the source file is currently staged in the git staging area. To see what the CLI is doing, add the -v option to get the verbose output.

Examples

Let's create a snippet that we want to reuse:

#.github/enhanced-workflows/cache-step.yaml
name: Cache NPM dependencies
uses: actions/cache@v1
with:
  path: ~/.npm
  key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
  restore-keys: |
    ${{ runner.OS }}-npm-cache-

and then a enhanced workflow

#.github/enhanced-workflows/test.yaml
name: test
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - !!import/single cache-step.yaml
    - name: Install NPM dependencies
      run: npm install

Using the yaml-import package syntax, we can import the cache-step.yaml file and the generated output will contain the expanded version with everything in a single file:

#.github/workflows/test.yaml
name: test
on: [push]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Cache NPM dependencies
        uses: actions/cache@v1
        with:
          path: ~/.npm
          key: '${{ runner.OS }}-npm-cache-${{ hashFiles(''**/package-lock.json'') }}'
          restore-keys: |
            ${{ runner.OS }}-npm-cache-
      - name: Install NPM dependencies
        run: npm install

To steamline this, you can use Husky to define a pre-commit hook: package.json:

{
  ...
  "scripts": {
    "update-ga-workflows": "enhance-ga-workflow-yaml -s .github/enhanced-workflows/test.yaml -t .github/workflows/test.yaml -a",
  },
  ...
  "husky": {
    "hooks": {
      "pre-commit": "npm run update-ga-workflows"
    }
  }
}