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

build: add automated releases and pre-commit hooks #289

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{ "extends": ["@commitlint/config-conventional"] }
{
"extends": ["@commitlint/config-conventional"]
}
39 changes: 39 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: 'publish'

on:
push:
branches: [master]

jobs:
publish:
needs: ci
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- uses: actions/setup-node@v3
with:
node-version: latest
- run: npm install
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
Copy link
Author

Choose a reason for hiding this comment

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

@theoludwig what are your thoughts on using a Personal Access Token instead of the default GITHUB_TOKEN secret that GitHub provides?

From a note in semantic-release's documentation:

Automatically populated GITHUB_TOKEN cannot be used if branch protection is enabled for the target branch. It is not advised to mitigate this limitation by overriding an automatically populated GITHUB_TOKEN variable with a Personal Access Token, as it poses a security risk. Since Secret Variables are available for Workflows triggered by any branch, it becomes a potential vector of attack, where a Workflow triggered from a non-protected branch can expose and use a token with elevated permissions, yielding branch protection insignificant. One can use Personal Access Tokens in trusted environments, where all developers should have the ability to perform administrative actions in the given repository and branch protection is enabled solely for convenience purposes, to remind about required reviews or CI checks.

I'm unsure to whether ts-standard has branch protection enabled on the master branch (I'm guessing yes).

NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
ci:
needs: get-supported-node-versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use latest version of Node.js
uses: actions/setup-node@v3
with:
node-version: latest
- run: npm install
- run: npm run lint:commit -- --to "${{ github.sha }}"
- run: npm run lint:standard
- run: npm run lint:ts-standard
- run: npm run test

4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
6 changes: 6 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run test
npm run lint:standard -- --fix
npm run lint:ts-standard -- --fix
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
.editorconfig
.github
.prettierignore
.commitlintrc.json
.releaserc.yml
.husky/
CONTRIBUTING.md
eslintrc.json
coverage/
node_modules/
src/
Expand Down
44 changes: 44 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
branches:
- master
plugins:
- - "@semantic-release/commit-analyzer"
- releaseRules:
- breaking: true
release: major
- revert: true
release: patch
- type: feat
release: minor
- type: fix
release: patch
- type: perf
release: patch
- type: docs
release: patch
- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits
presetConfig:
types:
- type: build
section: Build system / dependencies
- type: ci
section: CI
- type: docs
section: Documentation
- type: feat
section: Features
- type: fix
section: Bug fixes
- type: perf
section: Performance
- type: refactor
section: Refactoring
- type: text
section: Testing
- "@semantic-release/changelog"
- "@semantic-release/github"
- "@semantic-release/npm"
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
- package.json
Comment on lines +42 to +44
Copy link
Member

Choose a reason for hiding this comment

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

That might be best to not have any assets.
The changelog will be published with the GitHub Release, what do you think? 😄

Copy link
Author

@Maytha8 Maytha8 Jun 12, 2023

Choose a reason for hiding this comment

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

CHANGELOG.md
This file already exists in this repo, so I might as well setup semantic-release to update it. 😃
@semantic-release/changelog will update the changelog automatically for us.

package.json
@semantic-release/npm updates the package.json version, so might as well commit that.

Copy link
Author

Choose a reason for hiding this comment

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

See #289 (comment) regarding package.json.

2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Changelog

## 13.0.0 - Pending

## 12.0.2

- **Fix:** Allow absolute `--project` path [(#269)](https://github.com/standard/ts-standard/pull/269).
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing

I welcome all pull requests. Please make sure you add appropriate test cases for any features
added.

> New to contributing? Check out [this How to Contribute guide](https://opensource.guide/how-to-contribute/).

## Setup

It is assumed that you already have a copy of this project.

To setup your development environment, run the following command inside the project folder:

```sh
npm install
```

This will install the required tools, dependencies, and git hooks.

## Committing

We follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and this is enforced by commitlint. Commits with incorrectly formatted messages will result in an error from git and the commit to be rejected.

When committing, tests and linters are also run. If any of them fail, git will throw an error and the commit will be rejected.

> Note that linters are run with the `--fix` argument, so any fixable issues will be fixed automatically.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ You can add an `ignore` property to your `package.json` `ts-standard` configurat
```json
{
"ts-standard": {
"ignore": [
"dist",
"src/**/*.js"
]
"ignore": ["dist", "src/**/*.js"]
}
}
```
Expand Down Expand Up @@ -119,10 +116,6 @@ Special thanks to [`standard`](https://github.com/standard/standard) for inspira
to [`eslint-config-standard-with-typescript`](https://github.com/standard/eslint-config-standard-with-typescript) for
creating a typescript specific standard.

## 📋 Contributing Guide
## 📋 Contributing

I welcome all pull requests. Please make sure you add appropriate test cases for any features
added. Before opening a PR please make sure to run the following scripts:

- `npm run lint:standard` checks for code errors and format according to [standard](https://github.com/standard/standard)
- `npm test` make sure all tests pass
See [CONTRIBUTING.md](./CONTRIBUTING.md)
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"author": "Todd Bluhm",
"license": "MIT",
"homepage": "https://github.com/standard/ts-standard",
"repository": {
"type": "git",
"url": "https://github.com/standard/ts-standard.git"
},
"keywords": [
"TypeScript Standard Style",
"check",
Expand Down Expand Up @@ -47,9 +51,10 @@
]
},
"scripts": {
"prepare": "husky install",
"lint:standard": "standard",
"lint:ts-standard": "node cli.js",
"lint:commit": "commitlint",
"lint:commit": "commitlint --from \"7b4219a67b4fe94b1a1487b7d545d0cc7742f770\"",
"test": "tape test/*.js"
},
"peerDependencies": {
Expand All @@ -72,9 +77,18 @@
"devDependencies": {
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/npm": "^10.0.3",
"@types/minimist": "^1.2.2",
"@types/node": "^18.0.6",
"husky": "^8.0.3",
"semantic-release": "^21.0.2",
"standard": "^17.0.0",
"tape": "^5.5.3"
},
"publishConfig": {
"provenance": true
}
}