Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Build and Test Node.js with GitHub Actions

Table of Contents

Overview

GitHub Actions provides Runners with Linux, Windows, or Apple OSes, and supports installing dependencies and executing shell commands to build, test, and deploy node.js apps.

Runners

GitHub provides 'Runners' that are pre-defined environments used for build, test, and deploy operations.

Runners come with specific minimum capabilities like:

Windows-based runners also have:

Runners can cache dependencies to speed up builds.

Installing Dependencies

Commands:

Note: Private registry installation using .npmrc file is supported. Use setup-node action to support this feature (required tokens/encrypted secrets).

Workflows

GitHub Actions

Intro To GitHub Actions

GitHub Actions are related to GitHub workflows, events, Jobs, and Runners.

GitHub Actions Are:

GitHub Actions Flow

Events trigger Workflows that contain Jobs that use Actions.

GitHub Workflows

Workflows define automation.

GitHub has Starter Workflows.

GitHub Actions syntax.

Standard Syntax Elements:

Allowable Workflow Syntax for GitHub Actions.

GitHub Actions Events

These are Events implemented by a Workflow on clause.

GitHub Jobs

Jobs are encapsulated by Workflows, and is a set of steps to be executed in order by a Runner.

GitHub Runners

Runners are compute resources.

Note: Avoid using self-service Runners in Public repos. This is a security risk.

Hosted Runners:

Self-Hosted Runners:

Reviewing GitHub Actions Customization And Results

Training: GitHub Actions: hellow-world.

GitHub Action Best Practices

Consider contributing to the Actions Marketplace. Follow these best practices when creating Actions for your Repos as any Marketplace contributions:

With

Parameters might include:

Run

Defines the shell command to run:

Node-Version

Workflow Artifact Storage

See GitHub Docs Storing workflow data as artifacts.

Pushing to Package Registries

See GitHub Docs Publishing Node.js packages.

My Exeperiences

Deploying NodeJS to Azure App Service

GitHub Actions:

Environment Variables:

Improvements

I can do the following to improve the above build-test-deploy script:

CI With GitHub Actions

These notes were generated while reviewing the MSLearn Module "Learn Continuous Integration: GitHub Actions"

Learning Objectives:

Mark Relases with Git Tags

Releases are based on Git tags.

About GitHub Tags and Releases.

Actions: Environment Variables

GitHub built-inv EnvVars:

EnvVars are passed to Actions in a Step using env: marker.

GitHub Actions Secrets

Secrets are Encrypted Environment Variables:

Secrets can be used in if: conditionals within a Job.

Actions: Artifacts

Often times artifacts from one Job need to be passed to another Job.

Uploads:

Downloads:

Retaining Artifacts:

Deleting Artifacts:

This is done via the GitHub UI.

Workflow Badges

Use these to show status in a repository.

Example URL: https://github.com/{OWNER}/{REPOSITORY}/actions/workflows/{WORKFLOW_FILE}/badge.svg

Specify a Branch (other than the default branch) by appending ?branch=BRANCH to the URL.

Adding a Workflow Status Badge.

AZ400 Implementing GitHub Actions Notes

These notes were taken while working through the AZ400 exercise.

  1. GitHub Repo import other repository: It is not necessary to add credentials for a public repo.
  2. Once import is completed, Settings can be entered to change Actions to allow or disable reusable workflows.
  3. Create an Azure Service Principal and save it as a GitHub Secret. This requires knowing your SubscriptionID and the target Resource Group name. Save the JSON output.
  4. Register the Resource Provider for the Azure App Service using az provider register --namespace Microsoft.Web.
  5. Open Settings of the GitHub Repo and go to the Secrets and Variables and open Actions to add the Secret by pasting-in the JSON object.
  6. Create the workflow YAML that can leverage BICEP to generate a deploy file, and will use the GitHub SECRET created earlier to authenticate to Azur and deploy the service/WebApp/etc.
  7. Open Actions in the GitHub Repo, find the Action (probably in-process) and click on it to see its status.
  8. Open Azure Portal and open the Resource Group. A GitHub Action, a Bicep template, and the App Service Plan will appear. In the case of a WebApp, a browse button will become available to open the WebApp in your default browser.

It is possible to add a Manual Approval to allow (or reject...or ignore) Deployments prior to the GitHub Action triggering the workflow.

References

Return to Conted Index

Return to Root README