Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: 'Debug: List post build files'
run: find * \( -path node_modules -o -path .git \) -print -prune -o -type f -print | tee /tmp/build.list

- name: 'Get Package Name'
run: echo "PACKAGE_NAME=$(jq -r .name package.json)" >> "$GITHUB_ENV"

# Prepare Test Environment

- name: Create Dummy Package.json
Expand All @@ -37,7 +40,7 @@ jobs:

- name: 'Debug: List Dependency Folder Contents'
working-directory: test
run: find node_modules/userid -type f -print
run: find "node_modules/${PACKAGE_NAME}" -type f -print

# Ensure the code works

Expand All @@ -50,7 +53,7 @@ jobs:
- name: Run Tests with Prepared Git Dependency
run: npm test -- --color
env:
MOCHA_IMPORT_OVERRIDE: userid
MOCHA_IMPORT_OVERRIDE: ${{env.PACKAGE_NAME}}
LONG_USERNAME_TEST: UsernameWithMoreThan15Chars
LONG_GROUPNAME_TEST: GroupnameWithMoreThan15Chars

Expand Down
230 changes: 230 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Release

on:
push:

pull_request:
branches:
- master

release:
types: [published]

workflow_dispatch:
inputs:
new-version:
description: New version to be published, overrides tag
required: true
type: string

npm-tag:
description: NPM tag
required: true
default: latest
type: choice
options:
- latest
- next

jobs:
build:
strategy:
matrix:
include:
- os: ubuntu-22.04
arch: linux-x64-glibc
- os: ubuntu-22.04-arm
arch: linux-arm64-glibc
- os: macos-13
arch: darwin-x64
- os: macos-14
arch: darwin-arm64

name: Build for ${{ matrix.arch }}
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Use Node.js 20
uses: actions/setup-node@v4
with:
cache: npm
node-version: 20

- name: Install dependencies
run: npm ci

- name: Prebuild
run: npm run build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: prebuild-${{ matrix.arch }}
path: prebuilds/**/*.node

build-musl:
strategy:
matrix:
include:
- os: ubuntu-22.04
arch: x64
platform: linux/amd64
- os: ubuntu-22.04-arm
arch: arm64
platform: linux/arm64
- os: ubuntu-22.04-arm
arch: armv7
platform: linux/arm/v7

name: Build for linux-${{ matrix.arch }}-musl
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform }}

- name: Prebuild
uses: addnab/docker-run-action@v3
with:
image: node:20-alpine
options: --platform=${{ matrix.platform }} --volume=${{ github.workspace }}:/repo --workdir=/repo
run: |
apk add --no-cache g++ make python3
npm ci
npm run build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: prebuild-linux-${{ matrix.arch }}-musl
path: prebuilds/**/*.node

build-freebsd-x64:
name: Build for freebsd-x64
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Prebuild
uses: vmactions/freebsd-vm@v1
with:
prepare: |
pkg install -y gmake python3 npm-node20
run: |
npm ci
npm run build
sync: sshfs

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: prebuild-freebsd-x64
path: prebuilds/**/*.node

build-linux-armv7-glibc:
name: Build for linux-armv7-glibc
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: linux/arm/v7

- name: Prebuild
uses: addnab/docker-run-action@v3
with:
image: node:20-bullseye
options: --platform=linux/arm/v7 --volume=${{ github.workspace }}:/repo --workdir=/repo
run: |
apt update -yq && apt install -yq wget
wget -qL https://deb.nodesource.com/setup_20.x | bash -
apt install -yq g++ make python3 nodejs
npm ci
npm run build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: prebuild-linux-armv7-glibc
path: prebuilds/**/*.node

publish:
name: Publish package
runs-on: ubuntu-latest

permissions:
contents: read
id-token: write

needs:
- build
- build-musl
- build-freebsd-x64
- build-linux-armv7-glibc

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true

- name: Setup npm with Node.js 20
uses: actions/setup-node@v4
with:
cache: npm
node-version: 20
token: ${{ secrets.NPM_TOKEN }}
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Download artifacts
id: download-artifact
uses: actions/download-artifact@v4

- name: Move prebuild artifacts
run: mkdir prebuilds && cp --recursive prebuild-*/* prebuilds/

- name: Pack package
run: npm pack
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}

- name: Upload package artifact
uses: actions/upload-artifact@v4
if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }}
with:
name: package
path: '*.tgz'

- name: Publish to NPM
run: |
npm version --allow-same-version --no-git-tag-version $VERSION
npm publish --provenance --tag $TAG
if: ${{ !env.ACT && (github.event_name == 'release' || github.event_name == 'workflow_dispatch') }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
TAG: ${{ inputs.npm-tag || 'latest' }}
VERSION: ${{ inputs.new-version || github.ref_name }}
4 changes: 2 additions & 2 deletions .github/workflows/versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, macos-13]
# There are problems on various architectures on lower versions that are more work to fix. Please open an issue if you need more version support
node: [12, 13, 14, 15, 16]
node: [16, 18, 20, 22]

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
prebuilds/
*.swp
node_modules
.idea/
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

Simple Node.js library with native bindings for getting uid and gid information.

[![](https://github.com/cinderblock/node-userid/workflows/Main/badge.svg)](https://github.com/cinderblock/node-userid/actions)
[![](https://github.com/cinderblock/node-userid/workflows/Test%20All%20Versions/badge.svg)](https://github.com/cinderblock/node-userid/actions)
[![Coverage Status](https://coveralls.io/repos/github/cinderblock/node-userid/badge.svg?branch=master)](https://coveralls.io/github/cinderblock/node-userid?branch=master)
[![](https://github.com/matthewh/node-userid/workflows/Main/badge.svg)](https://github.com/cinderblock/node-userid/actions)
[![](https://github.com/matthewh/node-userid/workflows/Test%20All%20Versions/badge.svg)](https://github.com/cinderblock/node-userid/actions)
[![Coverage Status](https://coveralls.io/repos/github/matthewh/node-userid/badge.svg?branch=master)](https://coveralls.io/github/cinderblock/node-userid?branch=master)

## Installation

```bash
$ npm install userid
# Or, alternatively, directly from github:
$ npm install cinderblock/node-userid
$ npm install @hershbergien/userid
```

This relies on GNU `getgrname` and `getgrid`.
Expand Down Expand Up @@ -70,7 +68,6 @@ Pull requests that would bring Windows into the fold would be welcome.

### Improvements to be made

- Publish pre-built versions of packages
- Don't depend on coveralls for coverage reports (maybe with [Standalone Stats](https://github.com/cinderblock/github-action-standalone-stats))
- Implement any `TODO`s found in the sources or tests
- Automatic testing of latest versions of Node/OSes
Expand All @@ -80,6 +77,8 @@ Pull requests that would bring Windows into the fold would be welcome.

## History

Version 2.0.0 adds prebuilt binaries for compatible architectures.

This package was originally created by [Jen Andre](https://github.com/jandre/node-userid) <jandre@gmail.com>.

In 2019, it was, unfortunately, missing updates that are required to run on the latest versions of Node.js.
Expand All @@ -91,7 +90,7 @@ It also signals the change to using Github Actions to run all our full coverage

## License

The license, when the package was created, had some mix of GLPv3 and Public Domain.
The license, when the package was created, had some mix of GPLv3 and Public Domain.

Since the main source code has always been Public Domain, I believe it should stay that way.
I've also explicitly extended it to the rest of the main (published) source code.
Expand Down
7 changes: 6 additions & 1 deletion cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"passwd",
"userid",
"tracefile",
"xcode"
"xcode",
"Hershberger",
"hershbergien",
"prebuildify",
"prebuilds",
"armv"
]
}
2 changes: 1 addition & 1 deletion lib/userid.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This code is PUBLIC DOMAIN, and is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.

module.exports = require('bindings')('userid.node');
module.exports = require('node-gyp-build')(`${__dirname}/..`);

// Historically, this function was defined similar to this by Jen's original implementation
module.exports.uid = (...args) => module.exports.ids(...args).uid;
Loading