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
14 changes: 12 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
jobs:
ci:
runs-on: ${{ matrix.os }}
# npm ci reads @plexinc packages, so do not rely on the repository
# default, which an organization can tighten without warning.
permissions:
contents: read
packages: read
env:
#hardcode the coveralls token...it's not overly important to protect, and github actions won't allow forks to work with coveralls otherwise
COVERALLS_REPO_TOKEN: "xTzWrR5HfbescAFnSnVXmWsVVMYglUMZi"
Expand All @@ -18,9 +23,14 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14.18.1"
node-version: "18.20.4"
architecture: 'x64' # fix for macos-latest
- run: npm ci
registry-url: 'https://npm.pkg.github.com'
scope: '@plexinc'
Comment thread
ljunkie marked this conversation as resolved.
Resolved
- name: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
run: npm ci
Comment thread
ljunkie marked this conversation as resolved.
Resolved
- run: npm run build
- run: npm run lint
- run: npm run test
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/create-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: "14.19.0"
node-version: "18.20.4"
registry-url: 'https://npm.pkg.github.com'
scope: '@plexinc'
Comment thread
ljunkie marked this conversation as resolved.
Resolved
# Get a bot token so the bot's name shows up on all our actions
- name: Get Token From roku-ci-token Application
uses: tibdex/github-app-token@v1
Expand All @@ -33,7 +35,10 @@ jobs:
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
echo "ARTIFACT_URL=$ARTIFACT_URL" >> $GITHUB_ENV

- run: npm ci
- name: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
run: npm ci
- run: npm version "$BUILD_VERSION" --no-git-tag-version
- run: npm pack

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

# Builds the current xelp/main, publishes it to GitHub Packages as
# @plexinc/<name>, then tags the commit and creates a GitHub release.
#
# Authentication is the workflow's own GITHUB_TOKEN, so there is no secret to
# provision or rotate. Reading a dependency that lives in another repository's
# package needs that repository granted under the package's Manage Actions
# access, not a different token. Consumers authenticate the way every other Plex
# client repo does, with a personal access token carrying read:packages.
#
# This replaces xelp_shadow_release.yml, which committed dist/ to the xelp/dist
# branch and served the package to consumers through a git tag. Run one or the
# other, never both: they compute the same version string and so want the same
# tag, and the shadow release force pushes it.
#
# Keep the shadow release around until roku-client, the only consumer of these
# forks, is installing from the @plexinc package. Then delete it.
#

on:
workflow_dispatch:
inputs:
dryRun:
description: Build and report what would be packed, without publishing, tagging or releasing.
type: boolean
default: false

# packages: write is the publish permission. contents: write is only for the
# tag and the release.
#
permissions:
contents: write
packages: write

jobs:
release:
runs-on: blacksmith-2vcpu-ubuntu-2404
steps:
- name: Check out xelp/main
uses: actions/checkout@v5
with:
ref: xelp/main
fetch-depth: 0

- name: Set up Node.js
uses: actions/setup-node@v5
with:
node-version: 20
registry-url: https://npm.pkg.github.com
scope: '@plexinc'

- name: Configure git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Work out the package name and version
id: release
run: |
set -euo pipefail

UPSTREAM_NAME=$(node -p "require('./package.json').name")

# Re-scope to @plexinc, dropping any existing scope, so
# @rokucommunity/bslint becomes @plexinc/bslint. GitHub Packages
# requires the scope to match the owner of this repository.
#
SCOPED_NAME="@plexinc/${UPSTREAM_NAME##*/}"

# Version scheme, unchanged from the shadow release: the upstream major
# and minor, then the build date with the upstream patch appended, so
# 0.70.3 built on 2026-08-28 becomes 0.70.202608283.
#
CURRENT_VERSION=$(node -p "require('./package.json').version")
BASE_VERSION=${CURRENT_VERSION%%[-+]*}

IFS='.' read -r -a PARTS <<< "$BASE_VERSION"
if [ ${#PARTS[@]} -ne 3 ]; then
echo "::error::Version $CURRENT_VERSION is not MAJOR.MINOR.PATCH"
exit 1
fi

VERSION="${PARTS[0]}.${PARTS[1]}.$(date -u +'%Y%m%d')${PARTS[2]}"

{
echo "upstream_name=$UPSTREAM_NAME"
echo "scoped_name=$SCOPED_NAME"
echo "version=$VERSION"
echo "metadata_version=$VERSION+xelp-$(git rev-parse --short HEAD)"
} >> "$GITHUB_OUTPUT"

# Published versions are immutable and tags are no longer force-pushed, so
# a same day re-run would collide twice over. Fail before doing the work.
#
- name: Fail if this version is already published
env:
# Only the three steps that talk to the registry get the token: this
# one, the install, and the publish. Building, linting, testing and
# packing do not reach the network, so they do not need it. Add it to
# any new step that runs npm against the registry.
#
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCOPED_NAME: ${{ steps.release.outputs.scoped_name }}
VERSION: ${{ steps.release.outputs.version }}
run: |
if npm view "$SCOPED_NAME@$VERSION" version >/dev/null 2>&1; then
echo "::error::$SCOPED_NAME@$VERSION is already published. Land another commit, or wait for tomorrow's date stamp."
exit 1
fi

# The publish happens before the tag, and a published version cannot be
# replaced, so a tag collision found at the tagging step would leave a
# published package that no re-run can tag. The shadow release used this
# same version scheme, so its tags are real candidates for a collision.
#
if git ls-remote --exit-code --tags origin "refs/tags/$VERSION" >/dev/null 2>&1; then
echo "::error::Tag $VERSION already exists. Land another commit, or wait for tomorrow's date stamp."
exit 1
fi

# The upstream lockfile is what keeps the transitive dependencies on
# working versions, so install from it rather than re-resolving. A clean
# re-resolve floats vscode-languageserver-protocol onto an exports only
# release that the TypeScript build cannot import.
#
- name: Install dependencies
env:
# Reading a dependency published from another repository requires that
# repository to be listed under the package's Manage Actions access.
# The grant is per package and is not inherited, so a newly published
# @plexinc package needs its consumers added before this will resolve.
#
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm ci

- name: Build
run: npm run build

# The shadow release ran the lint and test suites as a side effect of
# npm version, which triggers the preversion script. Setting the version
# through npm pkg set does not run lifecycle scripts, so the gate runs
# here where a failure names the step that failed.
#
- name: Lint
run: npm run lint

- name: Test
run: npm test

# The rename happens here and is never committed to xelp/main, so a merge
# from upstream never has to resolve a changed package name. The repository
# URL is what links the package to this repo, and GitHub Packages rejects
# the publish if it points anywhere else.
#
- name: Rewrite the package metadata for the @plexinc scope
env:
SCOPED_NAME: ${{ steps.release.outputs.scoped_name }}
VERSION: ${{ steps.release.outputs.version }}
run: |
npm pkg set name="$SCOPED_NAME"
npm pkg set version="$VERSION"
npm pkg set repository.url="git+https://github.com/${{ github.repository }}.git"

- name: Publish to GitHub Packages
if: ${{ !inputs.dryRun }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm publish

- name: Report what would be packed
if: ${{ inputs.dryRun }}
run: npm pack --dry-run

- name: Tag the release
if: ${{ !inputs.dryRun }}
env:
VERSION: ${{ steps.release.outputs.version }}
METADATA_VERSION: ${{ steps.release.outputs.metadata_version }}
run: |
git tag -a "$VERSION" -m "Release $METADATA_VERSION"
git push origin "$VERSION"

- name: Create the GitHub release
if: ${{ !inputs.dryRun }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPSTREAM_NAME: ${{ steps.release.outputs.upstream_name }}
SCOPED_NAME: ${{ steps.release.outputs.scoped_name }}
VERSION: ${{ steps.release.outputs.version }}
METADATA_VERSION: ${{ steps.release.outputs.metadata_version }}
run: |
gh release create "$VERSION" \
--repo "$GITHUB_REPOSITORY" \
--title "$SCOPED_NAME $VERSION" \
--notes "Built from \`$METADATA_VERSION\`.

Consume it with an alias, so the package keeps its upstream name inside \`node_modules\`:

\`\`\`json
\"$UPSTREAM_NAME\": \"npm:$SCOPED_NAME@$VERSION\"
\`\`\`" \
--prerelease
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use GitHub for @plexinc packages.
@plexinc:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:always-auth=true
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/node": "^14.6.0",
"@typescript-eslint/eslint-plugin": "^3.10.1",
"@typescript-eslint/parser": "^3.10.1",
"brighterscript": "https://github.com/plexinc/brighterscript.git#0.70.202603123",
"brighterscript": "npm:@plexinc/brighterscript@^0.70.0",
Comment thread
ljunkie marked this conversation as resolved.
Resolved
"chai": "^4.3.6",
"coveralls-next": "^4.2.0",
"eslint": "^7.7.0",
Expand Down
Loading