Giter Club home page Giter Club logo

deploy's Introduction

primer/deploy

This GitHub Action deploys to Now and aliases the successful deployment to a predictable URL according to the following conditions:

  1. We run now without any arguments to get the "root" deployment URL, which is generated by Now.
  2. If the branch is master, we treat the alias field in now.json as the production URL and:
    1. If there is a rules.json:
      • now alias <deployment> <name>.now.sh to create a fallback URL for path aliases
      • now alias <deployment> <production> -r rules.json to set up path aliases
    2. now alias <deployment> <production> to alias the production URL.
  3. now alias <deployment> <name>-<branch>.now.sh to alias the root deployment to a branch-specific URL.

The app name (<name>) and branch (<branch>) are both "slugified" to strip invalid characters so that they'll work as URLs. Leading non-word characters are removed, and any sequence of characters that isn't alphanumeric or - is replaced with a single -. In other words, @primer/css becomes primer-css, shawnbot/some_branch becomes shawnbot-some-branch, and so on.

Status checks

Two status checks will be listed for this action in your checks: deploy is the action's check, and deploy/alias is a commit status created by the action that reports the URL and links to it via "Details":

image

Note: Checks listed in the PR merge box (above) always point to the most recent commit, but you can access the list of checks for the last commit of every push by clicking on the status icon (usually a green check or red x) in your repo's "Commits" and "Branches" pages, or commit history on a PR page:

image

Usage

To use this action in your own workflow, add the following snippet to your .github/main.workflow file:

action "deploy" {
  uses = "primer/deploy@master"
  secrets = [
    "GITHUB_TOKEN",
    "NOW_TOKEN",
  ]
}

You will need to provide a Zeit token value for the NOW_TOKEN secret in the Actions visual editor if you haven't already.

To avoid racking up failed deployments, we suggest that you place this action after any linting and test actions.

Now CLI arguments

It's possible to pass additional arguments through to the now CLI via the args field in your workflow action. Because the primer-deploy CLI accepts options of its own (such as --dry-run), you need to prefix any now arguments with --:

action "deploy" {
  uses = "primer/deploy@master"
+  args = "-- --meta autoDeployed=true"

You can also use args to deploy a subdirectory, e.g. docs:

action "deploy" {
  uses = "primer/deploy@master"
+  args = "-- docs"

deploy's People

Contributors

shawnbot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

deploy's Issues

Deprecate this action ๐Ÿ’€

A lot has changed with Now's GitHub integration since we made this action, and it does all of the things we do. As we migrate our repos from Now v1 to v2, we need to also remove this action from our workflows and add them to the list in our installed app settings. Here's the playbook for migrating:

  1. Add the repo in the Now app settings (private, behind sudo auth).
  2. Delete any actions with uses = "primer/deploy@..." in .github/main.workflow, and remove that action's name from any needs = [...] prerequisites in other actions.
  3. Commit those changes to a new branch and create a PR so that you can see what happens and fix any issues that come up.

That should be it! If all goes well, you'll get a comment from now[bot] with a link to the deployment. If the repo you're updating is on Now v2 (if it has version: 2 in now.json), you'll get an alias URL for the most recent deployment in the form {project}-git-{branch}.primer.now.sh. โœจ

Note that migration URLs are still available in the status checks list for each push, but the integration uses our Deployments API and closes #7.

Repos to migrate

Docs to update

  • primer/actions (this repo can probably be deleted if we're only using primer/publish everywhere)

Run now with `--no-verify`

We've been having issues with the Now CLI timing out, and it looks like there are a couple of fixes:

  1. Reduce the scale numbers so that Now doesn't have to verify instantiation of as many instances in different regions.
  2. Run now --no-verify the first time to skip the instantiation check.

Unfortunately we can't test this with args = ["--", "--no-verify"] because now alias barfs on the --no-verify flag.

Use the deployments API?

Deployments would allow us to move links for the deployed site out of status checks and into the area above the PR merge box:

image

Based on my brief skimming, it looks like we would create a deployment with the API from this action and base the "environment" on branch (maybe development for "root" deployments and branch aliases, staging for release candidates, and production on master?), let GitHub sort out the required status checks, then we'd be on the hook for running something that gets the deployment event, actually does the deployment (running now), then reports back status.

I think that we can respond to the deployment event in Actions, which would mean that maybe we have a on = "deployment" workflow that runs a different action than the one that creates the deployment, in which case we wouldn't have to run a server that gets the webhooks? I dunno, the more I write about it the less convinced I am that this is worth doing. ๐Ÿค”

/cc @jonrohan

$ now alias deprecated

On 3/19/19, a new version of Now was released which unfortunately deprecates the alias subcommand.

Instead they have replaced it with a simpler but less powerful feature called "Automatic Aliasing".

https://zeit.co/blog/automatic-aliasing

That said, I do not see any mention of the POST aliases endpoint being deprecated from the v2 API. ๐Ÿค”

https://zeit.co/docs/api/#endpoints/aliases/assign-an-alias-to-a-deployment

I'm wondering if this action will need to be updated?

Run now from this repo's working dir, not via npx

Currently we run the Now CLI with npx now <args>, which presents some issues:

  1. Each repo is responsible for having now as a (dev) dependency, and may use a version that are "incompatible" with the assumptions we make here.
  2. As seen in this failed run, if npx has to install now at runtime it'll fail because it's running as root, which prevents lifecycle hooks like postinstall from running, and it looks to me from that error that now relies on those.

So instead of running npx now, we should have now as a dependency in this repo and get its CLI path locally, i.e. ./node_modules/.bin/now.

The only downside to this is that repos can't spec their own Now CLI version, but being able to upgrade it consistently across our repos by pinning a version of this action feels more sustainable to me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.