Skip to content
This repository has been archived by the owner on Mar 24, 2020. It is now read-only.

Latest commit

 

History

History
335 lines (257 loc) · 9.18 KB

README.md

File metadata and controls

335 lines (257 loc) · 9.18 KB

publish-me-action

⚠️ This repository is no longer maintained. Use Release Me! Action instead.

Automatically releases new versions with Semantic Release.

Usage

To start using the action, one needs to add a workflow file to a repository. For a quick start, see a simple example:

# .github/workflows/continuous-delivery.yaml

name: Continuous Delivery

on:
  push:
    branches:
      - master

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Fetch all history.
          fetch-depth: 0
          persist-credentials: false
      - name: Release
        uses: ridedott/publish-me-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

For more advanced configuration options and examples, please refer to the sections below.

Environment variables

Environment variables are used to provide secrets to the action. Secrets can be set for a repository in the settings -> secrets page.

  • GITHUB_TOKEN [required string]

    Must be set to a GitHub token with the repo scopes enabled.

    If no branch protection is enabled, a default GitHub Actions token (secrets.GITHUB_TOKEN) can be used. However, if the branch protection is enabled, a Personal Access Token must be used instead with permissions to push to a chosen release branch.

    As an example, this repository uses a Personal Access Token of a user DottBott, which is a GitHub account registered with a purpose of performing automated actions.

  • NPM_TOKEN: [optional string] An authentication token of a chosen npm registry. If undefined, npm publish will be ignored. See the examples section on how to use this action with npm and GitHub Packages.

Inputs

Inputs are used to configure the behavior of the action.

  • BRANCH: [optional string, defaults to 'master']

    A git branch to release to.

  • DEBUG: [optional boolean, defaults to false]

    Outputs debug information for semantic-release plugins.

  • DRY_RUN: [optional boolean, defaults to false]

    Skips prepare, publish and success steps.

  • SCRIPT_PATH: [optional string, defaults to '']

    Executes a script with @semantic-release/exec plugin. Scripts must have read and execute permissions.

Examples

Publish to GitHub Packages

  1. Add a registry configuration to a package.json file:

    {
      "publishConfig": {
        "access": "restricted",
        "registry": "https://npm.pkg.github.com"
      }
    }
  2. Use the following configuration of an action:

    # .github/workflows/continuous-delivery.yaml
    
    name: Continuous Delivery
    
    on:
      push:
        branches:
          - master
    
    jobs:
      release:
        name: Release
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v2
            with:
              # Fetch all history.
              fetch-depth: 0
              persist-credentials: false
          - name: Release
            uses: ridedott/publish-me-action@master
            env:
              # Use an automatically populated `GITHUB_TOKEN` environment
              # variable.
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              # `GITHUB_TOKEN` can also be used to authenticate with GitHub
              # Packages.
              NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Publish to npm

  1. Add a registry configuration to a package.json file:

    {
      "publishConfig": {
        "access": "restricted",
        "registry": "https://registry.npmjs.org"
      }
    }
  2. Use the following configuration of an action:

    # .github/workflows/continuous-delivery.yaml
    
    name: Continuous Delivery
    
    on:
      push:
        branches:
          - master
    
    jobs:
      release:
        name: Release
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v2
            with:
              # Fetch all history.
              fetch-depth: 0
              persist-credentials: false
          - name: Release
            uses: ridedott/publish-me-action@master
            env:
              # Use an automatically populated `GITHUB_TOKEN` environment
              # variable.
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              # See https://docs.npmjs.com/about-authentication-tokens for
              # information on how to acquire a token.
              NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

Publish to GitHub Packages with branch protection enabled

  1. Add a registry configuration to a package.json file:

    {
      "publishConfig": {
        "access": "restricted",
        "registry": "https://npm.pkg.github.com"
      }
    }
  2. Use the following configuration of an action:

    # .github/workflows/continuous-delivery.yaml
    
    name: Continuous Delivery
    
    on:
      push:
        branches:
          - master
    
    jobs:
      release:
        name: Release
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v2
            with:
              # Fetch all history.
              fetch-depth: 0
              persist-credentials: false
          - name: Release
            uses: ridedott/publish-me-action@master
            env:
              # Use a manually populated `GITHUB_TOKEN_WORKAROUND` environment
              # variable with permissions to push to a protected branch. This
              # variable can have an arbitrary name, as an example, this
              # repository uses `GITHUB_TOKEN_DOTTBOTT`. It is recommended
              # to leave the following comment for other developers to be
              # aware of the reasoning behind it:
              #
              # This must be used as GitHub Actions token does not support
              # pushing to protected branches.
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_WORKAROUND }}
              # Regular `GITHUB_TOKEN` can be used to authenticate with GitHub
              # Packages, but a custom `GITHUB_TOKEN_WORKAROUND` can also be used
              # as long as it has `packages:write` permission granted.
              NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See usage notes on how to consume this package in your project.

Prerequisites

Minimal requirements to set up the project:

  • Node.js v12, installation instructions can be found on the official website, a recommended installation option is to use Node Version Manager. It can be installed in a few commands.
  • A package manager npm. All instructions in the documentation will follow the npm syntax.
  • Optionally a Git client.

Installing

Start by cloning the repository:

git clone [email protected]:ridedott/publish-me-action.git

In case you don't have a git client, you can get the latest version directly by using this link and extracting the downloaded archive.

Go the the right directory and install dependencies:

cd publish-me-action
npm install

That's it! You can now go to the next step.

Tests

All tests are being executed using Jest. All tests files live side-to-side with a source code and have a common suffix: .spec.ts.

There are three helper scripts to run tests in the most common scenarios:

npm run test
npm run test:watch
npm run test:coverage

Formatting

This project uses Prettier to automate formatting. All supported files are being reformatted in a pre-commit hook. You can also use one of the two scripts to validate and optionally fix all of the files:

npm run format
npm run format:fix

Linting

This project uses ESLint to enable static analysis. TypeScript files are linted using a custom configuration. You can use one of the following scripts to validate and optionally fix all of the files:

npm run lint
npm run lint:fix

Publishing

Publishing is handled in an automated way and must not be performed manually.

Each commit to the master branch is automatically tagged using semantic-release.

Contributing

See CONTRIBUTING.md.

Automation

Source

Versioning

This project adheres to Semantic Versioning v2.