chore(ci): Create GitHub release on new tag #154
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '*' | |
pull_request: | |
branches: | |
- main | |
jobs: | |
job_lint: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
cache: "npm" | |
cache-dependency-path: "./package-lock.json" | |
- name: Install dependencies | |
run: npm ci | |
- name: Lint code | |
run: npm run lint | |
job_ci: | |
strategy: | |
matrix: | |
os: | |
- name: Ubuntu | |
machine: ubuntu-latest | |
- name: Window | |
machine: windows-latest | |
- name: MacOS | |
machine: macos-latest | |
node-version: | |
- 18.x | |
- 20.x | |
- 21.x | |
- 22.x | |
name: Test and Build (${{ matrix.os.name }}, NodeJS v${{ matrix.node-version }}) | |
runs-on: ${{ matrix.os.machine }} | |
needs: job_lint | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: "npm" | |
cache-dependency-path: "./package-lock.json" | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
- name: Build | |
run: npm run build | |
job_upload_coverage: | |
name: Upload Coverage | |
runs-on: ubuntu-latest | |
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' }} | |
needs: job_ci | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
cache: "npm" | |
cache-dependency-path: "./package-lock.json" | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
env: | |
CI: true | |
- name: Upload coverage | |
uses: codecov/codecov-action@v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
file: ./coverage/coverage-final.json | |
job_create_release: | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name,'v') }} | |
needs: job_ci | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Create Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
generate_release_notes: true | |
job_publish_to_npm: | |
name: Publish to npm registry | |
runs-on: ubuntu-latest | |
if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name,'v') }} | |
needs: job_ci | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
registry-url: https://registry.npmjs.org/ | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Publish package | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
job_publish_to_gpr: | |
name: Publish to GitHub Packages | |
runs-on: ubuntu-latest | |
if: ${{ github.ref_type == 'tag' && startsWith(github.ref_name,'v') }} | |
needs: job_ci | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
registry-url: https://npm.pkg.github.com/ | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
run: npm run build | |
- name: Publish package | |
run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |