Skip to content

Commit 7b689e7

Browse files
committed
Add Makefile
1 parent 176b7b3 commit 7b689e7

4 files changed

Lines changed: 215 additions & 209 deletions

File tree

.github/workflows/release.yaml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
branches:
6-
- release
6+
- release*
77

88
permissions:
99
contents: write
@@ -14,37 +14,17 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
1719
- uses: pnpm/action-setup@v4
1820
with:
1921
version: latest
2022
- uses: actions/setup-node@v4
2123
with:
2224
node-version-file: package.json
2325
cache: pnpm
24-
- run: pnpm install
25-
- run: |
26-
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
27-
git config --global user.email "actions@users.noreply.github.com"
28-
git config --global user.name "GitHub Actions"
29-
RELEASE_DESCRIPTION=$(awk '/## \[Unreleased\]/{flag=1; next} /## \[/{flag=0} flag' ./CHANGELOG.md | sed '/^[[:space:]]*$/d')
30-
if echo "$RELEASE_DESCRIPTION" | grep -q '### Changed'; then
31-
pnpm version major
32-
elif echo "$RELEASE_DESCRIPTION" | grep -q '### Added'; then
33-
pnpm version minor
34-
elif echo "$RELEASE_DESCRIPTION" | grep -q '### Fixed'; then
35-
pnpm version patch
36-
fi
37-
echo "TAG_NAME=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
38-
echo "RELEASE_DESCRIPTION<<EOF" >> $GITHUB_ENV
39-
echo "$RELEASE_DESCRIPTION" >> $GITHUB_ENV
40-
echo "EOF" >> $GITHUB_ENV
41-
- uses: softprops/action-gh-release@v2
26+
- run: make setup
27+
- run: make release
4228
env:
29+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4330
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44-
with:
45-
tag_name: ${{ env.TAG_NAME }}
46-
name: "Release ${{ env.TAG_NAME }}"
47-
body: ${{ env.RELEASE_DESCRIPTION }}
48-
draft: false
49-
prerelease: false
50-
- run: git fetch --all && git switch main && git rebase release && git push origin main

Makefile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
setup: ## 🛠️ Setup the project environment
2+
$(call remove_wrong_installation)
3+
$(call install_pnpm)
4+
$(call update_pnpm)
5+
$(call install_dependencies)
6+
$(call setup_githooks)
7+
.PHONY: setup
8+
9+
lint: ## 🧬 Check code by eslint
10+
@node --run eslint
11+
.PHONY: lint
12+
13+
test: ## 🧪 Run tests
14+
@node --test
15+
.PHONY: test
16+
17+
release: lint test ## 🚀 Release a new version
18+
@pnpm dlx @firefoxic/release-it
19+
.PHONY: release
20+
21+
help: ## 🧾 Print this message
22+
@printf "\n\t📜 $(ANSI_BOLD)Available targets:$(ANSI_RESET)\n\n"
23+
@grep -E '^[a-zA-Z0-9_-]+:.*?## ' $(MAKEFILE_LIST) \
24+
| awk -F ':|##' '\
25+
BEGIN { \
26+
ANSI_BOLD_CYAN = "$(ANSI_BOLD_CYAN)"; \
27+
ANSI_RESET = "$(ANSI_RESET)"; \
28+
} \
29+
{ \
30+
targets[NR]=$$1; descs[NR]=$$3; \
31+
if (length($$1) > max) max = length($$1); \
32+
} \
33+
END { \
34+
for (i = 1; i <= NR; i++) { \
35+
printf "\t%s%" max "s%s —%s\n", ANSI_BOLD_CYAN, targets[i], ANSI_RESET, descs[i]; \
36+
} \
37+
printf "\n" \
38+
}'
39+
.PHONY: help
40+
41+
REQUIRED_PNPM := ^10.17.0
42+
43+
ANSI_RESET := \033[0m
44+
ANSI_BOLD := \033[1m
45+
ANSI_BOLD_CYAN := \033[1;36m
46+
47+
define remove_wrong_installation
48+
@test ! -f package-lock.json -o -f yarn.lock || rm -rf package-lock.json yarn.lock node_modules
49+
endef
50+
51+
define install_pnpm
52+
@command -v pnpm >/dev/null 2>&1 || curl -fsSL https://get.pnpm.io/install.sh | sh -
53+
endef
54+
55+
define update_pnpm
56+
@pnpm dlx semver -- $$(pnpm -v) -r $(REQUIRED_PNPM) >/dev/null 2>&1 || pnpm self-update
57+
endef
58+
59+
define install_dependencies
60+
@test -d node_modules || pnpm install
61+
endef
62+
63+
define setup_githooks
64+
@git config --local core.hooksPath .githooks
65+
endef

package.json

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,18 @@
2828
},
2929
"dependencies": {
3030
"ico-endec": "^0.1.6",
31-
"meow": "^13.2.0",
32-
"sharp": "^0.34.3",
31+
"meow": "^14.0.0",
32+
"sharp": "^0.34.4",
3333
"svgo": "^4.0.0"
3434
},
3535
"scripts": {
36-
"prepare": "git config core.hooksPath .githooks",
37-
"lint": "eslint",
38-
"pretest": "pnpm lint",
39-
"test": "node --test",
40-
"preversion": "pnpm test",
41-
"version": "update-changelog",
42-
"postversion": "pnpm publish --provenance --access public --no-git-checks",
43-
"postpublish": "git push --follow-tags"
36+
"help": "make help",
37+
"eslint": "eslint",
38+
"test": "node --test"
4439
},
4540
"devDependencies": {
4641
"@firefoxic/eslint-config": "^5.0.0",
47-
"@firefoxic/update-changelog": "^1.0.0",
48-
"eslint": "9.35.0"
42+
"eslint": "^9.36.0"
4943
},
5044
"keywords": [
5145
"optimize",

0 commit comments

Comments
 (0)