Coder Social home page Coder Social logo

s0 / libyear-node-action Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 5.0 802 KB

Track NPM dependency freshness, and calculate how pull requests will impact this

License: GNU General Public License v3.0

JavaScript 2.75% TypeScript 97.25%
libyear dependencies github-actions github-action nodejs actions

libyear-node-action's Introduction

Node dependency libyear stats & PR checks

codecov

This GitHub Action will allow you to track how well a repository is keeping up-to-date with NPM dependencies, using libyear.

This action is powered by the NPM package by the same name: libyear.

It can be used in combination with other actions to generate badges (see below).

Usage

Simply include the action s0/libyear-node-action in the appropriate point in your workflow, and pass in the required configuration options:

Note: For best results, it is recommended you install your NPM using your preferred package manager before running this action

**Note: We recommend using the latest release rather than develop to avoid future breaking changes with your workflow.

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    steps:

    # Any prerequisite steps
    - uses: actions/checkout@master
    - run: npm install

    # Calculate libyear
    - uses: s0/libyear-node-action@develop

Configuration

All configuration options are passed in via env, as environment variables. For example:

jobs:
  deploy:
    # ...
    - uses: s0/libyear-node-action@develop
      env:
        FOLDER: some/sub/directory

Full list of variables

Env Variable Description Required?
FOLDER Which directory within your repository should libyear be run in. (Default: root of repository) No

Outputs

This action generates outputs that can be used in later steps or outputs (for example to generate badges to display in your README, see below).

The following outputs are generated. Each of them represents a metric from libyear.

Output Description
drift A floating-point number with 2 decimal places
pulse A floating-point number with 2 decimal places
releases An integer
major An integer
minor An integer
patch An integer

Example: Generating badges using libyear stats

Here's an example workflow that will generate a badge for you and push it to a special branch that can be referenced in e.g. your README. It uses the actions emibcn/badge-action and s0/git-publish-subdir-action in addition to this action.

name: Generate Badges
on:
  # Run on pushes to your main branch
  push:
    branches:
      - develop
  # Run every day
  schedule:
    - cron: "0 0 * * *"

jobs:
  get-badges:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Use Node.js
      uses: actions/setup-node@v1
      with:
        node-version: 10.x

    # Install dependencies and run libyear
    # (notice how the libyear step has an id, this is referenced later)
    - run: npm install
    - id: libyear
      uses: s0/libyear-node-action@develop

    # Generate a badge and store it in the badge/directory
    - run: mkdir badges
    - uses: emibcn/badge-action@v1
      with:
        label: 'libyear'
        # Here is where we use the output from the libyear step
        status: ${{ steps.libyear.outputs.drift }} year(s) behind
        color: 'blue'
        path: 'badges/drift.svg'

    # Upload the directory "badge" as a branch "badge" on the same repo
    - uses: s0/git-publish-subdir-action@develop
      env:
        REPO: self
        BRANCH: badges
        FOLDER: badges
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        SQUASH_HISTORY: true

We use this for this repository, you can see the workflow here: badges.yml

TODO

Please see the issues for details of planned work.

libyear-node-action's People

Contributors

s0 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

libyear-node-action's Issues

Add PR functionality

Add functionality to compare libyear metrics between target and base of a pull request, and leave a comment on the PR with the difference.

Switch to programmatic use once that becomes available in libyear

This is currently listed as a TODO for libyear.

Right now we're running a node subprocess and reading from the stdout. This isn't ideal, in particular we're unable to get both json output, and validation information, so we're unable to take advantage of libyear configuration to specify under what conditions the action should fail etc...

Bug: Action errors when using default configuration

When integrating the github action as per documentation, using Node 14.x, we get an error as below:

TypeError: report.map is not a function
    at Object.getResultsTable (/home/runner/work/_actions/s0/libyear-node-action/v0.1.0/dist/main/index.js:3932:19)
    at /home/runner/work/_actions/s0/libyear-node-action/v0.1.0/dist/main/index.js:4060:41
    at step (/home/runner/work/_actions/s0/libyear-node-action/v0.1.0/dist/main/index.js:4028:23)
    at Object.next (/home/runner/work/_actions/s0/libyear-node-action/v0.1.0/dist/main/index.js:4009:53)
    at fulfilled (/home/runner/work/_actions/s0/libyear-node-action/v0.1.0/dist/main/index.js:4000:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

TypeError: report.map is not a function

We recently migrated a project package manager from npm to yarn. We also update our action workflow as follow :

jobs:
  libyear:
    runs-on: ubuntu-latest
    env:
      YARN_NODE_LINKER: node-modules
    steps:
    - uses: actions/checkout@master
    - name: Use Node.js
      uses: actions/setup-node@v3
      env:
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      with:
        node-version: 16.14.0
        cache: 'yarn'
    - run: yarn install
      env:
        NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

    # Calculate libyear
    - id: libyear
      uses: s0/[email protected]

The following error occurs on the libyear step:

##[debug]Evaluating condition for step: 'Run s0/[email protected]'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Run s0/[email protected]
##[debug]Loading inputs
##[debug]Loading env
Run s0/[email protected]
Result: 
TypeError: Cannot read property 'toFixed' of null
    at /home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:3937:26
    at Array.map (<anonymous>)
    at Object.getResultsTable (/home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:3933:[19](https://github.com/busbud/public-website/actions/runs/3126873968/jobs/5072933976#step:5:19))
    at /home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:4062:41
    at step (/home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:4029:23)
    at Object.next (/home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:4010:53)
    at fulfilled (/home/runner/work/_actions/s0/libyear-node-action/v0.1.2/dist/main/index.js:4001:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

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.