Skip to content

Commit eebeecf

Browse files
committed
configured with semver-workflow
1 parent e3b8f17 commit eebeecf

File tree

9 files changed

+2945
-70
lines changed

9 files changed

+2945
-70
lines changed

Diff for: .github/workflows/main.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
---
2+
name: CI & Release
3+
4+
# Workflow name based on selected inputs. Fallback to default Github naming when expression evaluates to empty string
5+
run-name: >-
6+
${{
7+
inputs.release && inputs.test && format('Build {0} ➤ Test ➤ Publish to NPM', github.ref_name) ||
8+
inputs.release && !inputs.test && format('Build {0} ➤ Skip Tests ➤ Publish to NPM', github.ref_name) ||
9+
github.event_name == 'workflow_dispatch' && inputs.test && format('Build {0} ➤ Test', github.ref_name) ||
10+
github.event_name == 'workflow_dispatch' && !inputs.test && format('Build {0} ➤ Skip Tests', github.ref_name) ||
11+
''
12+
}}
13+
14+
on:
15+
# Build on pushes branches that have a PR (including drafts)
16+
pull_request:
17+
# Build on commits pushed to branches without a PR if it's in the allowlist
18+
push:
19+
branches: [master, legacy-v2]
20+
# https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow
21+
workflow_dispatch:
22+
inputs:
23+
test:
24+
description: Run tests
25+
required: true
26+
default: true
27+
type: boolean
28+
release:
29+
description: Release new version
30+
required: true
31+
default: false
32+
type: boolean
33+
34+
concurrency:
35+
# On PRs builds will cancel if new pushes happen before the CI completes, as it defines `github.head_ref` and gives it the name of the branch the PR wants to merge into
36+
# Otherwise `github.run_id` ensures that you can quickly merge a queue of PRs without causing tests to auto cancel on any of the commits pushed to main.
37+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
38+
cancel-in-progress: true
39+
40+
jobs:
41+
build:
42+
runs-on: ubuntu-latest
43+
name: Lint & Build
44+
steps:
45+
- uses: actions/checkout@v3
46+
- uses: actions/setup-node@v3
47+
with:
48+
cache: npm
49+
node-version: lts/*
50+
- run: npm ci
51+
# Linting can be skipped
52+
- run: npm run lint --if-present
53+
if: github.event.inputs.test != 'false'
54+
# But not the build script, as semantic-release will crash if this command fails so it makes sense to test it early
55+
- run: npm run prepublishOnly --if-present
56+
57+
test:
58+
needs: build
59+
# The test matrix can be skipped, in case a new release needs to be fast-tracked and tests are already passing on main
60+
if: github.event.inputs.test != 'false'
61+
runs-on: ${{ matrix.os }}
62+
name: Node.js ${{ matrix.node }} / ${{ matrix.os }}
63+
strategy:
64+
# A test failing on windows doesn't mean it'll fail on macos. It's useful to let all tests run to its completion to get the full picture
65+
fail-fast: false
66+
matrix:
67+
# Run the testing suite on each major OS with the latest LTS release of Node.js
68+
os: [macos-latest, ubuntu-latest, windows-latest]
69+
node: [lts/*]
70+
# It makes sense to also test the oldest, and latest, versions of Node.js, on ubuntu-only since it's the fastest CI runner
71+
include:
72+
- os: ubuntu-latest
73+
# Test the oldest LTS release of Node that's still receiving bugfixes and security patches, versions older than that have reached End-of-Life
74+
node: lts/-2
75+
- os: ubuntu-latest
76+
# Test the actively developed version that will become the latest LTS release next October
77+
node: current
78+
steps:
79+
# It's only necessary to do this for windows, as mac and ubuntu are sane OS's that already use LF
80+
- name: Set git to use LF
81+
if: matrix.os == 'windows-latest'
82+
run: |
83+
git config --global core.autocrlf false
84+
git config --global core.eol lf
85+
- uses: actions/checkout@v3
86+
- uses: actions/setup-node@v3
87+
with:
88+
cache: npm
89+
node-version: ${{ matrix.node }}
90+
- run: npm i
91+
- run: npm test --if-present
92+
93+
release:
94+
needs: [build, test]
95+
# only run if opt-in during workflow_dispatch
96+
if: always() && github.event.inputs.release == 'true' && needs.build.result != 'failure' && needs.test.result != 'failure' && needs.test.result != 'cancelled'
97+
runs-on: ubuntu-latest
98+
name: Semantic release
99+
steps:
100+
- uses: actions/checkout@v3
101+
with:
102+
# Need to fetch entire commit history to
103+
# analyze every commit since last release
104+
fetch-depth: 0
105+
- uses: actions/setup-node@v3
106+
with:
107+
cache: npm
108+
node-version: lts/*
109+
- run: npm ci
110+
# Branches that will release new versions are defined in .releaserc.json
111+
# @TODO remove --dry-run after verifying everything is good to go
112+
- run: npx semantic-release --dry-run
113+
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
114+
# e.g. git tags were pushed but it exited before `npm publish`
115+
if: always()
116+
env:
117+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
119+
# Re-run semantic release with rich logs if it failed to publish for easier debugging
120+
- run: npx semantic-release --dry-run --debug
121+
if: failure()
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

Diff for: .husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit ""

Diff for: .husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx lint-staged

Diff for: .releaserc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@sanity/semantic-release-preset",
3+
"branches": [
4+
"master",
5+
{ "name": "legacy-v2", "channel": "legacy-v2", "range": "0.x.x" }
6+
]
7+
}

Diff for: README.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sanity-plugin-netlify-deploy-status-badge
22

3+
> This is a Sanity Studio v3 plugin. For the v2 version, please refer to the [legacy-v2](https://github.com/dorelljames/sanity-plugin-netlify-deploy-status-badge/tree/legacy-v2) branch.
4+
35
Display Netlify's status badge in Sanity Studio and your site's recent deploys. Plus, trigger a new build if you want to!
46

57
![](https://raw.githubusercontent.com/dorelljames/sanity-plugin-netlify-deploy-status-badge/master/src/assets/preview-full.png)
@@ -58,13 +60,13 @@ export default defineConfig({
5860

5961
### Authentication
6062

61-
By default, accessing deploy logs via the API does not require authentication. However, if you set your site's deploy logs to private, the plugin need to be setup with OAuth for you to authenticate in order to pull in data. Being authenticated also enables you to trigger a new build on your site.
63+
By default, accessing deploy logs via the API does not require authentication. However, if you set your site's deploy logs to private, the plugin needs to be setup with OAuth for you to authenticate and pull in data to show site deploys. Being authenticated also enables you to trigger a new build on your site.
6264

6365
Authentication can be done in two ways: OAuth or personal tokens. Support for the latter will be implemented later as I'll need to spend more time integrating it with [sanity-studio-secrets](https://github.com/sanity-io/sanity-studio-secrets).
6466

6567
#### Which one to choose?
6668

67-
With personal tokens, anyone who has access to your Sanity Studio can do administrative actions on your behalf such as trigger a new build, etc. while with OAuth, anyone who has access to your Sanity Studio will still need to login and authorize with their Netlify account to do the former actions mentioned.
69+
It might not be relevant as of now as personal tokens has been not been implemented but with personal tokens, anyone who has access to your Sanity Studio can do administrative actions on your behalf such as trigger a new build, etc. while with OAuth, anyone who has access to your Sanity Studio will still need to login and authorize with their Netlify account to do the former actions mentioned.
6870

6971
#### How to configure?
7072

@@ -94,3 +96,22 @@ netlifyDeployStatusBadge({
9496

9597
MIT © Dorell James
9698
See LICENSE
99+
100+
## License
101+
102+
[MIT](LICENSE) © Dorell James
103+
104+
## Develop & test
105+
106+
This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
107+
with default configuration for build & watch scripts.
108+
109+
See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
110+
on how to run this plugin with hotreload in the studio.
111+
112+
### Release new version
113+
114+
Run ["CI & Release" workflow](https://github.com/dorelljames/sanity-plugin-netlify-deploy-status-badge/actions/workflows/main.yml).
115+
Make sure to select the main branch and check "Release new version".
116+
117+
Semantic release will only release on configured branches, so it is safe to run release on any branch.

Diff for: commitlint.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
}

Diff for: lint-staged.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
'**/*.{js,jsx}': ['eslint'],
3+
'**/*.{ts,tsx}': ['eslint', () => 'tsc --build'],
4+
}

Diff for: package.json

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sanity-plugin-netlify-deploy-status-badge",
3-
"version": "1.0.0",
3+
"version": "3.0.0",
44
"description": "Display Netlify's status badge in Sanity Studio and your site's recent deploys. Plus, trigger a new build if you want to!",
55
"keywords": [
66
"sanity",
@@ -43,7 +43,8 @@
4343
"clean": "rimraf dist",
4444
"format": "prettier --write --cache --ignore-unknown .",
4545
"link-watch": "plugin-kit link-watch",
46-
"lint": "eslint ."
46+
"lint": "eslint .",
47+
"prepare": "husky install"
4748
},
4849
"dependencies": {
4950
"@sanity/icons": "^2.4.1",
@@ -55,9 +56,16 @@
5556
"zod": "^3.21.4"
5657
},
5758
"devDependencies": {
59+
"@commitlint/cli": "^17.6.7",
60+
"@commitlint/config-conventional": "^17.6.7",
5861
"@sanity/eslint-config-no-v2-imports": "^0.0.1-studio-v3.3",
5962
"@sanity/pkg-utils": "^2.3.9",
6063
"@sanity/plugin-kit": "^3.1.7",
64+
"@sanity/semantic-release-preset": "^4.1.2",
65+
"@semantic-release/commit-analyzer": "^10.0.1",
66+
"@semantic-release/github": "^9.0.4",
67+
"@semantic-release/npm": "^10.0.4",
68+
"@semantic-release/release-notes-generator": "^11.0.4",
6169
"@types/react": "^18.2.17",
6270
"@typescript-eslint/eslint-plugin": "^6.2.0",
6371
"@typescript-eslint/parser": "^6.2.0",
@@ -67,6 +75,8 @@
6775
"eslint-plugin-prettier": "^5.0.0",
6876
"eslint-plugin-react": "^7.33.1",
6977
"eslint-plugin-react-hooks": "^4.6.0",
78+
"husky": "^8.0.3",
79+
"lint-staged": "^13.2.3",
7080
"npm-run-all": "^4.1.5",
7181
"prettier": "^3.0.0",
7282
"prettier-plugin-packagejson": "^2.4.5",

0 commit comments

Comments
 (0)