Skip to content

Commit

Permalink
👷 Add CI pipeline for package publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed Dec 21, 2023
1 parent 3bdb27b commit efd3af5
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
max_line_length = 100
trim_trailing_whitespace = true
69 changes: 69 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build and publish npm package

on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:

jobs:
build:
name: Create build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm

- name: Install dependencies
run: npm ci

- name: Build library
run: |
npm run build
- name: Store build artifact
uses: actions/upload-artifact@v3
with:
name: build
path: build/
retention-days: 1

publish:
name: Publish the NPM package
runs-on: ubuntu-latest
needs:
- build

# do not publish in forks or non-tag pushes
if: startsWith(github.ref, 'refs/tags/') && github.repository_owner == 'open-formulieren'

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: npm
registry-url: 'https://registry.npmjs.org'
scope: '@open-formulieren'

- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build
path: build/

- name: Publish package to NPM
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
npm publish --access public --new-version=$VERSION
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 comments on commit efd3af5

Please sign in to comment.