Skip to content
Open
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
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish to npm

on:
workflow_run:
workflows: ["Main"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

runs only if Main workflow completed

types:
- completed
branches: [ "main" ]

jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

runs only on succesful completion of main.yml

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org/'
- uses: oven-sh/setup-bun@v1
- run: bun install
- name: update changelog
run: |
if bun run update-changelog; then
echo "changelog updated"
else
echo "skipping publish because no changes were detected"
exit 1
fi
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Push tags
run: |
git config --local user.name "github-actions"
git config --local user.email "[email protected]"
git push origin main --tags
Copy link
Collaborator Author

@jkone27 jkone27 May 23, 2025

Choose a reason for hiding this comment

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

then push origin main as a new commit and git tagging was prev made by npm version x command

8 changes: 6 additions & 2 deletions changelog-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const version = await $`bunx changelog --latest-release`.text();
const packageVersion = await $`npm info vite-plugin-fable version`.text();

if (version === packageVersion) {
process.exit(0);
console.log("version is already up to date, do not publish");
process.exit(1);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if same version, return error / false - no need to publish or further actions in publication

}

await $`npm version ${version.trim()}`;
await $`npm version ${version.trim()}`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

else npm version x (exit code 0 is success by default)


console.log(`Updated package.json version to ${version.trim()}`);
console.log(`Run 'git push origin main --tags' after publishing to push the new version tag.`);
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"format": "bunx --bun prettier ./package.json ./index.js ./types.d.ts ./sample-project/vite.config.js ./docs/*.md ./docs/content/*.css ./docs/scripts/*.js ./docs/*.html ./.devcontainer/devcontainer.json --write && dotnet fantomas .",
"postinstall": "dotnet publish Fable.Daemon/Fable.Daemon.fsproj --nologo -c Release --ucr -p:PublishReadyToRun=true -o ./bin",
"lint": "bunx tsc",
"prepublishOnly": "bun changelog-updater.js"
"update-changelog": "bun changelog-updater.js",
"manualPublish": "bun run update-changelog && npm publish"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can still run manually with this command, instead of relying on pre publish npm hook

},
"files": [
"index.js",
Expand Down