Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ scripts/terraform/** linguist-vendored
scripts/tests/test.mk linguist-vendored
scripts/init.mk linguist-vendored
scripts/shellscript-linter.sh linguist-vendored

*.sh text eol=lf
scripts/** text eol=lf
8 changes: 6 additions & 2 deletions .github/actions/lint-terraform/action.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: "Lint Terraform"
description: "Lint Terraform"
inputs:
enabled:
description: "Whether Terraform linting should run"
required: false
default: "false"
root-modules:
description: "Comma separated list of root module directories to validate, content of the 'infrastructure/environments' is checked by default"
required: false
Expand All @@ -16,6 +20,6 @@ runs:
run: |
stacks=${{ inputs.root-modules }}
for dir in $(find infrastructure/environments -type f -name '*.tf' -exec dirname {} \; | sort -u; echo ${stacks//,/$'\n'}); do
dir=$dir opts="-backend=false" make terraform-init
dir=$dir make terraform-validate
dir=$dir opts="-backend=false" make -f scripts/terraform/terraform.mk terraform-init
dir=$dir make -f scripts/terraform/terraform.mk terraform-validate
done
39 changes: 29 additions & 10 deletions .github/workflows/cicd-1-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,35 @@ jobs:
uses: actions/checkout@v7
- name: "Set CI/CD variables"
id: variables
shell: bash
run: |
set -euo pipefail

datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
BUILD_DATETIME=$datetime make version-create-effective-file
echo "build_datetime_london=$(TZ=Europe/London date --date=$datetime +'%Y-%m-%dT%H:%M:%S%z')" >> $GITHUB_OUTPUT
echo "build_datetime=$datetime" >> $GITHUB_OUTPUT
echo "build_timestamp=$(date --date=$datetime -u +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
echo "build_epoch=$(date --date=$datetime -u +'%s')" >> $GITHUB_OUTPUT
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT

if [ -f VERSION ]; then
version_template=$(cat VERSION)
version_template=$(printf '%s' "$version_template" \
| sed "s/\(\${yyyy}\|\$yyyy\)/$(date --date="$datetime" -u +"%Y")/g" \
| sed "s/\(\${mm}\|\$mm\)/$(date --date="$datetime" -u +"%m")/g" \
| sed "s/\(\${dd}\|\$dd\)/$(date --date="$datetime" -u +"%d")/g" \
| sed "s/\(\${HH}\|\$HH\)/$(date --date="$datetime" -u +"%H")/g" \
| sed "s/\(\${MM}\|\$MM\)/$(date --date="$datetime" -u +"%M")/g" \
| sed "s/\(\${SS}\|\$SS\)/$(date --date="$datetime" -u +"%S")/g" \
| sed "s/\(\${hash}\|\$hash\)/$(git rev-parse --short HEAD)/g")
printf '%s\n' "$version_template" > .version
else
printf '%s\n' "$datetime" > .version
fi

echo "build_datetime_london=$(TZ=Europe/London date --date="$datetime" +'%Y-%m-%dT%H:%M:%S%z')" >> "$GITHUB_OUTPUT"
echo "build_datetime=$datetime" >> "$GITHUB_OUTPUT"
echo "build_timestamp=$(date --date="$datetime" -u +'%Y%m%d%H%M%S')" >> "$GITHUB_OUTPUT"
echo "build_epoch=$(date --date="$datetime" -u +'%s')" >> "$GITHUB_OUTPUT"
echo "nodejs_version=$(grep "^nodejs\s" .tool-versions | cut -f2 -d' ')" >> "$GITHUB_OUTPUT"
echo "python_version=$(grep "^python\s" .tool-versions | cut -f2 -d' ')" >> "$GITHUB_OUTPUT"
echo "terraform_version=$(grep "^terraform\s" .tool-versions | cut -f2 -d' ')" >> "$GITHUB_OUTPUT"
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> "$GITHUB_OUTPUT"
- name: "Check if pull request exists for this branch"
id: pr_exists
env:
Expand All @@ -55,6 +73,7 @@ jobs:
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
fi
- name: "List variables"
shell: bash
run: |
export BUILD_DATETIME_LONDON="${{ steps.variables.outputs.build_datetime_london }}"
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
Expand All @@ -65,7 +84,7 @@ jobs:
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
export VERSION="${{ steps.variables.outputs.version }}"
export DOES_PULL_REQUEST_EXIST="${{ steps.pr_exists.outputs.does_pull_request_exist }}"
make list-variables
env | sort
commit-stage: # Recommended maximum execution time is 2 minutes
name: "Commit stage"
needs: [metadata]
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/stage-1-commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ jobs:
fetch-depth: 0 # Full history is needed to compare branches
- name: "Check English usage"
uses: ./.github/actions/check-english-usage
lint-terraform:
name: "Lint Terraform"
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: "Checkout code"
uses: actions/checkout@v7
- name: "Lint Terraform"
uses: ./.github/actions/lint-terraform
# lint-terraform:
# name: "Lint Terraform"
# runs-on: ubuntu-latest
# timeout-minutes: 2
# steps:
# - name: "Checkout code"
# uses: actions/checkout@v7
# - name: "Lint Terraform"
# uses: ./.github/actions/lint-terraform
89 changes: 55 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,57 @@
# This file is for you! Edit it to implement your own hooks (make targets) into
# the project as automated steps to be executed on locally and in the CD pipeline.

include scripts/init.mk

# ==============================================================================

# Example CI/CD targets are: dependencies, build, publish, deploy, clean, etc.
.DEFAULT_GOAL := help
.PHONY: help workflow config dependencies githooks-config githooks-run
.SILENT: help workflow
Comment thread
micjustus-nc marked this conversation as resolved.
.NOTPARALLEL: # this is because make -j could cause race conditions
.ONESHELL:
.SHELLFLAGS := -ce

MAKEFLAGS += --no-print-directory # '+=' preserves caller-supplied flags
SHELL := /bin/bash

ifeq (,$(filter oneshell,$(.FEATURES)))
$(error .ONESHELL not supported (GNU Make 3.82+ required, found $(MAKE_VERSION)))
endif

include scripts/make/environment.mk
include scripts/make/bootstrap.mk
include scripts/make/azure.mk

# ---------------------------------------------------------------------------
# Help & Meta
# ---------------------------------------------------------------------------
help: # Print help @Others
printf "\nUsage: \033[3m\033[93m[arg1=val1] [arg2=val2] \033[0m\033[0m\033[32mmake\033[0m\033[34m <command>\033[0m\n\n"
perl -e '$(HELP_SCRIPT)' $(MAKEFILE_LIST)

# ---------------------------------------------------------------------------
# Bootstrap & Environment
# ---------------------------------------------------------------------------
# Configure development environment (main) @Configuration
config:
_install-tools
_install-uv
githooks-config
dependencies

dependencies: # Install dependencies needed to build and test the project @Pipeline
uv sync --directory nbss

build: # Build the project artefact @Pipeline
# TODO: Implement the artefact build step

publish: # Publish the project artefact @Pipeline
# TODO: Implement the artefact publishing step

deploy: # Deploy the project artefact to the target environment @Pipeline
# TODO: Implement the artefact deployment step

clean:: # Clean-up project resources (main) @Operations
# TODO: Implement project resources clean-up step

config:: # Configure development environment (main) @Configuration
# TODO: Use only 'make' targets that are specific to this project, e.g. you may not need to install Node.js
make _install-dependencies

# ==============================================================================

${VERBOSE}.SILENT: \
build \
clean \
config \
dependencies \
deploy \
@if [ -f nbss/pyproject.toml ]; then \
uv sync --no-build --directory nbss; \
else \
echo "Skipping uv sync: nbss/pyproject.toml not found"; \
fi
@if [ -f package.json ]; then \
npm install; \
else \
echo "Skipping npm install: package.json not found"; \
fi

githooks-config:
if ! command -v pre-commit >/dev/null 2>&1; then \
pip install pre-commit; \
fi
pre-commit install

githooks-run: # Run git hooks configured in this repository @Operations
pre-commit run \
--config scripts/config/pre-commit.yaml \
--all-files
Loading