GithubHelp home page GithubHelp logo

justincy / github-action-npm-release Goto Github PK

View Code? Open in Web Editor NEW
15.0 3.0 11.0 82 KB

Automatically generate a release when the package.json version changes

License: MIT License

JavaScript 100.00%

github-action-npm-release's Introduction

Automatic GitHub Release

Automatically generate a release when the package.json version changes. The release name and tag will match the new version. If no releases yet exist, this action will create the first release.

The release notes will contain a change log generated from git history in the following format:

- f0d91bd Making progress
- 275e3e2 Initial commit

Assumptions

This action makes a few assumptions:

  • actions/checkout@v2 with fetch-depth: 0 is used before this action runs. That allows this action to have all the information it needs to generate the change log from the git history.
  • You are only releasing from one branch
  • It is only used during push

Usage Example

name: Release
on:
  push:
    branches:
      - master

jobs:
  build:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Release
        uses: justincy/[email protected]
        id: release
      - name: Print release output
        if: ${{ steps.release.outputs.released == 'true' }}
        run: echo Release ID ${{ steps.release.outputs.release_id }}

Works great in tandem with auto-publishing. Here's an example for the GitHub Package Registry:

name: Release
on:
  push:
    branches:
      - master

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Automatic GitHub Release
        uses: justincy/[email protected]
        id: release
      - uses: actions/setup-node@v1
        if: steps.release.outputs.released == 'true'
        with:
          registry-url: 'https://npm.pkg.github.com'
      - name: Publish
        if: steps.release.outputs.released == 'true'
        run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Inputs

  • token: Personal access token for GitHub authentication. Optional. Defaults to ${{ github.token }}.
  • path: Path of the package.json file that will be examined. Optional. Defaults to ${{ github.workspace }}.

Outputs

  • released: Set to true when a release is created.
  • html_url: The URL for viewing the release in a browser.
  • upload_url: The URL for uploading assets to the release.
  • release_id: ID of the release.
  • release_tag: Tag of the release.
  • release_name: Name of the release.

Why re-invent the wheel?

  • Publish to npm
  • Release Me Action
    • I don't want to be forced to use any specific commit format. I want a new version to be the only signal to release.
  • Version Check
    • It only checks commits in a single push. If the workflow run associated with the push that has the new version fails and you push again to fix it, then the second workflow run isn't associated with the commits where the version changed and therefore it doesn't detect that the version changed.
  • I wanted to learn more about GitHub actions.

Possible future enhancements

  • Add options for draft and pre-release
  • Add option for custom git-log format

github-action-npm-release's People

Contributors

justincy avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

github-action-npm-release's Issues

Release missing subsequent commits

This action works really well for what I want, with the slight negative side-effect that Releases lose the # commits to x since this release.

image

I believe this is because target_commitish is not set to the branch, but rightly the commit hash.
I'm unsure if this property is able to accept a combination of branch and commit hash to allow github to maintain a link between the release and target branch.

Do you know if target_commitish is able to accept a value like master#a1b2c3?

Unable to generate the change log

Hello,

I've run into this issue today:

image

The action code is simply

- name: Automatic GitHub Release
  uses: justincy/[email protected]
  id: release

But when I try to run the same command in my terminal, it seems to be working fine

$ git log 8017db07255d151fed69abce14cad59ce1276c41..HEAD --pretty=format:"- %h %s"

- d4ece6c Updated workflow version
- b1b789c Updated action code
...

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.