Skip to content
archive

GitHub Action

Build and Tag

v2.0.1 Latest version

Build and Tag

archive

Build and Tag

Properly tags your GitHub Action

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Build and Tag

uses: JasonEtco/[email protected]

Learn more about this action in JasonEtco/build-and-tag-action

Choose a version

📦🔖

Build and Tag action

GitHub Actions status Codecov


A GitHub Action for publishing JavaScript Actions! It's designed to act on new releases, and updates the tag with a compiled JS file, using @vercel/ncc. The process looks like this:

  • Reads the main property in your package.json
  • Force pushes action.yml and the above file to the release's tag
  • Force pushes to the major version tag (ex: v1.0.0 -> v1)

image

This repository even uses it! @vercel/ncc supports TypeScript out of the box 😍

Usage

name: Publish

on:
  release:
    types: [published, edited]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.release.tag_name }}
      - name: Install deps and build
        run: npm ci && npm run build
      - uses: JasonEtco/build-and-tag-action@v2
        env:
          GITHUB_TOKEN: ${{ github.token }}

You can also use this action with other events - you'll just need to specify a tag_name (see below).

Example package.json for your project

The two important thing you'll need to set in your action are the main field and the build script. Here's an example of a minimal package.json that will use @vercel/ncc to compile your action to dist/index.js, update your action.yml file to use the node16 runtime and point build-and-tag-action at the compiled file:

{
  "name": "your-action-name",
  "main": "dist/index.js",
  "scripts": {
    "build": "npx @vercel/ncc build && npx convert-action"
  }
}

Your package.json will probably contain a dependencies section, in addition to other fields such as license.

Options

tag_name

The tag to update. If the workflow event is release, it will use the tag_name from the event payload. This option can be useful when using this action in a workflow with other actions that generate a release:

- uses: fictional/releaser@v1 # Not a real action!
  id: releaser
- uses: JasonEtco/build-and-tag-action@v2
  with:
    tag_name: ${{ steps.releaser.outputs.tag_name }}

Motivation

The guide to JavaScript Actions recommends including node_modules in your repository, and manual steps to following the versioning recommendations. There are anti-patterns there that just don't sit right with me; so we can enable the same workflow, automatically!

This Action is heavily inspired by mheap/github-action-auto-compile-node & Actions-R-Us/actions-tagger. This is more or less a combination of those two Actions, meant to work together.