Publish NPM Package #7
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
| name: Publish NPM Package | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_bump: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GA_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Setup Rust | |
| uses: actions-rs/toolchain@v1 | |
| with: | |
| toolchain: stable | |
| override: true | |
| - name: Install wasm-pack | |
| run: | | |
| curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | |
| - name: Configure git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "actions[bot]@github.com" | |
| - name: Build WASM | |
| run: | | |
| cd src/rust/wasm | |
| wasm-pack build --target web --out-dir ../../ts | |
| - name: Update package.json with custom name and bump version | |
| run: | | |
| cd src/ts | |
| # First, update package.json with custom metadata | |
| node -e " | |
| const fs = require('fs'); | |
| const genPkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| const customPkg = { | |
| \"name\": \"@cityjson\/flatcitybuf\", | |
| \"type\": \"module\", | |
| \"version\": genPkg.version, | |
| \"description\": \"FlatCityBuf is a library for reading and writing CityJSON with FlatBuffers.\", | |
| \"author\": { | |
| \"name\": \"Hidemichi Baba\", | |
| \"email\": \"baba.papa1120.ba@gmail.com\" | |
| }, | |
| \"license\": \"MIT\", | |
| \"repository\": { | |
| \"type\": \"git\", | |
| \"url\": \"https://github.com/cityjson/flatcitybuf\" | |
| }, | |
| \"homepage\": \"https://github.com/cityjson/flatcitybuf\", | |
| \"bugs\": { | |
| \"url\": \"https://github.com/cityjson/flatcitybuf/issues\" | |
| }, | |
| \"keywords\": [ | |
| \"cityjson\", | |
| \"flatbuffers\", | |
| \"wasm\", | |
| \"geospatial\", | |
| \"3d-city-models\" | |
| ], | |
| \"files\": [ | |
| genPkg.files | |
| ], | |
| \"main\": genPkg.main, | |
| \"types\": genPkg.types, | |
| \"sideEffects\": genPkg.sideEffects || [ | |
| \"./snippets/*\" | |
| ] | |
| }; | |
| fs.writeFileSync('package.json', JSON.stringify(customPkg, null, 2)); | |
| " | |
| # Then bump the version | |
| npm version ${{ github.event.inputs.version_bump }} --no-git-tag-version | |
| - name: Commit version bump | |
| run: | | |
| git add . | |
| git commit -m "chore: bump npm version (${{ github.event.inputs.version_bump }})" | |
| git push | |
| - name: Publish to NPM | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: | | |
| cd src/ts | |
| npm publish --access public |