Skip to content

Package against main #40

Package against main

Package against main #40

name: "Run prebuild's and Create GitHub and NPM release"
run-name: Package against ${{ github.ref_name }}
# Create branch for release
# update package.json for package version
on:
workflow_dispatch:
inputs:
Beta:
description: "Beta Release"
required: true
default: true
type: boolean
env:
oldNodeBuildTargets: -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.1 -t 18.0.0
nodeBuildTargets: -t 19.0.0 -t 20.0.0 -t 21.0.0
oldElectronBuildTargets: -t 5.0.0 -t 6.0.0 -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.2 -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0
electronBuildTargets: -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 24.0.0 -t 25.0.0 -t 26.0.0 -t 27.0.0 -t 28.0.0 -t 29.0.0
winIA32nodeBuildTargets: -t 10.0.0 -t 11.0.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 -t 16.0.0 -t 17.0.1
winIA32electronBuildTargets: -t 20.0.0 -t 21.0.0 -t 22.0.0 -t 23.0.0 -t 24.0.0 -t 25.0.0 -t 26.0.0 -t 27.0.0 -t 28.0.0 -t 29.0.0
ReleasePrebuildCount: 392
ReleasePrebuildifyCount: 84
jobs:
Prepare_prebuild_environment:
name: Prepare prebuild environment ${{ github.ref_name }}
runs-on: ubuntu-latest
steps:
- name: Delete pr-* branches
uses: dawidd6/action-delete-branch@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branches: "release-candidate"
- uses: actions/checkout@v4
- name: Create Branch
uses: peterjgrainger/action-create-branch@v2.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-node@v3
with:
node-version: lts/*
- name: Fetch Adjust version script
if: ${{ inputs.Beta }}
run: wget https://raw.githubusercontent.com/homebridge/.github/latest/.github/npm-version-script.js
working-directory: .github
- if: ${{ inputs.Beta }}
run: npm install semver
- name: Adjust version
if: ${{ inputs.Beta }}
run: node .github/npm-version-script.js ${{ github.ref }} beta
- name: npm version (without git commit)
if: ${{ inputs.Beta }}
run: npm version pre --preid=beta --no-git-tag-version
- name: Allow prebuilds to be stored on github
run: sed -i.bak '/prebuilds/d' .gitignore
- name: Commit & Push changes
uses: actions-js/push@master
with:
author_name: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "release-candidate"
message: "Prepare prebuild environment ${{ github.ref_name }}"
prebuild:
name: ${{ matrix.name }} - Prebuild NPM and GitHub Release artifacts
needs: Prepare_prebuild_environment
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
name:
[
darwin-x64,
darwin-arm64,
linux-arm,
linux-arm64,
linux-arm64-older,
linux-ia32,
linux-ia32-older,
linux-x64,
linux-x64-older,
linuxmusl-arm,
linuxmusl-arm64,
linuxmusl-x64,
win32-ia32,
win32-x64,
]
include:
- name: linuxmusl-x64
os: ubuntu-latest
BASE_IMAGE: library/node:16-alpine
DOCKERFILE: Dockerfile.alpine
QEMU_ARCH: x86_64
CMD: BuildAllCMD
COUNT: 35
NPMCOUNT: 12
- name: linuxmusl-arm
os: ubuntu-latest
BASE_IMAGE: arm32v6/node:16-alpine
DOCKERFILE: Dockerfile.alpine
QEMU_ARCH: arm
CMD: BuildAllCMD
COUNT: 35
NPMCOUNT: 12
- name: linuxmusl-arm64
os: ubuntu-latest
BASE_IMAGE: arm64v8/node:16-alpine
DOCKERFILE: Dockerfile.alpine
QEMU_ARCH: aarch64
CMD: BuildAllCMD
COUNT: 35
NPMCOUNT: 12
- name: linux-arm
os: ubuntu-latest
BASE_IMAGE: balenalib/raspberry-pi-debian:buster
DOCKERFILE: Dockerfile.debian
QEMU_ARCH: arm
CMD: BuildAllCMD
COUNT: 34
NPMCOUNT: 12
# Builds for NodeJS 19+
- name: linux-x64
os: ubuntu-latest
BASE_IMAGE: library/debian:buster-slim
DOCKERFILE: Dockerfile.debian
QEMU_ARCH: x86_64
CMD: BuildNewCMD
COUNT: 11
NPMCOUNT: 3
- name: linux-ia32
os: ubuntu-latest
BASE_IMAGE: i386/debian:buster-slim
DOCKERFILE: Dockerfile.debian
QEMU_ARCH: i386
CMD: BuildNewCMD
COUNT: 11
NPMCOUNT: 3
- name: linux-arm64
os: ubuntu-latest
BASE_IMAGE: arm64v8/debian:buster-slim
DOCKERFILE: Dockerfile.debian
QEMU_ARCH: aarch64
CMD: BuildNewCMD
COUNT: 11
NPMCOUNT: 3
# Builds for NodeJS 18 or lower
- name: linux-x64-older
os: ubuntu-latest
BASE_IMAGE: library/debian:9.6-slim
DOCKERFILE: Dockerfile.oldDebian
QEMU_ARCH: x86_64
CMD: BuildOldCMD
COUNT: 24
NPMCOUNT: 9
- name: linux-ia32-older
os: ubuntu-latest
BASE_IMAGE: i386/debian:9.6-slim
DOCKERFILE: Dockerfile.oldDebian
QEMU_ARCH: i386
CMD: BuildOldCMD
COUNT: 24
NPMCOUNT: 9
- name: linux-arm64-older
os: ubuntu-latest
BASE_IMAGE: arm64v8/debian:9.6-slim
DOCKERFILE: Dockerfile.oldDebian
QEMU_ARCH: aarch64
CMD: BuildOldCMD
COUNT: 24
NPMCOUNT: 9
# Other OS's
- name: darwin-x64
os: macOS-latest
COUNT: 35
NPMCOUNT: 11
- name: darwin-arm64
os: [self-hosted, macOS, ARM64]
COUNT: 35
NPMCOUNT: 11
- name: win32-ia32
os: windows-2019
arch: ia32
COUNT: 31
NPMCOUNT: 0
- name: win32-x64
os: windows-2019
arch: x64
COUNT: 35
NPMCOUNT: 0
steps:
- uses: actions/checkout@v4
with:
ref: "release-candidate"
- uses: actions/setup-node@v3
with:
node-version: 18.x
- name: get-npm-version
if: runner.os == 'Linux'
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1
- name: Linux - Setup Dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get --yes --no-install-recommends install binfmt-support qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static:register --reset
# Hackery to setup builds
- name: Setup Build Commands
if: runner.os == 'Linux'
run: |
echo "BuildOldCMD=\"./.prebuild/build.sh .prebuild/prebuild.js ${oldNodeBuildTargets} && \
./.prebuild/build.sh .prebuild/prebuildify.js ${oldNodeBuildTargets} && \
./.prebuild/build.sh .prebuild/electron.js ${oldElectronBuildTargets}\"" >> $GITHUB_ENV
echo "BuildNewCMD=\"./.prebuild/build.sh .prebuild/prebuild.js ${nodeBuildTargets} && \
./.prebuild/build.sh .prebuild/prebuildify.js ${nodeBuildTargets}&& \
./.prebuild/build.sh .prebuild/electron.js ${electronBuildTargets}\"" >> $GITHUB_ENV
echo "BuildAllCMD=\"./.prebuild/build.sh .prebuild/prebuild.js ${oldNodeBuildTargets} ${nodeBuildTargets} && \
./.prebuild/build.sh .prebuild/prebuildify.js ${oldNodeBuildTargets} ${nodeBuildTargets} && \
./.prebuild/build.sh .prebuild/electron.js ${oldElectronBuildTargets} ${electronBuildTargets}\"" >> $GITHUB_ENV
echo "CMD=${{ matrix.CMD }}" >> $GITHUB_ENV
- name: Linux - Prep Build EXECCMD = ${{ env.CMD }}
if: runner.os == 'Linux'
run: |
echo "${{ env.CMD }}"
echo "EXECCMD=${!CMD}" >> $GITHUB_ENV
# Linux builds
- name: Linux - Build Docker Image ${{ matrix.DOCKERFILE }} - ${{ matrix.BASE_IMAGE }} - ${{ matrix.QEMU_ARCH }}
if: runner.os == 'Linux'
run: |
docker build -f .prebuild/${{ matrix.DOCKERFILE }} --build-arg BASE_IMAGE=${{ matrix.BASE_IMAGE }} --build-arg QEMU_ARCH=${{ matrix.QEMU_ARCH }} -t multiarch-build .
- name: Linux - Prebuild Binaries - ${{ env.EXECCMD }}
if: runner.os == 'Linux'
run: |
docker run --rm -v $(pwd):/node-pty multiarch-build sh -c ${{ env.EXECCMD }}
# Mac OS
- name: macOS - Prebuild Binaries
if: runner.os == 'macOS'
run: |
python3 -m pip install packaging setuptools
npm ci --ignore-scripts
env JOBS=max node .prebuild/prebuild.js ${oldNodeBuildTargets} ${nodeBuildTargets}
env JOBS=max node .prebuild/electron.js ${oldElectronBuildTargets} ${electronBuildTargets}
# buildify doesn't work on Mac due to missing spawn_helper
# env JOBS=max node .prebuild/buildify.js
# Windows
- name: Windows ia32 - Prebuild Binaries
if: ${{ (runner.os == 'Windows') && (matrix.arch == 'ia32') }}
shell: bash
run: |
npm ci --ignore-scripts
env JOBS=max node_modules/.bin/prebuild ${winIA32nodeBuildTargets} --include-regex "\.(node|exe|dll|pdb)" --arch ${{ matrix.arch }}
env JOBS=max node_modules/.bin/prebuild ${oldElectronBuildTargets} ${winIA32electronBuildTargets} --include-regex "\.(node|exe|dll|pdb)" -r electron -a ${{ matrix.arch }}
- name: Windows x64 - Prebuild Binaries
if: ${{ (runner.os == 'Windows') && (matrix.arch == 'x64') }}
shell: bash
run: |
npm ci --ignore-scripts
env JOBS=max node_modules/.bin/prebuild ${oldNodeBuildTargets} ${nodeBuildTargets} --include-regex "\.(node|exe|dll|pdb)" --arch ${{ matrix.arch }}
env JOBS=max node_modules/.bin/prebuild ${oldElectronBuildTargets} ${electronBuildTargets} --include-regex "\.(node|exe|dll|pdb)" -r electron --arch ${{ matrix.arch }}
# Start of Checks
- name: Check Release prebuilds exist
shell: bash
run: |
fileCount=$(ls prebuilds/*/node-pty*tar.gz | wc -l)
echo "Release Prebuild count ${fileCount}"
if [ "$fileCount" -ne ${{ matrix.COUNT }} ]; then echo "::warning::Release Prebuild count ${fileCount}, expected ${{ matrix.COUNT }}"; else echo "::notice::Release Prebuild count ${fileCount}, expected ${{ matrix.COUNT }}"; fi
- name: "Check file existence"
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "prebuilds/*/node*node"
- name: Check NPM prebuilds exist
if: steps.check_files.outputs.files_exists == 'true'
shell: bash
run: |
fileCount=$(ls prebuilds/*/node*node | wc -l)
echo "NPM Prebuild count ${fileCount}"
if [ "$fileCount" -ne ${{ matrix.NPMCOUNT }} ]; then echo "::warning::Release NPM Prebuild count ${fileCount}, expected ${{ matrix.NPMCOUNT }}"; else echo "::notice::Release NPM Prebuild count ${fileCount}, expected ${{ matrix.NPMCOUNT }}"; fi
- if: runner.os == 'Linux'
run: sudo chown -R $USER:$USER .
- name: Commit & Push changes
uses: actions-js/push@be2c6e7c16dba301499992e84b3b32aaaa56507c
with:
author_name: ${{ github.actor }}
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "release-candidate"
message: "Prebuilds for ${{ steps.package-version.outputs.current-version}} - ${{ matrix.name }}"
pull: true
publish:
name: Publish GitHub and NPM Release
needs: prebuild
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: "release-candidate"
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: lts/*
registry-url: "https://registry.npmjs.org"
cache: "npm"
- name: NPM build
run: |
npm ci --ignore-scripts
npm run build
- name: Check Release prebuilds exist
shell: bash
run: |
fileCount=$(ls prebuilds/*/node-pty*tar.gz | wc -l)
echo "Release Prebuild count ${fileCount}"
if [ "$fileCount" -ne ${ReleasePrebuildCount} ]; then echo "::error::Release Prebuild count ${fileCount}, expected ${ReleasePrebuildCount}"; exit 1; else echo "::notice::Release Prebuild count ${fileCount}, expected ${ReleasePrebuildCount}"; fi
- name: Check Release prebuildify`s exist
shell: bash
run: |
fileCount=$(ls prebuilds/*/node*node | wc -l)
echo "Release Prebuild count ${fileCount}"
if [ "$fileCount" -ne ${ReleasePrebuildifyCount} ]; then echo "::error::Release Prebuildify count ${fileCount}, expected ${ReleasePrebuildifyCount}"; exit 1; else echo "::notice::Release Prebuildify count ${fileCount}, expected ${ReleasePrebuildifyCount}"; fi
- name: get-npm-version
id: package-version
uses: martinbeentjes/npm-get-version-action@v1.3.1
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.package-version.outputs.current-version}}
release_name: Release v${{ steps.package-version.outputs.current-version}}
body: |
Changes in this Release
- First Change
- Second Change
draft: false
prerelease: true
- uses: AButler/upload-release-assets@v2.0
name: Upload Prebuild Artifacts to ${{ steps.package-version.outputs.current-version}}
with:
files: "prebuilds/*/node-pty*tar.gz"
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-tag: v${{ steps.package-version.outputs.current-version}}
- name: NPM Pack Release
run: |
npm pack
- uses: AButler/upload-release-assets@v2.0
name: Upload NPM Release to ${{ steps.package-version.outputs.current-version}}
with:
files: "*node-pty-prebuilt-multiarch*.tgz"
repo-token: ${{ secrets.GITHUB_TOKEN }}
release-tag: v${{ steps.package-version.outputs.current-version}}
- name: "Check file existence"
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "prebuilds/*/node-pty-prebuilt-multiarch-*-node-*-darwin-arm64.tar.gz"
- name: Check MacOS ARM prebuilds exist
if: steps.check_files.outputs.files_exists == 'false'
run: |
echo "Missing MacOS ARM prebuilds, please remove release Artifats, and reun"
exit 1
- name: npm publish beta
if: ${{ github.repository == 'homebridge/node-pty-prebuilt-multiarch' && inputs.Beta }}
run: npm publish --access public --tag=beta
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: npm publish production
if: ${{ github.repository == 'homebridge/node-pty-prebuilt-multiarch' && ! inputs.Beta }}
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}