-
-
Notifications
You must be signed in to change notification settings - Fork 1
Addressing PR comments #146
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9aee728
Update npm publish workflow to use Trusted Publishing (OIDC), bump al…
Copilot 90c4931
Pin pnpm/action-setup to commit SHA for security
Claude 8b73797
CI: specify pnpm version for action-setup
Sans3108 075b230
Fix prettier.yml and add pnpm version specification to workflows
Claude df1ab08
Format files with Prettier
actions-user 17986a3
Generalize PUBLISHING.md to remove personal details
Claude 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 |
|---|---|---|
| @@ -1,39 +1,38 @@ | ||
| # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created | ||
| # For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | ||
| # Publishes the package to npm when a GitHub release is created. | ||
| # Uses npm Trusted Publishing (OIDC) — no NPM_TOKEN secret required. | ||
| # See PUBLISHING.md for setup instructions. | ||
|
|
||
| name: Node.js Package | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| name: Publish to npm | ||
|
|
||
| on: | ||
| release: | ||
| types: [created] | ||
|
|
||
| jobs: | ||
| publish-npm: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write # Required for npm Trusted Publishing (OIDC) | ||
| steps: | ||
| - name: Check out code | ||
| uses: actions/checkout@v4 | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v5 | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@v4 | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: 'package.json' # Grabs node version from package.json | ||
| node-version-file: 'package.json' | ||
| registry-url: https://registry.npmjs.org/ | ||
| cache: pnpm | ||
|
|
||
| - name: Install pnpm | ||
| run: npm install -g pnpm | ||
|
|
||
| - name: Install deps | ||
| run: pnpm i | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Build package | ||
| run: pnpm build | ||
|
|
||
| - name: Publish package | ||
| run: pnpm publish --no-git-checks | ||
| env: | ||
| NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
| run: npm publish --provenance --access public | ||
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,67 @@ | ||
| # Publishing to npm | ||
|
|
||
| This project uses **npm Trusted Publishing** (OIDC) via GitHub Actions. | ||
| When a GitHub release is created, the [npm-publish workflow](.github/workflows/npm-publish.yml) automatically builds and publishes the package to npm — no long-lived tokens required. | ||
|
|
||
| ## One-time setup (npmjs.com) | ||
|
|
||
| > You must have published at least one version of the package to npm before you can enable trusted publishing. | ||
|
|
||
| 1. Go to [npmjs.com](https://www.npmjs.com) and sign in to the account that owns the `ddnet` package. | ||
| 2. Navigate to the **package settings** page: <https://www.npmjs.com/package/ddnet/access> | ||
| 3. Under **Publishing access**, find the **Trusted Publishers** section. | ||
| 4. Click **Add a trusted publisher** and fill in: | ||
| - **Organization or user:** `Sans3108` | ||
| - **Repository:** `DDNet` | ||
| - **Workflow filename:** `npm-publish.yml` | ||
| - **Environment:** _(leave blank)_ | ||
| 5. Save the configuration. | ||
|
|
||
| Once this is done, the GitHub Actions workflow can publish to npm using OIDC without any stored secrets (`NPM_TOKEN` is no longer needed and can be removed from the repository secrets if it exists). | ||
|
|
||
| ## How to publish a new release | ||
|
|
||
| 1. **Update the version** in `package.json`: | ||
| ```bash | ||
| # Bump the patch version (e.g., 0.10.2 → 0.10.3) | ||
| npm version patch | ||
|
|
||
| # Or for a minor version bump (e.g., 0.10.2 → 0.11.0) | ||
| npm version minor | ||
|
|
||
| # Or for a major version bump (e.g., 0.10.2 → 1.0.0) | ||
| npm version major | ||
| ``` | ||
| This updates `package.json` and creates a git tag automatically. | ||
|
|
||
| 2. **Push the commit and tag** to GitHub: | ||
| ```bash | ||
| git push origin master --follow-tags | ||
| ``` | ||
|
|
||
| 3. **Create a GitHub release** from the tag: | ||
| - Go to <https://github.com/Sans3108/DDNet/releases/new> | ||
| - Select the tag you just pushed (e.g., `v0.10.3` or `0.10.3`) | ||
| - Fill in the release title and notes | ||
| - Click **Publish release** | ||
|
|
||
| 4. The **npm-publish** workflow will trigger automatically, build the package, and publish it to npm with [provenance](https://docs.npmjs.com/generating-provenance-statements) attached. | ||
|
|
||
| ## What the workflow does | ||
|
|
||
| ``` | ||
| checkout → install pnpm → setup node → pnpm install → pnpm build → npm publish --provenance | ||
| ``` | ||
|
|
||
| - Uses OIDC (`id-token: write` permission) so npm can verify the package was published from this repository. | ||
| - Runs `pnpm install --frozen-lockfile` for reproducible builds. | ||
| - Publishes with `--provenance` so consumers can verify the package origin on npmjs.com. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Problem | Fix | | ||
| |---|---| | ||
| | **"No matching trusted publisher"** error in CI | Ensure the workflow filename in npmjs.com settings matches exactly: `npm-publish.yml` | | ||
| | **403 Forbidden** during publish | Verify that trusted publishing is configured for the correct user/org and repo on npmjs.com | | ||
| | **Version already exists** | You need to bump the version in `package.json` before publishing. npm does not allow re-publishing the same version. | | ||
| | **Provenance error** | Make sure the workflow has `permissions: id-token: write` and is running in a public repository | |
Oops, something went wrong.
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.