forked from rokucommunity/brighterscript-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
[XELP] Publish releases to GitHub Packages #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6ede33c
Publish releases to GitHub Packages under the @plexinc scope.
ljunkie 6a01a23
Disable the shadow release in favour of the npm release.
ljunkie e0bd805
Depend on the published @plexinc/brighterscript package.
ljunkie 7a81f48
Give CI access to the @plexinc registry.
ljunkie 0c94a51
Scope the registry token to the steps that use npm.
ljunkie f145eaf
Read @plexinc dependencies with the organization token.
ljunkie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| 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. Consumers authenticate the way every other Plex client | ||
| # repo does, with a personal access token carrying read:packages. | ||
|
ljunkie marked this conversation as resolved.
|
||
| # | ||
| # 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 pack, but do not publish, tag, or release. | ||
| 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 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: | ||
| # Dependencies can live in another repo's package, and a repository's | ||
| # own GITHUB_TOKEN cannot read those, so prefer the organization token. | ||
| # The fallback keeps this working in a fork that has no @plexinc | ||
| # dependencies, where the repo token is enough. | ||
| # | ||
| NODE_AUTH_TOKEN: ${{ secrets.GH_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: Pack without publishing | ||
| 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 | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
Comment on lines
+1
to
+3
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.