Skip to content

Commit 742573c

Browse files
committed
chore: 🤖 Add provenance build
1 parent 02a697c commit 742573c

5 files changed

Lines changed: 675 additions & 1220 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
name: Deploy
11+
runs-on: ubuntu-latest
12+
permissions:
13+
id-token: write
14+
contents: write
15+
16+
steps:
17+
- name: Clone repository
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
token: ${{ secrets.GITHUB_TOKEN }}
22+
23+
- name: Install Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: lts/*
27+
28+
- name: Install pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: 10.28.1
32+
33+
- name: Install dependencies
34+
run: pnpm install
35+
36+
- name: Build and test
37+
run: |
38+
pnpm run build
39+
pnpm run coverage
40+
41+
- name: Upload coverage reports to Codecov
42+
uses: codecov/codecov-action@v4
43+
with:
44+
token: ${{ secrets.CODECOV_TOKEN }}
45+
fail_ci_if_error: false
46+
47+
- name: Prepublish
48+
run: pnpm run prepublishOnly
49+
50+
- name: Verify NPM token
51+
run: |
52+
npm config set //registry.npmjs.org/:_authToken=${NPM_TOKEN}
53+
echo "Verifying npm auth..."
54+
npm whoami --registry=https://registry.npmjs.org/
55+
env:
56+
NPM_TOKEN: ${{ secrets.JSON_WEB3_NPM_TOKEN }}
57+
58+
- name: NPM Publish
59+
uses: JS-DevTools/npm-publish@v3
60+
with:
61+
token: ${{ secrets.JSON_WEB3_NPM_TOKEN }}
62+
provenance: true
63+
access: public
64+
65+
- name: Configure Git user identity
66+
run: |
67+
git config --global user.name "github-actions[bot]"
68+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
69+
git config --global commit.gpgSign false
70+
git config --global tag.gpgSign false
71+
72+
- name: Create Git Tag (with overwrite)
73+
run: |
74+
git reset --hard HEAD
75+
VERSION=$(node -p "require('./package.json').version")
76+
TAG_NAME="v$VERSION"
77+
echo "VERSION=$VERSION" >> $GITHUB_ENV
78+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
79+
80+
if git ls-remote --tags origin | grep -q "refs/tags/$TAG_NAME$"; then
81+
git push --delete origin "$TAG_NAME" || echo "Failed to delete remote tag"
82+
git tag -d "$TAG_NAME" 2>/dev/null || echo "Local tag does not exist"
83+
fi
84+
85+
git tag "$TAG_NAME" -m "Release version $VERSION"
86+
git push origin "$TAG_NAME"
87+
echo "NEED_RELEASE=true" >> $GITHUB_ENV
88+
89+
- name: Get Previous Git Tag
90+
run: |
91+
PREV_TAG=$(git tag --sort=-creatordate | grep -v "$TAG_NAME" | head -n 1)
92+
echo "Previous tag: $PREV_TAG"
93+
echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV
94+
95+
- name: Generate Changelog and Compare Link
96+
run: |
97+
echo "Generating changelog from commits between $PREV_TAG and $TAG_NAME"
98+
echo "### Changes Since $PREV_TAG" > CHANGELOG.md
99+
git log "$PREV_TAG..HEAD" --pretty=format:"%s" --no-merges | sort | uniq | sed 's/^/- /' >> CHANGELOG.md
100+
101+
COMPARE_URL="https://github.com/${{ github.repository }}/compare/$PREV_TAG...$TAG_NAME"
102+
echo "" >> CHANGELOG.md
103+
echo "**Full Changelog**: $COMPARE_URL" >> CHANGELOG.md
104+
105+
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
106+
cat CHANGELOG.md >> $GITHUB_ENV
107+
echo "EOF" >> $GITHUB_ENV
108+
109+
- name: Delete existing GitHub Release (if exists)
110+
run: |
111+
RELEASE_ID=$(gh release view "${{ env.TAG_NAME }}" --json id --jq '.id' 2>/dev/null || echo "")
112+
if [ -n "$RELEASE_ID" ]; then
113+
gh release delete "${{ env.TAG_NAME }}" --yes || echo "Failed to delete release"
114+
fi
115+
env:
116+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
118+
- name: Create GitHub Release
119+
if: env.NEED_RELEASE == 'true'
120+
uses: softprops/action-gh-release@v2
121+
with:
122+
tag_name: ${{ env.TAG_NAME }}
123+
name: Release ${{ env.TAG_NAME }}
124+
body: |
125+
## Release ${{ env.VERSION }}
126+
${{ env.CHANGELOG }}
127+
files: |
128+
dist/*
129+
draft: false
130+
prerelease: false
131+
env:
132+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,20 @@
3636
],
3737
"scripts": {
3838
"build": "tsup",
39+
"postinstall": "pnpm run ncu",
3940
"lint": "prettier . --write",
40-
"prepublishOnly": "pnpm run build",
41+
"ncu": "pnpm npm-check-updates -u --deep",
42+
"prepublishOnly": "pnpm run build && vite-node scripts/clean.ts",
4143
"publishOnly": "pnpm run build",
4244
"test": "vitest run --coverage",
4345
"test:watch": "vitest"
4446
},
4547
"devDependencies": {
46-
"@types/node": "^25.0.9",
48+
"@types/node": "^25.0.10",
4749
"@vitest/coverage-v8": "^4.0.17",
48-
"prettier": "^3.8.0",
50+
"fs-extra": "^11.3.3",
51+
"npm-check-updates": "^19.3.1",
52+
"prettier": "^3.8.1",
4953
"prettier-plugin-lint-md": "^1.0.1",
5054
"prettier-plugin-organize-imports": "^4.3.0",
5155
"prettier-plugin-sort-json": "^4.2.0",
@@ -58,5 +62,10 @@
5862
"packageManager": "pnpm@10.28.1",
5963
"engines": {
6064
"node": ">=18"
65+
},
66+
"publishConfig": {
67+
"access": "public",
68+
"provenance": true,
69+
"registry": "https://registry.npmjs.org/"
6170
}
6271
}

0 commit comments

Comments
 (0)