Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automate package publishing using semantic-release #68

Merged
merged 8 commits into from
Mar 14, 2023
Merged
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
9 changes: 6 additions & 3 deletions .github/workflows/lint.pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: current
- uses: pnpm/action-setup@v2
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
Expand Down
107 changes: 107 additions & 0 deletions .github/workflows/pr-title-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: PR Title Checker

on:
pull_request:
types: ["opened", "edited", "reopened", "synchronize"]
branches:
- '*'
- '*/*'
- '**'
- '!master'

jobs:
check:
name: Validate PR Title
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: current
- name : Get Title of PR
uses: actions/github-script@v6
id: pr-title
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: json
script: |
const { data: pr } = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
return pr.title;
- name : Test Title of PR
uses: actions/github-script@v6
id: pr-title-check
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: json
script: |
const prTitle = ${{steps.pr-title.outputs.result}};
const regex = new RegExp('^(chore|docs|feat|fix|perf|refactor|style|test|build|revert)((.+))?:(.+)');
return !regex.test(prTitle);
- name: Update PR Comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: json
script: |
// Retrieve existing bot comments for the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment => {
return comment.user.type === 'Bot' && comment.body.includes('Incorrect Pull Request Title Format')
});

if (${{steps.pr-title-check.outputs.result}}) {
const body = `**Incorrect Pull Request Title Format**
The title of this pull request does not appear to match the commit message format.
\`\`\`
Examples from Commitizen
\`\`\`
![](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)
`;

// If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body
});
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
});
}
return;
}
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: `:sparkles: **Valid Pull Request Title Format** :sparkles:`,
});
return;
}
- name: Check PR Title Status
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: json
script: |
const hasError = ${{steps.pr-title-check.outputs.result}};
if (hasError) {
core.setFailed('PR Title Checker job has failed!');
}
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Release
on:
push:
branches:
- master
- alpha
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: current
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
- name: Test
run: pnpm test
- name: Build
run: pnpm build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
9 changes: 6 additions & 3 deletions .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: current
- uses: pnpm/action-setup@v2
- name: Install pnpm and dependencies
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/update-alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Update alpha
on:
workflow_run:
workflows:
- Release
branches:
- master
types: completed
jobs:
rebase:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Rebase alpha to master
run: |
git fetch --unshallow
git checkout alpha
git rebase origin/master
git push
1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

21 changes: 21 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"branches": [{ "name": "master" }, { "name": "alpha", "prerelease": true }],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
"tarballDir": "release"
}
],
[
"@semantic-release/github",
{
"assets": "release/*.tgz"
}
],
"@semantic-release/git"
]
}
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,29 @@ Run `node dev.js` or `pnpm dev`
Usage: node dev.js [-c <string> | --cliClasses=<string>] [--usePixels] [--development] [--externalClasses] [--externalizeClasses] [--usePreflight]

Example: `node dev.js --usePixels --development --cliClasses=m-2`
! Do not use shortcut when passing negative values, e.g. `node dev.js --cliClasses='-m-2! gap-2'`
! Do not use shortcut when passing negative values, e.g. `node dev.js --cliClasses='-m-2! gap-2'`

## Contributing

We use [commitizen](https://github.com/commitizen/cz-cli) to ensure coherent commit message structure, used by [semantic release](#releases) to generate change logs and handle versioning.

```
npm install -g commitizen
```

When installed, you should be able to type `cz` or `git cz` in your terminal to commit your changes (replacing
`git commit`).

[![Add and commit with Commitizen](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)](https://github.com/commitizen/cz-cli/raw/master/meta/screenshots/add-commit.png)


## Releases

This project uses [Semantic Release](https://github.com/semantic-release/semantic-release) to automate package
publishing when making changes to the `master` or `alpha` branch.

It is recommended to branch off the `alpha` branch and follow
[conventional commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) when making changes. When your
changes are ready for pull request, this should be opened against the `alpha` branch.

Please note that the version published will depend on your commit message structure. Make sure to use commitizen (see [Development section](#Contributing)).
20 changes: 19 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@warp-ds/uno",
Copy link
Contributor

Choose a reason for hiding this comment

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

Been wondering about this... is there a reason why the package is named uno and not drive? 🤔😅

Copy link
Contributor

@pearofducks pearofducks Mar 14, 2023

Choose a reason for hiding this comment

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

Users have no relation to the word drive. They're using this package in an UnoCSS context. We don't need to be filling users' heads with "OK I want the Warp Uno preset, was that @warp-ds/drive or @warp-ds/speed or the other gimmicky package name they went with?" 😆

preset or preset-uno might be an even better name - but it's possible at some point we want to export more than just a preset from this package.

Copy link
Contributor

Choose a reason for hiding this comment

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

...then my next question is: Why is it called drive and not uno in github? 🤷‍♂️😅😜 I was a bit confused about this since all other repos is mapped 1:1 between github and npm? (Or at least I think they are? 🤔😄)

Copy link
Contributor

Choose a reason for hiding this comment

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

Basically "for the lulz". I agree with your logic, we could have some kind of alias repo to be sure people find the right thing. I'm up for whatever the team feels is best here to aid users understanding our packages and being able to discover things.

Copy link
Contributor

Choose a reason for hiding this comment

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

"for the lulz"

Totally reasonable reason. 👌😄

"repository": "git@github.com:warp-ds/drive.git",
"version": "0.0.15",
"type": "module",
"exports": {
Expand All @@ -17,12 +18,17 @@
"#preflights": "./src/_preflights/index.js",
"#postprocess": "./src/postprocessor.js"
},
"files": [
"dist",
"src",
"dev.js"
],
"scripts": {
"commit": "cz",
"dev": "node dev.js",
"dev:env": "vite dev-env --config ./vite.config.js",
"test": "vitest",
"build": "rollup -c",
"version": "pnpm test && pnpm build && pnpm publish",
"lint": "eslint . --fix",
"lint:check": "eslint ."
},
Expand All @@ -35,17 +41,29 @@
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.1",
"@semantic-release/changelog": "^6.0.2",
"@semantic-release/git": "^10.0.1",
"@unocss/autocomplete": "^0.50.4",
"@warp-ds/eslint-config": "^0.0.1",
"cz-conventional-changelog": "^3.3.0",
"drnm": "^0.9.0",
"eslint": "^8.35.0",
"rollup": "^3.18.0",
"semantic-release": "^20.1.1",
"unocss": "^0.50.4",
"uvu": "^0.5.6",
"vite": "^4.1.4",
"vitest": "^0.29.2"
},
"eslintConfig": {
"extends": "@warp-ds"
},
"publishConfig": {
"access": "public"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}
Loading