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

workflow-ts

v0.0.4

Published

Create modular and extendable workflows using TypeScript

Downloads

1

Readme

workflow-ts

Simply typed classes, for modular workflows management and governance.

Quick Start

  1. Run npm install --save-dev workflow-ts
  2. Convert your YAML workflow files into TypeScript files by running npx convert-workflows
  3. Build your workflow YAML files as part of your build process, as described here

Motivation

YAML configurations are an absolute nightmare to maintain.

Seriously, though. Managing logic in key/value structures doesn't make any sense. It forces us to:

🤢 Duplicate logic across repositories 😖 Reinvent the wheel - although actions are (kinda) standardized, jobs and workflows have similar structure. Yet, thry're still rewritten for each repository 😵‍💫 Guess types (is [push] a string or an array?) 🥴 Push code just to test whether the workflow is valid

Using code to define our workflows, we can avoid this turmoil :)

Example

Let's consider we have the following workflow YAML file:

# my-repository/.github/workflows/unit-tests-commit.yml

name: Run unit tests on every commit
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

  test:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm install
      - run: npm run test

In order to reuse this in another project, we need to duplicate the file. But what if we also want to change something?

For example, let's say in the other project the tests should only run on the main and dev branches.

1. Generating the TypeScript workflow file

By running npx convert-workflows we'll generate the following file:

// my-monorepo/first-project/src/workflows/unit-tests-commit.wac.ts

import { Workflow, Job, Step } from 'workflow-ts';

export const workflow = new Workflow('test-workflow', {
  name: 'Run tests',
  on: 'push',
  jobs: [
    new Job('build', {
      runsOn: 'ubuntu-latest',
      steps: [
        new Step({ uses: 'actions/checkout@v4' }),
      ],
    }),
    new Job('test', {
      name: 'Run tests',
      runsOn: 'ubuntu-latest',
      steps: [
        new Step({ uses: 'actions/checkout@v4' }),
        new Step({ run: 'npm install' }),
        new Step({ run: 'npm run test' }),
      ],
    }),
  ],
});

Now we can treat it as any other code we maintain, create a builder function, reuse it, etc.

2. Abstracting the workflow

Let's create a builder function:

// my-monorepo/common/workflowUtils.ts

import { Workflow, Job, Step } from 'workflow-ts';

export function buildWorkflow(
  triggeringBranches?: string[]
): Workflow {
  const onValue = triggeringBranches === undefined
    ? 'push'
    : { push: { branches: triggeringBranches } };

  return new Workflow('test-workflow', {
    name: 'Run tests',
    on: onValue,
    jobs: [
      /// Same as before
    ],
  });
}

3. Reuse workflow in other project

We can call the function to generate our workflow:

// my-monorepo/second-project/src/workflows/unit-tests-commit.wac.ts

import { buildWorkflow } from '../../../common/workflowUtils';

const workflow = buildWorkflow(['main', 'dev']);
export workflow;

4. Generate the YAML files

In order for the workflows to actually run, we only need to have the YAML files before we push the code. This is done by running emmanuelnk/github-actions-workflow-ts' script: npx generate-workflow-files build.