Coder Social home page Coder Social logo

build-and-tag-action's Introduction

๐Ÿ“ฆ๐Ÿ”–

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.

build-and-tag-action's People

Contributors

andyfeller avatar dependabot[bot] avatar jasonetco avatar layzeedk avatar mheap avatar nzws avatar shem8 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  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

Watchers

 avatar  avatar  avatar  avatar

build-and-tag-action's Issues

Is there an option to not build and only tag?

Hi I really like how this action takes the v1.x.x tag and then force pushes a v1 tag.

I am creating very simple actions that don't use node. I am using composite to create my action. Is there an option to skip the node build and just tag?

Upgrade to node 20

As node16 has been deprecated, I am getting this warning message when using this action:

Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: JasonEtco/build-and-tag-action@v2. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

Add support to make yarn usable in setup field

/usr/bin/yarn --frozen-lockfile && yarn build
yarn run v1.22.4
error Command "&&" not found.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
##[error]The process '/usr/bin/yarn' failed with exit code 1
โœ–  fatal     Error: The process '/usr/bin/yarn' failed with exit code 1 
    at ExecState._setResult (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v1/dist/index.js:16755:25)
    at ExecState.CheckComplete (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v1/dist/index.js:16738:18)
    at ChildProcess.<anonymous> (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v1/dist/index.js:16632:27)
    at ChildProcess.emit (events.js:210:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)

Add support for `action.yaml`

It would be nice to support also action.yaml instead of just yml, though it is the same file format, and it is just one character less. However, I am pretty sure there are some people out there who prefer yaml to yml, or just type it like that by muscle memory :)

`index.ts` test state leaks across tests

Was trying to add a feature and was writing tests and saw some very weird behaviour on node v20.2.0.

In /tests/index.ts.ts, in the beforeEach, if you add this console.log line at the end of the setup function:

  beforeEach(() => {
    nock.cleanAll()
    tools = generateToolkit()
    delete process.env.INPUT_SETUP
    delete process.env.INPUT_TAG_NAME
    console.log(tools.context.payload)
  })

... you can see that the context.payload state that is modified in certain tests in index.test.ts (like setting draft or prelease) leaks across tests. Here's the output from npm test (see last two logs):

  โ— Console

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: false, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: true, prerelease: false, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

    console.log
      { release: { draft: true, prerelease: true, tag_name: 'v1.0.0' } }

      at Object.<anonymous> (tests/index.test.ts:14:13)

Additional files

I use wordpos in an action. It's currently inpossible to publish that package because it has additional files in dist:

Screenshot 2021-11-12 at 09 55 43

And only dist/index.js is added to the Automatic compilation commit. After looking into the code I think it's not possible to add the whole dist folder with your package. But correct me if I'm working.

Error: Resource not accessible by integration

Run JasonEtco/build-and-tag-action@v2
  with:
  env:
    GITHUB_TOKEN: ***
โ„น  info      Updating tag [v1.0.5]
โ„น  info      Creating tree
Error: Resource not accessible by integration
โœ–  fatal     HttpError: Resource not accessible by integration 
    at /home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:4476:23
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.createCommit [as default] (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:17383:18)
    at async buildAndTagAction (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:17492:20)

Action looks failed to connect to GitHub API.
https://github.com/say8425/bump-test/actions/runs/4595276424/jobs/8115347070#step:5:8

Add support for action.pre, action.post instead of action.main only

I have an action.yml that looks like this

# ...
runs:
  using: 'node20'
  main: 'dist/restore/index.js'
  post: 'dist/save/index.js'
  post-if: 'success()'

As you can see I need both post and main js files to be included in the action for it to work. However with this I am only limited to main,

How can it be fixed?

GitHub Enterprise support

Hi, is this action comptabile with GitHub Enterprise? When I try to use it, I receive the following error:

โ„น  info      Creating tree
Error: Bad credentials

โœ–  fatal     HttpError: Bad credentials 
    at /mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:4476:23
    at processTicksAndRejections (internal/process/task_queues.js:[9](https://code.rbi.tech/raiffeisen/wzhgaho-merlin-gha-helper/runs/307969?check_suite_focus=true#step:5:10)7:5)
    at async Object.createCommit [as default] (/mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:17383:18)
    at async buildAndTagAction (/mnt/data/actions-runner/_work/_actions/internal-marketplace/build-and-tag-action/v2/dist/index.js:17492:20)

My configuration:

name: publish

on:
  release:
    types: [published, edited]

env:
  NODE_EXTRA_CA_CERTS: /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem

jobs:
  publish:
    runs-on: [ self-hosted, build-testtenant ]
    permissions: write-all
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.release.tag_name }}
      - uses: actions/setup-node@v3
        with:
          node-version: 16
      - name: Install deps and build
        run: npm ci && npm run build
      - uses: internal-marketplace/build-and-tag-action@v2
        env:
          DEBUG: '*'
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I'm pretty sure I hand over correctly the token. The issue is somewhere here, with the createTree API.

https://github.com/JasonEtco/build-and-tag-action/blob/main/src/lib/create-commit.ts#L11

Should this action work with GHES 3.6?

Thank you.

Access Issue?

There seems to be an issue with running this action, I gave it the GitHub Token for access and seems to have issues getting the permissions needed.

https://github.com/cloudflare/wrangler-action/actions/runs/5801118421/job/15724694064

Run JasonEtco/build-and-tag-action@v2
โ„น  info      Updating tag [3.0.1]
โ„น  info      Creating tree
Error: Resource not accessible by integration
โœ–  fatal     HttpError: Resource not accessible by integration 
    at /home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:4476:23
    at processTicksAndRejections (node:internal/process/task_queues:96:[5](https://github.com/cloudflare/wrangler-action/actions/runs/5801118421/job/15724694064#step:5:6))
    at async Object.createCommit [as default] (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:1[7](https://github.com/cloudflare/wrangler-action/actions/runs/5801118421/job/15724694064#step:5:8)3[8](https://github.com/cloudflare/wrangler-action/actions/runs/5801118421/job/15724694064#step:5:9)3:18)
    at async buildAndTagAction (/home/runner/work/_actions/JasonEtco/build-and-tag-action/v2/dist/index.js:174[9](https://github.com/cloudflare/wrangler-action/actions/runs/5801118421/job/15724694064#step:5:10)2:20)

Add support for repository that has multiple action.yml

For example, if you have such a structure, this action will fail during validation step but should not fail.

.
โ”œโ”€โ”€ action1
โ”‚ย ย  โ”œโ”€โ”€ action.yml
โ”‚ย ย  โ””โ”€โ”€ index.js
โ”œโ”€โ”€ action2
โ”‚ย ย  โ”œโ”€โ”€ action.yml
โ”‚ย ย  โ””โ”€โ”€ index.js
โ”œโ”€โ”€ action3
โ”‚ย ย  โ”œโ”€โ”€ action.yml
โ”‚ย ย  โ””โ”€โ”€ index.js
โ””โ”€โ”€ action4
ย  ย  โ”œโ”€โ”€ action.yml
ย  ย  โ””โ”€โ”€ index.js

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.