Skip to content

Automatic GitHub Releases of packages built with Vercel pkg using GitHub Actions

Notifications You must be signed in to change notification settings

karlhorky/vercel-pkg-github-actions-release

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Creating GitHub Releases of pkg Executables using GitHub Actions

Introduction

Vercel's pkg allows packaging a Node.js project into an executable, which can run on devices which don't have Node.js installed.

GitHub Actions can run code on a schedule, allowing for automatically building your pkg and releasing to GitHub Releases.

This is a guide to show this. I tried contributing this to the official docs, but unfortunately this was declined by Vercel: vercel/pkg#1246

Guide

GitHub Actions can be used to automatically run pkg when a specific event has occurred.

For example, to automatically run pkg to create executables and upload them as assets to a new release on GitHub every time a new Git tag is pushed, try setting up softprops/action-gh-release as follows:

  1. Add a new file in your project called .github/workflows/release.yml (create the directories .github/workflow in case they don't exist in your project) and add this file content:
name: Build and release
on:
  push:
    tags:
      - 'v*.*.*'
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 'lts/*'
      - run: yarn --frozen-lockfile
      - run: npm install --global pkg
      - name: Build
        run: pkg index.js --output your-program-name-here --targets linux,macos,win
      - name: Release
        uses: softprops/action-gh-release@v1
        with:
          files: |
            your-program-name-here-linux
            your-program-name-here-macos
            your-program-name-here-win.exe
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  1. Create a new Git tag with the version that you want:
git tag -a v1.0.0
  1. Push the new tag to GitHub:
git push --tags

This will create a new release under Releases on your GitHub repo that will contain the built executables as assets:

Releases page on GitHub repo showing release with assets

Every time that you want to create a new release with assets, create a new tag and push it (steps 2 and 3 above).

The final version of the workflow and release:

About

Automatic GitHub Releases of packages built with Vercel pkg using GitHub Actions

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published