Skip to content

Commit 9d5fb92

Browse files
committed
fix: update publish workflow
1 parent 576fcc8 commit 9d5fb92

File tree

1 file changed

+48
-6
lines changed

1 file changed

+48
-6
lines changed

.github/workflows/publish.yml

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,35 @@ jobs:
5454
name: build
5555
path: build
5656

57-
- uses: actions/setup-node@v6.0.0
57+
- name: Check remote
58+
id: check_remote
59+
run: |
60+
cd build || exit 1
61+
tar -xzf pdown-*.tgz
62+
VERSION=${GITHUB_REF_NAME#v}
63+
if npm add "pdown@${VERSION}" >/dev/null 2>&1; then
64+
echo "exists=true" > $GITHUB_OUTPUT
65+
echo "Version ${VERSION} of pdown is already published to npm. Skipping."
66+
else
67+
echo "exists=false" > $GITHUB_OUTPUT
68+
echo "Version ${VERSION} of pdown is not published yet."
69+
fi
70+
71+
- name: Setup node
72+
uses: actions/setup-node@v6.0.0
73+
if: steps.check_remote.outputs.exists == 'false'
5874
with:
5975
node-version: '*'
6076
registry-url: https://registry.npmjs.org
6177

6278
# Ensure npm 11.5.1 or later is installed to enable trusted publishing
6379
# https://docs.npmjs.com/trusted-publishers
6480
- name: Update npm
81+
if: steps.check_remote.outputs.exists == 'false'
6582
run: npm install -g npm@latest
6683

6784
- name: Publish
85+
if: steps.check_remote.outputs.exists == 'false'
6886
run: npm publish ./build/pdown-*.tgz
6987
github-packages:
7088
needs: [build]
@@ -73,22 +91,46 @@ jobs:
7391
id-token: write
7492
packages: write
7593
steps:
76-
- name: Checkout
77-
uses: actions/checkout@v4.2.2
78-
7994
- name: Download build artifact
8095
uses: actions/download-artifact@v5.0.0
8196
with:
8297
name: build
8398
path: build
8499

85-
- uses: actions/setup-node@v6.0.0
100+
- name: Check remote
101+
id: check_remote
102+
run: |
103+
cd build || exit 1
104+
tar -xzf pdown-*.tgz
105+
VERSION=${GITHUB_REF_NAME#v}
106+
if npm add "pdown@${VERSION}" --registry https://npm.pkg.github.com >/dev/null 2>&1; then
107+
echo "exists=true" > $GITHUB_OUTPUT
108+
echo "Version ${VERSION} of pdown is already published to GitHub Packages. Skipping."
109+
else
110+
echo "exists=false" > $GITHUB_OUTPUT
111+
echo "Version ${VERSION} of pdown is not published yet."
112+
fi
113+
env:
114+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
116+
- name: Setup node
117+
uses: actions/setup-node@v6.0.0
118+
if: steps.check_remote.outputs.exists == 'false'
86119
with:
87120
node-version: '*'
88121
registry-url: https://npm.pkg.github.com
89122

90123
- name: Publish
91-
run: npm publish ./build/pdown-*.tgz
124+
if: steps.check_remote.outputs.exists == 'false'
125+
run: |
126+
npm config set registry=https://npm.pkg.github.com
127+
cd build
128+
tar -xzf pdown-*.tgz
129+
cd package
130+
npm pkg delete scripts.prepack
131+
npm pkg delete scripts.postpack
132+
npm pkg set name="@${GITHUB_REPOSITORY_OWNER}/pdown"
133+
npm publish
92134
env:
93135
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94136
github-release:

0 commit comments

Comments
 (0)