-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (63 loc) · 2.08 KB
/
publish.yml
File metadata and controls
73 lines (63 loc) · 2.08 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
name: Build and Publish Package
on:
push:
branches: [ main ]
tags: [ 'v*' ]
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.28.0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
scope: '@ghosttypes'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm build
- name: Set version
id: set_version
run: |
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# If this is a tag push, use the tag version
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
else
# If this is not a tag push, use the current version and add timestamp
CURRENT_VERSION=$(node -p "require('./package.json').version")
TIMESTAMP=$(date +%Y%m%d%H%M%S)
VERSION="${CURRENT_VERSION}-${TIMESTAMP}"
fi
echo "Using version: $VERSION"
CURRENT_VERSION=$(node -p "require('./package.json').version")
if [[ "$CURRENT_VERSION" != "$VERSION" ]]; then
pnpm version $VERSION --no-git-tag-version
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Publish to GitHub Packages
run: pnpm publish --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report error details if failed
if: failure()
run: |
echo "::error::Package publish failed. Please check authentication and configuration."
echo "::group::PNPM Config"
pnpm config list
echo "::endgroup::"
echo "::group::Repository Info"
echo "Owner: ${{ github.repository_owner }}"
echo "Repo: ${{ github.repository }}"
echo "::endgroup::"