Skip to content

Commit

Permalink
Add auto-publish on push to release branch
Browse files Browse the repository at this point in the history
  • Loading branch information
firefoxic committed Jul 30, 2024
1 parent 561ab1e commit ed221b7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release

on:
push:
branches:
- release

permissions:
contents: write
id-token: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version-file: package.json
cache: pnpm
- run: pnpm install
- run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
git config --global user.email "firefoxic.dev@gmail.com"
git config --global user.name "firefoxic"
version_type=$(node scripts/determine-version.js)
if [ -n "$version_type" ]; then
pnpm version ${version_type}
pnpm publish --provenance --access public --no-git-checks
fi
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"prepare": "husky",
"preversion": "pnpm test",
"version": "./bin/cli.js",
"postversion": "pnpm publish --access=public",
"postversion": "if [ \"$CI\" != \"true\" ]; then pnpm publish --access public; fi",
"postpublish": "git push --follow-tags",
"lint": "eslint",
"test": "node --test",
Expand Down
18 changes: 18 additions & 0 deletions scripts/determine-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { cwd } from "node:process"
import { join } from "node:path"
import { readFileSync } from "node:fs"

let changelogPath = join(cwd(), `CHANGELOG.md`)
let changelog = readFileSync(changelogPath, `utf-8`)
let unreleasedSection = changelog.split(`## [Unreleased]`)[1].split(`## [`)[0]
let versionType = ``

if (unreleasedSection.includes(`### Changed`)) {
versionType = `major`
} else if (unreleasedSection.includes(`### Added`)) {
versionType = `minor`
} else if (unreleasedSection.includes(`### Fixed`)) {
versionType = `patch`
}

console.log(versionType)

0 comments on commit ed221b7

Please sign in to comment.