pateketrueke / yrv

Your routing vibes! (for Svelte)
https://svelte.dev/repl/0f07c6134b16432591a9a3a0095a80de
161 stars 9 forks source link

[Ops] Auto Publish NPM Package when push to master #67

Closed jhechtf closed 3 years ago

jhechtf commented 3 years ago

It would help speed things up if we properly setup actions on the project so that any merges into master are linting, testing, and (if those are passing) building + publishing to NPM.

I've done something similar with Gitlab Pipelines, and Actions appears to have a pre-set thing that we could use, but it would require some setup on your part.

pateketrueke commented 3 years ago

Sounds good, if we can setup that for any branch It'll be fine. Please let me know what do I need to do to help you!

jhechtf commented 3 years ago

You'll need to grab an NPM token with write access from your account (or whatever account owns the YRV package there); I'll setup a verdaccio server to test. Might also be a good time to think about using something like standard-version for releases. I'll see what I can whip up here in a second.

jhechtf commented 3 years ago
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
  release:
    types: [created]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
      - run: npm ci
      - run: npm run lint

  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: 12
          registry-url: https://registry.npmjs.org/
      - run: npm ci
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

seems to be the start of what we need. hard to test as i don't want to publish a package to npmjs unnecessarily.

pateketrueke commented 3 years ago

Good enough, I believe we can prove it by using an invalid NPM_TOKEN, thank you!

jhechtf commented 3 years ago

In double checking I realized this pipeline wouldn't exactly do what we need.

We need to

  1. make sure we are only running the publish on tags
  2. this means we need to add in automation for our release script. It will appropriately bump the version so that we don't get into conflicts with NPM versions.
  3. This means needing an access token and likely utilizing https://github.com/marketplace/actions/standard-release-notes or similar actions (we could always hand-code it; I've done this on Gitlab CI so it's not foreign).