Skip to content

Commit

Permalink
chore: add CICD to publish
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Jun 15, 2024
1 parent 5447ce3 commit f4363a6
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Publish package

on: workflow_dispatch

permissions:
contents: write

jobs:
publish_package:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Bun
uses: oven-sh/setup-bun@v1

- id: changelog
name: Generate changelog
run: bun scripts/generate-changelog.ts

- name: Install modules
run: bun install

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"

- name: Build package
run: bun run prepublishOnly

- name: Run publint
run: bunx publint

- name: Publish package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: GitHub Release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ steps.changelog.outputs.version }}
name: v${{ steps.changelog.outputs.version }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
generateReleaseNotes: true
1 change: 1 addition & 0 deletions esbuild-plugin-autoload
Submodule esbuild-plugin-autoload added at 68c2af
36 changes: 36 additions & 0 deletions scripts/generate-changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { execSync } from "node:child_process";
import { randomUUID } from "node:crypto";
import { appendFileSync } from "node:fs";
import { EOL } from "node:os";

function getLatestTag() {
try {
return execSync("git describe --abbrev=0 --tags").toString().trim();
} catch (e) {
console.warn(e);
return execSync("git rev-list --max-parents=0 HEAD").toString().trim();
}
}

const commits = execSync(
`git log ${getLatestTag()}..HEAD --pretty="format:%s%b"`,
)
.toString()
.trim()
.split("\n")
.reverse();

console.log(getLatestTag(), commits);

const version = execSync("npm pkg get version").toString().replace(/"/gi, "");

const delimiter = `---${randomUUID()}---${EOL}`;

if (process.env.GITHUB_OUTPUT)
appendFileSync(
process.env.GITHUB_OUTPUT,
`changelog<<${delimiter}${commits.join(
EOL.repeat(2),
)}${EOL}${delimiter}version=${version}${EOL}`,
);
else console.log("Not github actions");

0 comments on commit f4363a6

Please sign in to comment.