Evaluate inputs in conditionals from input context instead of github … #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Node Workflow | |
# Standard workflow for any NodeJS based projects. | |
on: | |
workflow_call: | |
inputs: | |
mainline_branch: | |
default: "master" | |
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to the master branch." | |
repo_url: | |
default: "harbor.devops.k8s.rcsb.org" | |
description: "The URL of the remote Docker image repository." | |
repo_project: | |
required: true | |
description: "The name of the project or organization in the remote Docker image repository." | |
docker_image_name: | |
required: true | |
description: "The name of the Docker image to create." | |
do_staging_build: | |
default: "false" | |
description: "Build, tag, and push a docker image with the staging tag on commits to the mainline branch." | |
restart_staging_deployment: | |
default: "false" | |
description: "Restart the staging K8s deployments for this application on commits to the mainline branch." | |
staging_k8s_deployment_name: | |
required: "false" | |
description: "The name of the deployment in the K8s staging namespace to restart. Needed if restart_staging_deployment is true." | |
do_production_build: | |
default: "true" | |
description: "Build, tag, and push a docker image with the production tag on commits to the mainline branch." | |
restart_production_deployment: | |
default: "false" | |
description: "Restart the production K8s deployment for this application on commits to the mainline branch." | |
production_k8s_deployment_name: | |
required: false | |
description: "The names of the deployment in the K8s production namespace to restart. Needed if production_k8s_deployment_name is true." | |
node_version: | |
default: "16" | |
description: "The nodejs version of the runner to use. Defaults to 16." | |
workflow_dispatch: | |
inputs: | |
mainline_branch: | |
default: "master" | |
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to the master branch." | |
repo_url: | |
default: "harbor.devops.k8s.rcsb.org" | |
description: "The URL of the remote Docker image repository." | |
repo_project: | |
required: true | |
description: "The name of the project or organization in the remote Docker image repository." | |
docker_image_name: | |
required: true | |
description: "The name of the Docker image to create." | |
do_staging_build: | |
default: "false" | |
description: "Build, tag, and push a docker image with the staging tag on commits to the mainline branch." | |
do_production_build: | |
default: "true" | |
description: "Build, tag, and push a docker image with the production tag on commits to the mainline branch." | |
node_version: | |
default: "16" | |
description: "The nodejs version of the runner to use. Defaults to 16." | |
jobs: | |
# Build jobs | |
debug: | |
name: "Debug conditionals" | |
runs-on: | |
- "self-hosted" | |
- "node-${{ inputs.node_version }}" | |
steps: | |
- name: "Output inputs and refs" | |
run: | | |
echo "=== Check branch conditionals" | |
echo "github.ref_name: ${{ github.ref_name }}" | |
echo "inputs.mainline_branch: ${{ inputs.mainline_branch }}" | |
echo "Is github.ref_name == inputs.mainline_branch: ${{ github.ref_name == inputs.mainline_branch }}" | |
echo "=== Check event conditionals" | |
echo "github.event_name: ${{ github.event_name }}" | |
echo "Is github.event_name != 'pull_request': ${{ github.event_name != 'pull_request' }}" | |
echo "=== Check environment conditionals" | |
echo "inputs.do_staging_build: ${{ inputs.do_staging_build }}" | |
echo "inputs.restart_staging_deployment: ${{ inputs.restart_staging_deployment }}" | |
echo "inputs.staging_k8s_deployment_name: ${{ inputs.staging_k8s_deployment_name }}" | |
echo "inputs.do_production_build: ${{ inputs.do_production_build }}" | |
echo "inputs.restart_production_deployment: ${{ inputs.restart_production_deployment }}" | |
echo "inputs.production_k8s_deployment_name: ${{ inputs.production_k8s_deployment_name }}" | |
build_npm: | |
name: "Build via NPM" | |
uses: ./.github/workflows/run_npm.yaml | |
with: | |
script: "build" | |
node_version: ${{ inputs.node_version }} | |
lint_npm: | |
name: "Lint via NPM" | |
uses: ./.github/workflows/run_npm.yaml | |
with: | |
script: "lint" | |
node_version: ${{ inputs.node_version }} | |
lint_docker: | |
name: "Lint Dockerfile" | |
uses: ./.github/workflows/lint_docker.yaml | |
# Test jobs | |
test_npm: | |
name: "Run unit tests via NPM" | |
needs: | |
- build_npm | |
- lint_npm | |
- lint_docker | |
uses: ./.github/workflows/run_npm.yaml | |
with: | |
script: "test" | |
node_version: ${{ inputs.node_version }} | |
build_docker: | |
name: "Build docker image" | |
needs: | |
- build_npm | |
- lint_npm | |
- lint_docker | |
uses: ./.github/workflows/build_docker.yaml | |
with: | |
repo_url: "${{ inputs.repo_url }}" | |
repo_project: "${{ inputs.repo_project }}" | |
docker_image_name: "${{ inputs.docker_image_name }}" | |
# Staging jobs | |
build_docker_staging: | |
name: "Push docker image with staging tag" | |
if: | | |
inputs.do_staging_build == 'true' && | |
github.ref_name == inputs.mainline_branch && | |
github.event_name != 'pull_request' | |
needs: | |
- test_npm | |
- build_docker | |
uses: ./.github/workflows/retag_docker.yaml | |
with: | |
repo_url: "${{ inputs.repo_url }}" | |
repo_project: "${{ inputs.repo_project }}" | |
docker_image_name: "${{ inputs.docker_image_name }}" | |
old_tag: "${{ github.ref_name }}" | |
new_tag: "staging" | |
restart_staging_k8s_deployment: | |
name: "Restart deployment in K8s staging namespace" | |
if: | | |
inputs.restart_staging_deployment == 'true' && | |
inputs.staging_k8s_deployment_name && | |
github.ref_name == inputs.mainline_branch && | |
github.event_name != 'pull_request' | |
needs: | |
- build_docker_staging | |
uses: ./.github/workflows/restart_k8s_deployment.yaml | |
strategy: | |
fail-fast: false | |
matrix: | |
region: [west, east] | |
with: | |
deployment_name: "${{ inputs.staging_k8s_deployment_name }}" | |
namespace: "staging" | |
region: "${{ matrix.region }}" | |
# Production jobs | |
build_docker_production: | |
name: "Push docker image with production tag" | |
if: | | |
inputs.do_production_build == 'true' && | |
github.ref_name == inputs.mainline_branch && | |
github.event_name != 'pull_request' | |
needs: | |
- test_npm | |
- build_docker | |
uses: ./.github/workflows/retag_docker.yaml | |
with: | |
repo_url: "${{ inputs.repo_url }}" | |
repo_project: "${{ inputs.repo_project }}" | |
docker_image_name: "${{ inputs.docker_image_name }}" | |
old_tag: "${{ github.ref_name }}" | |
new_tag: "production" | |
restart_production_k8s_deployment: | |
name: "Restart deployment in K8s production namespace" | |
if: | | |
inputs.restart_production_deployment == 'true' && | |
inputs.production_k8s_deployment_name && | |
github.ref_name == inputs.mainline_branch && | |
github.event_name != 'pull_request' | |
needs: | |
- build_docker_production | |
uses: ./.github/workflows/restart_k8s_deployment.yaml | |
strategy: | |
fail-fast: false | |
matrix: | |
region: [ west, east ] | |
with: | |
deployment_name: "${{ inputs.production_k8s_deployment_name }}" | |
namespace: "production" | |
region: "${{ matrix.region }}" |