Skip to content

ci

ci #56

Workflow file for this run

name: ci
on:
push:
branches:
- main
tags:
- 'v*' # Tags matching v*, e.g. v1.0, v20.15.10, v0.3.1
pull_request:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Archive build # https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
run: tar -czvf lib.tar.gz ./lib
- name: Upload build
uses: actions/upload-artifact@v4
with:
name: build
path: ./lib.tar.gz
retention-days: 1
test:
needs: build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [21.x, 20.x, 18.x, 16.x, 14.x]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
lint:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Lint
run: npm run lint
publish-npm:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: ['build', 'test', 'lint']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
- name: Unarchive build
run: tar -xzf ./lib.tar.gz
- name: Publish
run: npm publish --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Create a repository secret named NPM_TOKEN containing an npm access token
publish-gpr:
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: ['build', 'test', 'lint']
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
registry-url: https://npm.pkg.github.com/
always-auth: true
scope: '@jessety'
- name: Install dependencies
run: npm install --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GPR_TOKEN }}
- name: Download build
uses: actions/download-artifact@v4
with:
name: build
- name: Unarchive build
run: tar -xzf ./lib.tar.gz
- name: Scope Package
run: echo $(cat package.json | jq '.name= "@jessety/\(.name)"') > package.json
- name: Publish
run: npm publish --ignore-scripts --registry=https://npm.pkg.github.com/@jessety
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by GitHub, and requires no setup
release:
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: ['publish-npm', 'publish-gpr']
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Git history won't be fetched without this option
- name: Generate release notes # To change the release notes format, edit RELEASE.md.hbs
id: notes
run: |
npx [email protected] --template RELEASE.md.hbs --output RELEASE.md --commit-limit false
NOTES=$(cat RELEASE.md)
NOTES="${NOTES//'%'/'%25'}"
NOTES="${NOTES//$'\n'/'%0A'}"
echo "::set-output name=notes::$NOTES"
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
body: ${{ steps.notes.outputs.notes }}
draft: false
prerelease: false