Git Product home page Git Product logo

licensed-ci's Introduction

licensed-ci

test

A GitHub Action to run github/licensed in a CI workflow.

  1. Run a workflow to update cached dependency metadata using licensed cache and push updates to GitHub
  2. Run licensed status to check that license data is available, known, up to date and valid for all dependencies
    • Status check failures will cause the step to fail, allowing examination and further updates to the code (if needed).

Available Workflows

Push (push)

This is the default workflow and the behavior in v1.1.0.

Update cached dependency metadata on the target branch and push changes to origin. If pr_comment input is set and a pull request is available, a comment is added to the pull request. This input is deprecated and will be removed in the next major version.

Branch (branch)

Update cached dependency metadata on a branch named <branch>-licenses and opens a pull request to merge the changes into the target branch. If pr_comment input is set, it will be added to the body text when creating the pull request. This input is deprecated and will be removed in the next major version.

Manual adjustments to license data or the github/licensed configuration should happen on the new licenses branch. Any runs of the action on a *-licenses branch will run status checks only - dependency metadata will not be updated.

Notes:

  • If the licenses branch already exists, it is rebased onto the target branch before caching metadata.
  • If an open pull request for the branch already exists, no further action is taken.

Push for changes from bots, Branch for changes from users (push_for_bots)

This is a hybrid workflow, choosing either the branch or push workflow depending on the context that triggered licensed-ci. The intended result is that dependency changes made by bots will run the push workflow, while dependency changes initiated by humans will run the branch workflow. Choosing the push workflow for changes made by bots requires less human interaction overall in reviewing and merging multiple pull requests.

The workflow that is run is chosen based on a few different checks:

  1. If the branch workflow has already created a *-licenses branch, continue to use the branch workflow
  2. If the action payload's sender field is for a user account, use the branch workflow
  3. If the above checks don't pass, use the push workflow

Configuration

  • github_token - Required. The access token used to push changes to the branch on GitHub.
  • command - Optional, default: licensed. The command used to call licensed.
  • config_file - Optional, default: .licensed.yml. The configuration file path within the workspace.
  • user_name - Optional, default: licensed-ci. The name used when committing cached file changes.
  • user_email - Optional, default: [email protected]. The email address used when committing cached file changes.
  • commit_message - Optional, default: Auto-update license files. Message to use when committing cached file changes.
  • pr_comment - Optional (deprecated). Markdown content to add to an available pull request.
    • this option is deprecated. Please use the available pr_url and pr_number to script additional actions in your workflow
  • workflow - Optional, default: push. Specifies the workflow that is run when metadata updates are found:
    1. push
    2. branch
    3. push_for_bots
  • cleanup_on_success - Optional, default: 'false'. Only applies to the branch workflow. Set to the string 'true' to close PRs and delete branches used by the branch workflow when licensed status succeeds on the parent branch.
  • dependabot_skip - Optional, default: 'false'. Set to the string 'true' to prepend [dependabot skip] to commit messages when licensed-ci is run on a Pull Request or commit authored by Dependabot. This will signal to Dependabot that it is safe to perform its normal operations even though non-Dependabot commits are present on the Dependabot Pull Request.
  • sources - Optional. Set to a string containing a comma-separated list of github/licensed sources to add --sources CLI arguments to cache and status commands.
  • format - Optional. Available values: [yaml, json]. Set to add a --format CLI argument to cache and status commands.

Outputs

  • licenses_branch - The branch containing licensed-ci changes.
  • user_branch - The branch containing user changes.
  • licenses_updated - A boolean string indicating whether license files were updated.
  • pr_url - The html url of the pull request for the license updates branch, if available, to enable further actions scripting.
  • pr_number - The number of the pull request for the license updates branch, if available, to enable further actions scripting.
  • pr_created - True if a pull request was created in a branch workflow, false otherwise.

Usage

See a full example below.

Supported Events

This action supports the push, pull_request, workflow_dispatch, and scheduled events. When using push, the action workflow should include tags-ignore: '**' to avoid running the action on pushed tags. New tags point to code but do not represent new or changed code that could include updated dependencies.

on:
  # run on pushes to the default branch
  push:
    branches:
      - main
    tags-ignore: '**'
  # run on pull request events with changes to code
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
  # run on demand
  workflow_dispatch:
  # run on a schedule against the repository's default branch
  schedule:
    - cron: '0 8 * * *' # run every day at 8am

Basic Ruby usage using Bundler + Gemfile

jobs:
  licensed:
    env: # optionally configure the Gemfile used
      BUNDLE_GEMFILE: ${{ github.workspace }}/licensed.gemfile
    steps:
      - uses: actions/checkout@v3
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.1
          bundler-cache: true # improve performance on subsequent runs
          cache-version: 1
      - run: xxx # Install project dependencies here.
      - uses: github/licensed-ci@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          command: "bundle exec licensed" # or bin/licensed when using binstubs

Basic non-Ruby usage using github/setup-licensed

jobs:
  licensed:
    steps:
      - uses: actions/checkout@v3
      
      # install licensed.  licensed v4 can only be installed as a gem and requires
      # running ruby/setup-ruby before github/setup-licensed.  If a project doesn't
      # require a specific version of ruby, default to installing latest stable
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ruby
      - uses: github/setup-licensed@v1
        with:
          version: 4.x

      - run: xxx # Install project dependencies here.
      - uses: github/licensed-ci@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}

Using outputs to make a PR comment

jobs:
  licensed:
    steps:
      - # environment setup ...
      - id: licensed # save the id of the step to reference later
        uses: github/licensed-ci@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/[email protected]
        if: always() && steps.licensed.outputs.pr_number
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              ...context.repo,
              issue_number: ${{ steps.licensed.outputs.pr_number }}
              body: 'My custom PR message'
            })

Authentication

Accessing private repositories during the licensed-ci action

The default GITHUB_TOKEN authentication token provided by GitHub Actions does not have read access to any other GitHub repositories. If running github/licensed in your repo requires access to a private GitHub repository, please set the github_token workflow input to a PAT from a user with access to necessary private repositories.

Using licensed-ci with permission restrictions on GITHUB_TOKEN

If your action workflow restricts which permissions are granted to GITHUB_TOKEN, please ensure that both contents and pull-requests are set to write. As part of an Actions workflow, licensed-ci can push license metadata file updates to a repo, comment on existing PRs, and open new PRs.

permissions:
  pull-requests: write
  contents: write

Full Node.js example

on:
  # run on pushes to the default branch
  push:
    branches:
      - main
  # run on pull request events with changes to code
  pull_request:
    types:
      - opened
      - reopened
      - synchronize
  # run on demand
  workflow_dispatch:

# ensure that the action can push changes to the repo and edit PRs
# when using `secrets.GITHUB_TOKEN`
permissions:
  pull-requests: write
  contents: write

jobs:
  licensed:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      # install environment pre-requisites and project dependencies
      - uses: actions/setup-node@v3
        with:
          node-version: 16
          cache: npm # cache dependencies for faster subsequent runs.
      - run: npm install --production --ignore-scripts

      # install licensed.  licensed v4 can only be installed as a gem and requires
      # running ruby/setup-ruby before github/setup-licensed.  If a project doesn't
      # require a specific version of ruby, default to installing latest stable
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: ruby
      - uses: github/setup-licensed@v1
        with:
          version: 4.x

      - id: licensed
        uses: github/licensed-ci@v1
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
      - uses: actions/[email protected]
        if: always() && steps.licensed.outputs.pr_number
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            github.issues.createComment({
              ...context.repo,
              issue_number: ${{ steps.licensed.outputs.pr_number }}
              body: 'My custom PR message'
            })

License

This project is released under the MIT License

Maintainers

  • @ajhenry
  • @lumaxis

Support

You can expect the following support. See SUPPORT for more information.

Contributions

Contributions are welcome! See CONTRIBUTING.md for more information on how to get involved.

Acknowledgement

Huge thank you and appreciation to @jonabc for championing license compliance and maintaining licensed over the years.

licensed-ci's People

Contributors

brend-smits avatar dependabot[bot] avatar elrayle avatar ipc103 avatar jeffwidman avatar jonabc avatar lumaxis avatar manuelpuyol avatar mmorel-35 avatar villelahdenvuo avatar zkoppert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

licensed-ci's Issues

Better handle `refs/tags/*` refs

Currently if the action is run on pushing tags the action will fail with a message like refs/tags/... doesn't reference a branch.

In general I think not running the action on tags is the right thing to do because tags are pointers to code but don't represent new code that should be evaluated, but this could be better handled by skipping the remainder of the action in some way without raising a failure.

How do I actually run this tool?

Hi, im trying to set up a gtihub action, and using your tool for scanning.

I have this yml file:


name: "Update and check dependency data"


on:
  push:
    branches: [main]


jobs:
  licensed:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: jonabc/licensed-ci@v1
      - uses: jonabc/setup-licensed@v1
        with:
         version: 2.x
      - run: licensed list

Where I would like to run "licensed status" on my project.
But of course this does not work, and the command "licensed" cannot be found.

How do I get to use the commands from your library?
I dont really understand the examples on your marketplace page, none of them seem to be actually using the comands, they just run a few scripts and so on

Is it possible to have the actions done as a bot?

Hey! Thanks for creating this action.

I was wondering if it's possible to have the actions (like the commits, branch and comments creation) done as non user? Is there a different token I could use for this?I'm currently using a PAT. I'm trying not to get pinged each time a branch/issue is created ๐Ÿ˜„

A bit more context, i'm currently using a different token like here https://github.com/github/licensed/blob/31b44067a069b7601060af337d7c27571486728f/.github/workflows/licensed.yml#L53.

Dealing with PRs created after licensed has created a fixup PR

This came up recently:

  1. A colleague pushed a branch (call it B)
  2. The licensed-ci action ran and created a PR to update the license cache
  3. The colleague created a PR based on branch B
  4. The colleague noticed that CI was failing on their PR due to the license cache problem, but didn't notice that there was already an automatically-created PR fixing the problem. As a result, they didn't know how to proceed.

As I understand it, if (3) had happened before (2), then the action would have created a comment on the PR explaining what to do. But since (2) happened before (3), there was no PR to add such a comment to, so there was no obvious breadcrumb in the PR pointing at the solution.

One idea for improving this situation would be also to run the Action when PRs are created, and if there are any license-fixup branches pending against the new PR's head branch, to add the informative comment to the PR then.

/cc @jonabc, who asked me to create this issue.

Cheers!

V1.5.5 broke our flow

Hi, since the release of V1.5.5 we've been seeing the following errors whenever the action tries to create a new branch for licenses:

/usr/bin/git fetch licensed-ci-origin enh/fix-sidekiq-sessions-licenses
fatal: could not read Password for 'https://***@github.com': No such device or address
/usr/bin/git fetch licensed-ci-origin enh/fix-sidekiq-sessions
fatal: could not read Password for 'https://***@github.com': No such device or address
/usr/bin/git checkout --track licensed-ci-origin/enh/fix-sidekiq-sessions-licenses
fatal: 'licensed-ci-origin/enh/fix-sidekiq-sessions-licenses' is not a commit and a branch 'enh/fix-sidekiq-sessions-licenses' cannot be created from it
/usr/bin/git checkout --track licensed-ci-origin/enh/fix-sidekiq-sessions
fatal: 'licensed-ci-origin/enh/fix-sidekiq-sessions' is not a commit and a branch 'enh/fix-sidekiq-sessions' cannot be created from it

Can you please advise on what we need to do to fix this? or better yet roll forward a non breaking fix for the patch version release?

Thanks!

Installation Error

We're seeing an ERROR while installing a gem from the looks of it. This happens for both 2.x and 3.x.

Run jonabc/setup-licensed@v1
  with:
    version: 3.x
    install-dir: /usr/local/bin
attempting to install licensed gem matching "3.x"
/usr/bin/gem list licensed --exact --remote --all --quiet
licensed (3.0.0, 2.15.2, 2.15.1, 2.15.0, 2.14.4, 2.14.3, 2.14.2, 2.14.1, 2.14.0, 2.13.0, 2.12.2, 2.12.1, 2.12.0, 2.11.1, 2.11.0, 2.10.0, 2.9.2, 2.9.1, 2.9.0, 2.8.0, 2.7.0, 2.6.2, 2.6.1, 2.6.0, 2.5.0, 2.4.0, 2.3.2, 2.3.1, 2.3.0, 2.2.0, 2.1.0, 2.0.1, 2.0.0, 1.5.2, 1.5.1, 1.4.0, 1.3.4, 1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.0, 1.1.0, 1.0.1, 1.0.0, 0.11.1, 0.11.0, 0.10.0, 0.6.0)
/usr/bin/gem install licensed -v 3.0.0
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.7.0 directory.
gem installation was not successful
attempting to install licensed executable matching "3.x"
sudo /usr/bin/tar xzv -f /tmp/JAeIhF/licensed.tar.gz -C /usr/local/bin ./licensed
./licensed
licensed (3.0.0) executable installed

Happy to help provide more debugging information if needed.

Handle rate limiting responses when querying the GitHub API

Licensed-ci makes a few API calls during it's execution to find and post on issues and PRs. It's possible for GitHub's API to respond with a rate limiting error, in which case the best thing for this action to do is to implement a backoff and/or retry strategy. From the documentation, it looks like the API will return a 403 error for rate limits.

There are two types of rate limits

  1. primary - this is the basic X requests per hour type of limit, and the response will include headers giving the time that the limits will be reset. A retry strategy waiting until the reset time should work, though it would make sense to still throw an error if the user would have to wait more than a minute of two. In that case the error message should be very clear with something like This action is rate limited until <time>, please rerun the action after that time.

  2. secondary - this is burst detection, X requests per second or similar. I think licensed could only detect this based on the error message, but I'll take a look and see what information is available when this rate limit is triggered. A retry strategy using some randomness to wait X number of seconds should mean help spread out requests and avoid sending consistent request bursts.

cc @hendrikvanantwerpen

Move off of actions mocks

I think we can get the same benefit in tests that actions mocks provides by using a normal mock/stub framework like sinon. The reason is that I'm not likely to work on my actions mocking framework too much and so that is likely to go stale if it's not already.

set-output deprecation warning when running the action

Hey there!

I'm noticing a log annotation when running the action:

Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

I checked out the linked blog article and from what I can tell in the code, the set-output code path is never used, and core.setOutput() is used instead. The blog notes that the @actions/core version should be v1.10 or greater so you should be functionally using the new (non-deprecated) setOutput() function.

My best guess at fixing this warning is to remove dist/index.js#L964-L975 and check if the warning is resolved.

Does that sound reasonable? If so, I can open up a PR.

Got Validation Failed error while running the pipeline (Bundler + Gemfile approach)

Got an error while running the pipeline using bundler + Gemfile approach.

/usr/bin/git remote add licensed-ci-origin ***github.com/my-private-repository/project-name

::set-output name=licenses_branch::licensed-ci-actions-licenses
##[debug]='licensed-ci-actions-licenses'

::set-output name=user_branch::licensed-ci-actions
##[debug]='licensed-ci-actions'
Error: Validation Failed: {"message":"The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.","resource":"Search","field":"q","code":"invalid"}
##[debug]Node Action run completed with exit code 1
##[debug]Finishing: Run jonabc/[email protected]

I did a quick googling and it seems the error is related to Github Octokit, although I'm not really sure because I don't really know how to correctly read this log and pinpoint which passage that produced this error. One thing to note is that one of the gems that needs to be installed is a proprietary gem that is stored on github packages.

I'll be happy to include additional debugging info if necessary, thanks!

Error running `git add` on an empty directory

I experienced a problem today with the latest release. I have a Go repo that has several directories cmd/X, cmd/Y, etc. that build different executables. I recently added a new such directory, for a new command (call it Z) that doesn't have any external dependencies. When I pushed that branch, I got an error like the following:

git add -- /home/runner/work/my/repo/.licenses/. /home/runner/work/my/repo/.licenses/X /home/runner/work/my/repo/.licenses/Y /home/runner/work/my/repo/.licenses/Z
fatal: pathspec '/home/runner/work/my/repo/.licenses/Z' did not match any files
Error: The process 'git' failed with exit code 128

This failure caused the action to fail without creating a PR to add the required license information.

ISTM that licensed-ci should do something like check which directories have contents and only pass those to git add, or alternatively perhaps run git add -- /home/runnier/work/my/repo/.licenses to add all existing directories at once. Note that git add --ignore-missing unfortunately cannot be used to get around the problem, since that option is only allowed when --dry-run is also specified.

I was able to work around the problem by creating the missing directories by adding empty .gitignore files to them, but obviously it would be nice if this weren't necessary.

Error: "does not reference a branch" when running Licensed CI

Hi @jonabc, thanks for all your hard work with licensed-ci!

I tried setting it up in a repository but got this error:

Error: refs/pull/16/merge does not reference a branch

This is the PR: pabio/template#16

Full workflow run: https://github.com/koj-co/template/pull/16/checks?check_run_id=1159826832.

These are the relevant logs:

Run jonabc/licensed-ci@v1
  with:
    config_file: .github/.licensed.yml
    github_token: ***
    user_name: Koj Bot
    user_email: [email protected]
    commit_message: :page_facing_up: Update dependency license file
    command: licensed
    workflow: push
    cleanup_on_success: false
git config user.name Koj Bot
git config user.email [email protected]
git remote add licensed-ci-origin ***github.com/koj-co/template.git
Error: refs/pull/16/merge does not reference a branch

Is it possible to have the action push signed commits?

Hello, thanks for creating this action!

I recently had the Require signed commits setting enabled for a repo as a security measure. However, this setting now prevents me from merging Pull Requests including any of licensed-ci's Auto-update license files commits.

I was wondering if it's possible to have signed commits when licensed-ci pushes its Auto-update license files commit via push/push_for_bots to help with this. It sadly does not seem possible when looking at the current push script :
https://github.com/github/licensed-ci/blob/6238e9d3b8f908d8cf5da450950d40ace4faf597/lib/workflows/push.js#L51C1-L65

Bump to Ruby 3.1?

I noticed the Readme and other places reference Ruby 2.6... what's holding back the upgrade to 3.1? Esp since these are actions workflows, IIUC they are isolated and don't require the target application source code to be upgraded...

Question: Run on pull request

Is it possible to run tis GitHub Action on pull requests to fail the build if the PR adds a new package with a license that is not acceptable?

On pull request I'm getting Error: refs/pull/14/merge does not reference a branch. Looks like it was meant to have been fixed according to https://github.com/jonabc/licensed-ci/issues/44#issuecomment-699157465, but might not be?

I used the trigger configuration like so:

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

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.