semantic-version/.github/workflows/ci.yml
Paul Hatcherian 7bf8143b3b
Some checks failed
CI / Build and Test (push) Has been cancelled
CI / Create Version Tag (push) Has been cancelled
CI / Publish Release (push) Has been cancelled
ci: update release
2026-01-19 08:31:08 -06:00

160 lines
4 KiB
YAML

name: CI
on:
pull_request:
push:
branches:
- master
- "feature/*"
tags:
- "v*"
jobs:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Format check
run: npm run format-check
- name: Test
run: npm test
- name: Package
run: npm run package
- name: Run Action
uses: ./
id: run
with:
debug: true
- name: Print version
run: echo "Version ${{ steps.run.outputs.version }}"
env:
DEBUG_OUTPUT: ${{ steps.run.outputs.debug_output }}
create-tag:
name: Create Version Tag
needs: build
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
filter: blob:none
- name: Get version
uses: ./
id: version
- name: Check if tag exists
id: check
run: |
if git rev-parse "v${{ steps.version.outputs.version }}" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: steps.check.outputs.exists == 'false'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}"
git push origin "v${{ steps.version.outputs.version }}"
release:
name: Publish Release
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Package
run: npm run package
- name: Extract version from tag
id: tag
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
- name: Update package.json version
run: npm version ${{ steps.tag.outputs.version }} --no-git-tag-version
- name: Publish to npm
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Update major version tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -fa v${{ steps.tag.outputs.major }} -m "Update v${{ steps.tag.outputs.major }} to ${{ steps.tag.outputs.version }}"
git push origin v${{ steps.tag.outputs.major }} --force
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
generate_release_notes: true
body: |
## Installation
### GitHub Action
```yaml
- uses: paulhatch/semantic-version@v${{ steps.tag.outputs.major }}
```
### CLI
```bash
npm install -g @semanticversion/cli
```