generated from NHSDigital/nhs-notify-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
148 lines (131 loc) · 5.43 KB
/
cicd-3-deploy.yaml
File metadata and controls
148 lines (131 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: "2. Deploy docs to GitHub Pages"
on:
workflow_run:
workflows: ["1. CI/CD pull request"]
types:
- completed
branches: [main]
workflow_dispatch:
inputs:
include_prereleases:
type: choice
description: "Include pre-releases"
default: "true"
options:
- "true"
- "false"
version:
type: string
default: latest
description: "Install specific version"
run-name: >-
${{ (inputs.include_prereleases != null
&& inputs.version != null
&& format('Triggered Manually. Include prerelease: {0} Version: {1} By: @{2}',
inputs.include_prereleases,
inputs.version,
github.actor))
|| format('Triggered by {0} ({1}). Include prerelease: true Version: latest',
github.event.workflow_run.name,
github.event.workflow_run.display_title) }}
permissions:
contents: read
pages: write
id-token: write
jobs:
metadata:
name: "Set CI/CD metadata"
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
build_datetime: ${{ steps.variables.outputs.build_datetime }}
build_timestamp: ${{ steps.variables.outputs.build_timestamp }}
build_epoch: ${{ steps.variables.outputs.build_epoch }}
nodejs_version: ${{ steps.variables.outputs.nodejs_version }}
python_version: ${{ steps.variables.outputs.python_version }}
terraform_version: ${{ steps.variables.outputs.terraform_version }}
version: ${{ steps.variables.outputs.version }}
# tag: ${{ steps.variables.outputs.tag }}
steps:
- name: "Checkout code"
uses: actions/checkout@v5
- name: "Set CI/CD variables"
id: variables
run: |
datetime=$(date -u +'%Y-%m-%dT%H:%M:%S%z')
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
# echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
- name: "List variables"
run: |
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}"
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 }}"
make list-variables
deploy-jekyll:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: metadata
steps:
- name: "Checkout code"
uses: actions/checkout@v5
- name: "Get version"
id: get-asset-version
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
INPUTS_INCLUDE_PRERELEASES="${{ inputs.include_prereleases }}"
INPUTS_INCLUDE_PRERELEASES=${INPUTS_INCLUDE_PRERELEASES:-"true"}
INPUTS_VERSION="${{ inputs.version }}"
INPUTS_VERSION=${INPUTS_VERSION:-"latest"}
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 "Release list response: $json"
# Check if the response is empty
if [[ "$json" == "[]" ]] || [[ -z "$json" ]]; then
echo "::error::No releases found. Please create a release before deploying docs."
exit 1
fi
release_version=$(echo $json | jq -r '.[0].tagName')
if [[ "$release_version" == "null" ]] || [[ -z "$release_version" ]]; then
echo "::error::Could not extract release version from: $json"
exit 1
fi
echo "Found release version: $release_version"
if [[ $INPUTS_VERSION == latest ]]; then
echo "release_version=$release_version" >> $GITHUB_OUTPUT
else
echo "release_version=$INPUTS_VERSION" >> $GITHUB_OUTPUT
fi
- 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}}