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