npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@heneise/serverless-v2.0.0

v1.1.1

Published

serverless on steroids with semantic-release, automated continuous integration and automated deployments to Google Cloud Functions.

Downloads

4

Readme

Serverless 2.0.0

serverless on steroids with semantic-release, automated continuous integration and automated deployments to Google Cloud Functions.

This repo is an example for an article on how to run Serverless functions with automated, continuous deployment and semantic versioning. You can find the full article here:

https://medium.com/heneise/serverless-v2-0-0-f5ed17fac386

Steps

Repo & Code Setup

serverless create --template google-nodejs --path serverless-2
cd serverless-2
npm install
npm install standard tap semantic-release --save-dev
npm install -g semantic-release-cli
mkdir test && touch test/foobar-test.js

Add test/foobar-test.js:

const test = require('tap').test
test('bogus', assert => {
  assert.equal(1, 1, 'bogus')
  assert.end()
})

Add scripts and repository in package.json:

"scripts": {
  "start": "node index.js",
  "pretest": "standard | snazzy",
  "test": "tap --coverage --jobs-auto './test/*-test.js'",
  "semantic-release": "semantic-release"
},
"repository": {
  "type": "git",
  "url": "https://github.com/heneise/serverless-v2.0.0.git"
}

Google keyfile.json

Follow the Google Credentials page to retrieve a keyfile.json: https://serverless.com/framework/docs/providers/google/guide/credentials

Make sure the Service account has "Editor" permissions on the project.

Instead of saving the keyfile.json to ~/.gcloud, copy it directly into your project folder. Don't worry, keyfile.json is on .gitignore and won't be commited to the repository.

Travis CI

Add .travis.yml:

language: node_js
node_js:
  - '10'
notifications:
  email: false
cache:
  directories:
    - node_modules
env:
  global:
    - NODE_ENV=test
before_install:
  - 'echo "//registry.npmjs.org/:_authToken="${NPM_TOKEN} > .npmrc'
  - npm i -g npm@6
  - npm i -g serverless
install:
  - npm ci
script:
  - npm test
after_success:
  - npm run semantic-release
deploy:
  skip_cleanup: true
  provider: script
  script: serverless deploy
  on:
    branch: master
branches:
  only:
    - master
    - /^greenkeeper.*$/

Before setting up travis, we need to commit and push the contents to a GitHub repository:

git init
git add .
git commit -am 'initial commit'
git remote add origin git remote add origin https://github.com/heneise/serverless-v2.0.0.git
git push -u origin master

Head over to travis and enable the repo for testing.

In order to deploy to Google Cloud Functions, you need the keyfile.json. And to deploy from travis, the keyfile has to be on travis. For this part, you need the travis-cli to encrypt the keyfile. Head to this Travis GitHub Repo for further information on how to install this. It should be as simple as gem install travis. Once you have the cli, you might need to log in with travis login.

$ travis encrypt-file keyfile.json --add
encrypting keyfile.json for heneise/serverless-v2.0.0
storing result as keyfile.json.enc
storing secure env variables for decryption

Make sure to add keyfile.json.enc to the git repository.
Make sure not to add keyfile.json to the git repository.
Commit all changes to your .travis.yml.

Keyfile is encrypted and ready on travvis. Next step.

Semantic-Release

Documentation

Once travis and github are set up, let's install the tokens:

$ semantic-release-cli setup
? What is your npm registry? https://registry.npmjs.org/
? What is your npm username? hc-eng
? What is your GitHub username? hc-eng
? What is your GitHub two-factor authentication code? XXXXXX
? What CI are you using? Travis CI
? Do you want a `.travis.yml` file with semantic-release setup? No

This might look different for you, if you haven't logged in with semantic-release before. We don't need the .travis.yml as we already configured that.

Summary

That's it. Happy version release.