Skip to content

8.12.1

8.12.1 #9

Workflow file for this run

name: Deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
name: Test on ${{ matrix.runtime }}
runs-on: ubuntu-latest
strategy:
matrix:
runtime: ['node', 'bun', 'deno']
node-version: [20.x]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Setup Bun
if: matrix.runtime == 'bun'
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup Deno
if: matrix.runtime == 'deno'
uses: denoland/setup-deno@v1
with:
deno-version: v2.x
- name: Install dependencies
run: npm ci
- name: Run Node.js tests
if: matrix.runtime == 'node'
run: npm test
- name: Run Bun tests
if: matrix.runtime == 'bun'
run: bun test
- name: Run Deno tests
if: matrix.runtime == 'deno'
run: deno test --allow-net --allow-env --allow-run --allow-read --allow-sys
publish:
name: Publish to npm
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
outputs:
published: ${{ steps.npm_check.outputs.exists == 'false' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Get package version
id: package_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Package version: $VERSION"
- name: Check if version exists on npm
id: npm_check
run: |
if npm view use-m@${{ steps.package_version.outputs.version }} version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Version ${{ steps.package_version.outputs.version }} already exists on npm"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Version ${{ steps.package_version.outputs.version }} does not exist on npm"
fi
- name: Publish to npm
if: steps.npm_check.outputs.exists == 'false'
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create git tag
if: steps.npm_check.outputs.exists == 'false'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git tag -a v${{ steps.package_version.outputs.version }} -m "Release v${{ steps.package_version.outputs.version }}"
git push origin v${{ steps.package_version.outputs.version }}
create-release:
name: Create GitHub Release
needs: publish
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push' && needs.publish.outputs.published == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get package version
id: package_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse v${{ steps.package_version.outputs.version }} >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Generate release notes
if: steps.check_tag.outputs.exists == 'true'
id: release_notes
run: |
VERSION=${{ steps.package_version.outputs.version }}
echo "# Release v${VERSION}" > release_notes.md
echo "" >> release_notes.md
echo "[![npm](https://img.shields.io/badge/npm-v${VERSION}-blue.svg)](https://www.npmjs.com/package/use-m/v/${VERSION})" >> release_notes.md
echo "" >> release_notes.md
echo "## What's Changed" >> release_notes.md
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
git log --pretty=format:"- %s (%h)" ${LAST_TAG}..HEAD >> release_notes.md
else
git log --pretty=format:"- %s (%h)" -10 >> release_notes.md
fi
echo "" >> release_notes.md
echo "## Installation" >> release_notes.md
echo '```bash' >> release_notes.md
echo "npm install use-m@${VERSION}" >> release_notes.md
echo '```' >> release_notes.md
- name: Create GitHub Release
if: steps.check_tag.outputs.exists == 'true'
uses: actions/create-release@v1
with:
tag_name: v${{ steps.package_version.outputs.version }}
release_name: v${{ steps.package_version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}