Skip to content

chore: add prepare hook so git: consumers get a built dist #100

chore: add prepare hook so git: consumers get a built dist

chore: add prepare hook so git: consumers get a built dist #100

Workflow file for this run

name: Release sql-storage-adapter
on:
push:
branches:
- master
paths:
- '.github/workflows/release.yml'
- 'package.json'
- 'src/**'
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm install
- name: Run tests
run: npx vitest run
continue-on-error: false
- name: Build package
run: npm run build
- name: Read package version
id: pkg
shell: bash
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if version is already published
id: npm_check
env:
VERSION: ${{ steps.pkg.outputs.version }}
run: |
CURRENT=$(npm view @framers/sql-storage-adapter version 2>/dev/null || echo "0.0.0")
if [ "$CURRENT" = "$VERSION" ]; then
echo "published=true" >> "$GITHUB_OUTPUT"
else
echo "published=false" >> "$GITHUB_OUTPUT"
fi
- name: Publish to npm
if: steps.npm_check.outputs.published == 'false'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Check if GitHub release already exists
id: release_check
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view "v${{ steps.pkg.outputs.version }}" &>/dev/null; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Extract release notes from CHANGELOG
id: changelog
if: steps.release_check.outputs.exists == 'false'
run: |
VERSION=${{ steps.pkg.outputs.version }}
NOTES=$(awk "/^## \[$VERSION\]/{flag=1; next} /^## \[/{flag=0} flag" CHANGELOG.md)
if [ -z "$NOTES" ]; then
NOTES="Release v$VERSION"
fi
echo "notes<<EOF" >> "$GITHUB_OUTPUT"
echo "$NOTES" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Create GitHub release
if: steps.release_check.outputs.exists == 'false'
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: v${{ steps.pkg.outputs.version }}
name: sql-storage-adapter v${{ steps.pkg.outputs.version }}
body: ${{ steps.changelog.outputs.notes }}
allowUpdates: true