Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
RossBugginsNHS committed Jul 2, 2024
2 parents 45e67d9 + 49617fa commit dcce03d
Show file tree
Hide file tree
Showing 74 changed files with 784 additions and 389 deletions.
11 changes: 5 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
// Configure tool-specific properties.
"customizations": {
"codespaces": {
"openFiles": [
"README.md",
".github/SECURITY.md",
"docs/index.md"
]
"openFiles": ["README.md", ".github/SECURITY.md", "docs/index.md"]
},
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"autoOpenWorkspace.enableAutoOpenIfSingleWorkspace": true,
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"[makefile]": {
Expand All @@ -33,6 +30,7 @@
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"zoma.vscode-auto-open-workspace",
"alefragnani.bookmarks",
"davidanson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
Expand Down Expand Up @@ -64,7 +62,8 @@
"yzane.markdown-pdf",
"yzhang.dictionary-completion",
"yzhang.markdown-all-in-one",
"joshx.workspace-terminals"
"joshx.workspace-terminals",
"takumii.markdowntable"
]
}
},
Expand Down
42 changes: 42 additions & 0 deletions .github/actions/build-docs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "Build Docs"
description: "build jekyll docs"
inputs:
version:
description: "Version number"
required: true
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Npm cli install
working-directory: ./docs
run: npm ci
shell: bash
- name: Setup Ruby
uses: ruby/[email protected]
with:
ruby-version: "3.1" # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
cache-version: 0 # Increment this number if you need to re-download cached gems
working-directory: "./docs"
- name: Setup Pages
id: pages
uses: actions/configure-pages@v5
- name: Build with Jekyll
working-directory: ./docs
# Outputs to the './_site' directory by default
shell: bash
run: make build BASE_URL="${{ steps.pages.outputs.base_path }}" VERSION="${{ inputs.version }}"
#run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}"
env:
JEKYLL_ENV: production
- name: Upload artifact
# Automatically uploads an artifact from the './_site' directory by default
uses: actions/upload-pages-artifact@v3
with:
path: "docs/_site/"
name: jekyll-docs-${{ inputs.version }}
32 changes: 27 additions & 5 deletions .github/workflows/cicd-1-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CI/CD pull request"
name: "1. CI/CD pull request"

# The total recommended execution time for the "CI/CD Pull Request" workflow is around 20 minutes.

Expand All @@ -8,6 +8,8 @@ on:
- "**"
pull_request:
types: [opened, reopened]
branches:
- main

jobs:
metadata:
Expand All @@ -23,6 +25,7 @@ jobs:
python_version: ${{ steps.variables.outputs.python_version }}
terraform_version: ${{ steps.variables.outputs.terraform_version }}
version: ${{ steps.variables.outputs.version }}
is_version_prerelease: ${{ steps.variables.outputs.is_version_prerelease }}
does_pull_request_exist: ${{ steps.pr_exists.outputs.does_pull_request_exist }}
steps:
- name: "Checkout code"
Expand All @@ -31,15 +34,18 @@ jobs:
id: variables
run: |
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
BUILD_DATETIME=$datetime make version-create-effective-file
BUILD_DATETIME=$datetime make version-create-effective-file dir=.
version=$(head -n 1 .version 2> /dev/null || echo unknown)
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" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
echo "version=$(echo $version)" >> $GITHUB_OUTPUT
echo "is_version_prerelease=$(if [[ $version == *-* ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT
- name: "Check if pull request exists for this branch"
id: pr_exists
env:
Expand All @@ -65,6 +71,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 }}"
export IS_VERSION_PRERELEASE="${{ steps.variables.outputs.is_version_prerelease }}"
make list-variables
commit-stage: # Recommended maximum execution time is 2 minutes
name: "Commit stage"
Expand Down Expand Up @@ -96,7 +103,7 @@ jobs:
name: "Build stage"
needs: [metadata, test-stage]
uses: ./.github/workflows/stage-3-build.yaml
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) || (github.event_name == 'push' && github.ref == 'refs/heads/main')
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
Expand All @@ -110,7 +117,21 @@ jobs:
name: "Acceptance stage"
needs: [metadata, build-stage]
uses: ./.github/workflows/stage-4-acceptance.yaml
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened'))
if: needs.metadata.outputs.does_pull_request_exist == 'true' || (github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened')) || (github.event_name == 'push' && github.ref == 'refs/heads/main')
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
build_epoch: "${{ needs.metadata.outputs.build_epoch }}"
nodejs_version: "${{ needs.metadata.outputs.nodejs_version }}"
python_version: "${{ needs.metadata.outputs.python_version }}"
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
version: "${{ needs.metadata.outputs.version }}"
secrets: inherit
publish-stage: # Recommended maximum execution time is 10 minutes
name: "Publish stage"
needs: [metadata, acceptance-stage]
uses: ./.github/workflows/stage-5-publish.yaml
if: (github.event_name == 'push' && github.ref == 'refs/heads/main')
with:
build_datetime: "${{ needs.metadata.outputs.build_datetime }}"
build_timestamp: "${{ needs.metadata.outputs.build_timestamp }}"
Expand All @@ -119,4 +140,5 @@ jobs:
python_version: "${{ needs.metadata.outputs.python_version }}"
terraform_version: "${{ needs.metadata.outputs.terraform_version }}"
version: "${{ needs.metadata.outputs.version }}"
is_version_prerelease: "${{ needs.metadata.outputs.is_version_prerelease }}"
secrets: inherit
98 changes: 0 additions & 98 deletions .github/workflows/cicd-2-publish.yaml

This file was deleted.

89 changes: 59 additions & 30 deletions .github/workflows/cicd-3-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
name: "CI/CD deploy"
name: "2. Deploy docs to GitHub Pages"

on:
workflow_dispatch:
inputs:
tag:
description: "This is the tag that is oging to be deployed"
required: true
default: "latest"
include_prereleases:
type: choice
description: "Include pre-releases"
default: "true"
options:
- "true"
- "false"

permissions:
contents: read
pages: write
id-token: write

jobs:
metadata:
Expand All @@ -21,7 +29,7 @@ jobs:
python_version: ${{ steps.variables.outputs.python_version }}
terraform_version: ${{ steps.variables.outputs.terraform_version }}
version: ${{ steps.variables.outputs.version }}
tag: ${{ steps.variables.outputs.tag }}
# tag: ${{ steps.variables.outputs.tag }}
steps:
- name: "Checkout code"
uses: actions/checkout@v4
Expand All @@ -37,7 +45,7 @@ jobs:
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
# TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
# echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- name: "List variables"
run: |
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
Expand All @@ -47,31 +55,52 @@ jobs:
export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}"
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
export VERSION="${{ steps.variables.outputs.version }}"
export TAG="${{ steps.variables.outputs.tag }}"
# export TAG="${{ steps.variables.outputs.tag }}"
make list-variables
deploy:
name: "Deploy to an environment"
deploy-jekyll:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: [metadata]
timeout-minutes: 10
needs: metadata
steps:
- name: "Checkout code"
uses: actions/checkout@v4
# TODO: More jobs or/and steps here
# success:
# name: "Success notification"
# runs-on: ubuntu-latest
# needs: [deploy]
# steps:
# - name: "Check prerequisites for notification"
# id: check
# run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT
# - name: "Notify on deployment to an environment"
# if: steps.check.outputs.secret_exist == 'true'
# uses: nhs-england-tools/[email protected]
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }}
# message-title: "Notification title"
# message-text: "This is a notification body"
# link: ${{ github.event.pull_request.html_url }}

- name: "Get version"
id: get-asset-version
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ ${{inputs.include_prereleases}} == true ]]; then
json=$(gh release list --json tagName --limit 1 --exclude-drafts)
else
json=$(gh release list --json tagName --limit 1 --exclude-drafts --exclude-pre-releases)
fi
echo $json
release_version=$(echo $json | (jq -r '.[0].tagName'))
if [[ $release_version == null ]]; then exit 1; else echo $release_version; fi
echo release_version=$(echo $release_version) >> $GITHUB_OUTPUT
- name: "Get release version"
id: download-asset
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release download ${{steps.get-asset-version.outputs.release_version}} -p jekyll-docs-*.tar --output artifact.tar
- uses: actions/upload-artifact@v4
with:
name: jekyll-docs-${{steps.get-asset-version.outputs.release_version}}
path: artifact.tar

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: jekyll-docs-${{steps.get-asset-version.outputs.release_version}}
Loading

0 comments on commit dcce03d

Please sign in to comment.