Skip to content

Commit c9bdb8e

Browse files
authored
feat: Deploy docs only when package is published with a new tag (#98)
1 parent 90e9817 commit c9bdb8e

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ env:
99
DEBUG: napi:*
1010
APP_NAME: es-git
1111
MACOSX_DEPLOYMENT_TARGET: '10.13'
12+
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
13+
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
1214
jobs:
1315
build:
1416
strategy:
@@ -119,8 +121,12 @@ jobs:
119121
deployments: write
120122
needs:
121123
- build
124+
outputs:
125+
published: ${{ steps.check-publish.outputs.published }}
122126
steps:
123127
- uses: actions/checkout@v4
128+
- name: Fetch git tags
129+
run: git fetch origin 'refs/tags/*:refs/tags/*'
124130
- name: Setup node
125131
uses: actions/setup-node@v4
126132
with:
@@ -162,6 +168,7 @@ jobs:
162168
generate_release_notes: false
163169
token: ${{ github.token }}
164170
- name: Publish
171+
id: publish
165172
run: |
166173
set -ex
167174
npm config set provenance true
@@ -181,3 +188,40 @@ jobs:
181188
env:
182189
GITHUB_TOKEN: ${{ github.token }}
183190
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
191+
- name: Check if publish happened and is latest
192+
id: check-publish
193+
run: |
194+
if [[ "$GITHUB_REF_TYPE" = "tag" ]]; then
195+
# Check if this is the latest version
196+
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
197+
if [[ "$GITHUB_REF_NAME" == "$LATEST_TAG" ]]; then
198+
echo "published=true" >> $GITHUB_OUTPUT
199+
else
200+
echo "published=false" >> $GITHUB_OUTPUT
201+
fi
202+
else
203+
echo "published=false" >> $GITHUB_OUTPUT
204+
fi
205+
publish-documentation-site:
206+
runs-on: ubuntu-latest
207+
needs:
208+
- release
209+
if: needs.release.outputs.published == 'true'
210+
steps:
211+
- uses: actions/checkout@v4
212+
- name: Setup node
213+
uses: actions/setup-node@v4
214+
with:
215+
node-version-file: ".node-version"
216+
check-latest: true
217+
cache: yarn
218+
- name: Install dependencies
219+
run: yarn install
220+
- name: Install Vercel CLI
221+
run: yarn global add vercel
222+
- name: Pull Vercel Environment Information
223+
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
224+
- name: Build Project Artifacts
225+
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
226+
- name: Deploy Project Artifacts to Vercel
227+
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

vercel.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"git": {
3+
"deploymentEnabled": {
4+
"main": false
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)