diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5c7ef4d --- /dev/null +++ b/.editorconfig @@ -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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..3469bed --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }}