Skip to content
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

ci: Add GH workflow for publishing to npm. #43

Merged
merged 12 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
64 changes: 64 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "publish-npm"

on:
release:
types: ["created"]
workflow_dispatch:

permissions: {}

jobs:
build:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"

- name: "Install task"
run: "npm install -g @go-task/cli"
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved

- name: "Run package task"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the purpose of the name is to add comments, that just repeat the command. right, we don't need it

run: "task package"

- name: "Upload build artifacts"
uses: "actions/upload-artifact@v4"
with:
path: "dist/"
junhaoliao marked this conversation as resolved.
Show resolved Hide resolved

publish-npm:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about publish-to-npm?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Shall we also update the workflow name and filename to match this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, good idea.

needs: ["build"]
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v4"
- uses: "actions/download-artifact@v4"

- uses: "actions/setup-node@v4"
with:
node-version: 22
registry-url: "https://registry.npmjs.org/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using LTS version of Node.js

Node.js 22 is currently in development. For production publishing workflows, it's recommended to use an LTS version.

       with:
-          node-version: 22
+          node-version: 20
           registry-url: "https://registry.npmjs.org/"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- uses: "actions/setup-node@v4"
with:
node-version: 22
registry-url: "https://registry.npmjs.org/"
- uses: "actions/setup-node@v4"
with:
node-version: 20
registry-url: "https://registry.npmjs.org/"


- run: "npm publish"
env:
NODE_AUTH_TOKEN: "${{secrets.NPM_TOKEN}}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add package validation steps before publishing

Consider adding validation steps before publishing to ensure package integrity.

+      - name: "Validate package"
+        run: |
+          npm pack --dry-run
+          npm audit
+
       - run: "npm publish"
         env:
           NODE_AUTH_TOKEN: "${{secrets.NPM_TOKEN}}"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- run: "npm publish"
env:
NODE_AUTH_TOKEN: "${{secrets.NPM_TOKEN}}"
- name: "Validate package"
run: |
npm pack --dry-run
npm audit
- run: "npm publish"
env:
NODE_AUTH_TOKEN: "${{secrets.NPM_TOKEN}}"


create-branch:
kirkrodrigues marked this conversation as resolved.
Show resolved Hide resolved
needs: ["publish-npm"]
runs-on: "ubuntu-latest"
permissions:
# For creating a new branch
contents: write

Check failure on line 50 in .github/workflows/publish-npm.yml

View workflow job for this annotation

GitHub Actions / lint (macos-latest)

50:17 [quoted-strings] string value is not quoted with double quotes
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0

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

- name: "Create and push branch"
run: |
git checkout -b "${{github.ref_name}}"
git push origin "refs/heads/${{github.ref_name}}"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"url": "https://github.com/y-scope/clp-ffi-js/issues"
},
"scripts": {
"release": "git diff --exit-code && npm publish"
"release": "git diff --exit-code && task package && npm publish"
},
"type": "module",
"files": [
Expand Down
Loading