diff options
| author | Soccera1 <[email protected]> | 2026-08-06 01:58:10 +1000 |
|---|---|---|
| committer | Soccera1 <[email protected]> | 2026-08-06 02:00:12 +1000 |
| commit | d11632d44b740ab8b78ec27544afb480f406a9d5 (patch) | |
| tree | 7b56ee4e54a7858c01e1c8b4a74832e9db8eaa09 /.github/workflows | |
| parent | 471a0af4628e4796421fdba55ebc79bb4240c47e (diff) | |
| download | bnu-d11632d44b740ab8b78ec27544afb480f406a9d5.tar.gz bnu-d11632d44b740ab8b78ec27544afb480f406a9d5.zip | |
Automatically publish to npm
Diffstat (limited to '.github/workflows')
| -rw-r--r-- | .github/workflows/publish.yml | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..ea1108d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,77 @@ +name: Publish to npm + +on: + push: + branches: + - master + +concurrency: + group: npm-publish + cancel-in-progress: false + +permissions: + contents: read + id-token: write + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Bun + uses: oven-sh/setup-bun@v2 + + - name: Set up Node for npm + uses: actions/setup-node@v4 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + + - name: Build optimized package + run: bun run build + + - name: Choose daily version + id: release + shell: bash + run: | + version="$(node --input-type=module <<'NODE' + import { readFile } from "node:fs/promises"; + + const packageJson = JSON.parse(await readFile("package.json", "utf8")); + const date = new Date().toISOString().slice(0, 10).replaceAll("-", ""); + const escapedName = packageJson.name.replace("/", "%2f"); + const response = await fetch(`https://registry.npmjs.org/${escapedName}`); + + let versions = []; + if (response.status !== 404) { + if (!response.ok) { + throw new Error(`npm registry returned ${response.status} ${response.statusText}`); + } + const metadata = await response.json(); + versions = Object.keys(metadata.versions ?? {}); + } + + const pattern = new RegExp(`^${date}\\.0\\.(\\d+)$`); + const previous = versions + .map((version) => pattern.exec(version)?.[1]) + .filter((increment) => increment !== undefined) + .map(Number); + const increment = previous.length === 0 ? 0 : Math.max(...previous) + 1; + + process.stdout.write(`${date}.0.${increment}`); + NODE + )" + + npm pkg set version="$version" + echo "version=$version" >> "$GITHUB_OUTPUT" + + - name: Verify package contents + run: npm pack --dry-run + + - name: Publish ${{ steps.release.outputs.version }} + run: npm publish --access public --provenance + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
