Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
achou11 authored Oct 11, 2023
0 parents commit 74a9e6f
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/prebuilds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Generate prebuilds

on:
push:
branches: [main]
tags:
- "*"

env:
NODE_VERSION: 16
MODULE_NAME: "" # UPDATE THIS
MODULE_VERSION: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || 'latest' }}

jobs:
build:
runs-on: ubuntu-20.04
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
target: ["android-arm", "android-arm64", "android-x64"]

steps:
- name: Assert env.MODULE_NAME is set
if: ${{ env.MODULE_NAME == '' }}
run: echo "env.MODULE_NAME must be set" && exit 1

- uses: actions/checkout@v4

- name: Setup NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r24 # https://github.com/android/ndk/wiki/Unsupported-Downloads#r24
add-to-path: false

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Download npm package and unpack
run: npm pack ${{ env.MODULE_NAME }}@${{ env.MODULE_VERSION }} | xargs tar -zxvf

- name: Install deps for package
working-directory: ./package
run: npm install

- name: Generate prebuild for ${{ matrix.target }}
working-directory: ./package
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: npx --yes [email protected] ${{ matrix.target }}

- name: Upload original prebuild artifacts # mostly for debugging purposes
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.target }}
path: ./package/prebuilds/${{ matrix.target }}

# The below steps are needed for the release job

- name: Set NODE_ABI env var
run: echo "NODE_ABI=$(node -e 'console.log(process.versions.modules)')" >> "$GITHUB_ENV"

- name: Derive release artifact name
id: artifact-name
run: echo "NAME=${{ env.MODULE_NAME }}-${{ env.MODULE_VERSION }}-node-${{ env.NODE_ABI }}-${{ matrix.TARGET }}" >> "$GITHUB_OUTPUT"

- name: Prepare release artifact
run: tar -czf ${{ steps.artifact-name.outputs.NAME }}.tar.gz --directory=./package/prebuilds/${{ matrix.TARGET }} .

- name: Upload release artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifact-name.outputs.NAME }}
path: ./${{ steps.artifact-name.outputs.NAME }}.tar.gz

release:
if: ${{ startsWith(github.ref, 'refs/tags') }}
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.MODULE_NAME }}-${{ env.MODULE_VERSION }}-*/*.tar.gz"
artifactErrorsFailBuild: true
allowUpdates: true
replacesArtifacts: true
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_STORE

node_modules
package
*.tgz
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Digital Democracy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# nodejs-mobile-prebuilds-template

Template repository for building and publishing [NodeJS Mobile](https://github.com/nodejs-mobile/nodejs-mobile) prebuilds for a specific module

## Getting started

1. Create a new repository from this template using the GitHub UI. Alternatively can fork it.
2. Update the environment variables defined in the [workflow file](./.github/workflows/prebuilds.yml) based on your needs:

- `NODE_VERSION`: the Node version to use for building (you most likely do not need to change this)
- `MODULE_NAME`: the name of the module that you're building prebuilds for
- `MODULE_VERSION`: the package version of the module that your'e building (you most likely do not need to change this)

3. Remove the [`Getting started`](#getting-started) section of this README! (since it's specific to the template repo)

## Working locally

### Requirements

- Node >= 16 and npm < 9
- Android NDK 24.0.8215888
- (optional) exported `ANDROID_NDK_PATH` environment variable

### General steps

Should be clear enough to follow the workflow steps but in summary:

1. Download the npm tarball package and unzip e.g. `npm pack foo@latest | xargs tar -zxvf` (replace `foo@latest` with the relevant package name and version)

2. Navigate to unzipped directory and run `npx prebuild-for-nodejs-mobile TARGET`, where `TARGET` is an accepted value from the [`prebuild-for-nodejs-mobile`](https://github.com/staltz/prebuild-for-nodejs-mobile) CLI
- if you don't have the `ANDROID_NDK_PATH` environment variable exported, you may run the command like so: `ANDROID_NDK_HOME=/path/to/ndk npx prebuild-for-nodejs-mobile TARGET`

## Creating a release

1. Create a git tag that matches the version of the module you want to create prebuilds for e.g. `git tag 1.0.0`

2. Push the tag to the remote e.g. `git push origin 1.0.0`

3. The workflow uses the tag version to create the prebuilds and then publish a release with those prebuilds.

4. The relevant artifacts will show up in GitHub Releases. Each artifact is a tarball containing the `.node` files for the target-specific prebuild.

0 comments on commit 74a9e6f

Please sign in to comment.