Skip to content
Merged
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
46 changes: 0 additions & 46 deletions .github/workflows/gpr-publish.yaml

This file was deleted.

67 changes: 67 additions & 0 deletions .github/workflows/publish-package-npm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Publish to NPM
Comment thread
RobinBol marked this conversation as resolved.
Comment thread
RobinBol marked this conversation as resolved.

# Publishes the package to npmjs.org using OIDC (Trusted Publisher).
#
# Requirements:
# - The `@athombv/jsdoc-template` package must have a Trusted Publisher
# configured on npmjs.org pointing at this repository and workflow file.
# - Bump the version on `master` via the Version workflow before merging to
# `production`.
#
# Steps:
# 1. Verifies a `files` array is present in package.json.
# 2. Installs dependencies and runs `npm run build` if it exists.
# 3. On `workflow_dispatch`: runs `npm publish --dry-run`.
# 4. On push to `production`: publishes to npmjs.org.

on:
workflow_dispatch:
push:
branches:
- production

permissions:
id-token: write
contents: read

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout git repository
uses: actions/checkout@v4

- name: Set up node
uses: actions/setup-node@v4
with:
# Node 24 bundles npm >= 11.5.1, required for OIDC `npm publish`.
node-version: '24'
registry-url: 'https://registry.npmjs.org/'

Comment thread
RobinBol marked this conversation as resolved.
- name: Verify files field in package.json
run: |
if ! jq -e .files package.json > /dev/null; then
echo "Missing 'files' array in package.json."
exit 1
fi

- name: Install dependencies
run: npm ci --ignore-scripts --audit=false

- name: Build
run: |
if jq --exit-status '.scripts | has("build")' package.json > /dev/null; then
echo "Running npm run build..."
npm run build
else
echo "No build script; skipping."
fi

- name: Publish dry run
if: github.event_name == 'workflow_dispatch'
run: npm publish --dry-run --provenance

- name: Publish
if: github.event_name == 'push' && github.ref == 'refs/heads/production'
run: npm publish --provenance
21 changes: 16 additions & 5 deletions .github/workflows/update-dependents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Update Dependent Repos

on:
workflow_run:
workflows: ["Publish to GitHub Packages Registry"]
workflows: ["Publish to NPM"]
Comment thread
RobinBol marked this conversation as resolved.
types:
- completed

Expand Down Expand Up @@ -161,17 +161,28 @@ jobs:
else . end
' package.json > package.json.tmp && mv package.json.tmp package.json

# Configure npm to use GitHub Packages for @athombv scope
echo "@athombv:registry=https://npm.pkg.github.com" >> .npmrc
echo "//npm.pkg.github.com/:_authToken=${GH_TOKEN}" >> .npmrc
# Strip any leftover @athombv -> GitHub Packages mapping from .npmrc
# so the new version resolves from npmjs.org. Remove the file when
# nothing meaningful remains.
if [ -f .npmrc ]; then
sed -i '/@athombv:registry/d; /npm.pkg.github.com/d' .npmrc
if [ ! -s .npmrc ] || ! grep -qv '^\s*$' .npmrc; then
Comment thread
RobinBol marked this conversation as resolved.
rm -f .npmrc
fi
fi

# Update lockfile
npm install --package-lock-only --ignore-scripts

# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json
# Stage the version bump, plus any add/modify/delete to .npmrc
# if it currently exists or is tracked in the repo.
git add -A -- package.json package-lock.json
if [ -e .npmrc ] || git ls-files --error-unmatch .npmrc > /dev/null 2>&1; then
git add -A -- .npmrc
fi
git commit -m "chore: update @athombv/jsdoc-template to ${NEW_SPEC}"

if ! git push --force origin "$BRANCH_NAME" 2>&1; then
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,13 @@

## How to use this template

This package is publicly distributed via [GitHub Packages](https://github.com/athombv/homey-jsdoc-template/pkgs/npm/jsdoc-template). No GitHub token is required to install it.

1. Add a `.npmrc` in the root of your project so npm resolves the `@athombv` scope to GitHub Packages:

```
@athombv:registry=https://npm.pkg.github.com
```

2. Install as a dev dependency
1. Install as a dev dependency

```bash
$ npm i --save-dev @athombv/jsdoc-template
```

3. Create `./jsdoc.json`:
2. Create `./jsdoc.json`:

```json
{
Expand Down Expand Up @@ -78,7 +70,7 @@ npm link @athombv/jsdoc-template

## Publishing
1. Bump the version on `master` via the [Version workflow](https://github.com/athombv/jsdoc-template/actions/workflows/version.yaml).
2. Merge `master` to `production` this will automatically publish the release to the GitHub Packages Registry.
2. Merge `master` to `production` - this will automatically publish the release to npmjs.org via OIDC (Trusted Publisher).
3. Create PRs in dependent repos via the [Update Dependents workflow](https://github.com/athombv/jsdoc-template/actions/workflows/update-dependents.yaml). This will automatically discover repos in the `athombv` org that use `@athombv/jsdoc-template` and open PRs to update them to the new version.


Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"/tmpl",
"/publish.js"
],
"publishConfig": {
"access": "public"
},
"author": "Athom B.V.",
"license": "GPL-3.0",
"dependencies": {
Expand Down