Skip to content

Commit 4e5fc0a

Browse files
committed
CCM-11938: try
1 parent f03815c commit 4e5fc0a

File tree

5 files changed

+210
-158
lines changed

5 files changed

+210
-158
lines changed

.github/actions/build-proxies/action.yml

Lines changed: 77 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ inputs:
55
version:
66
description: "Version number"
77
required: true
8+
environment:
9+
description: "Deployment environment"
10+
required: true
11+
apimEnv:
12+
description: "APIM environment"
13+
required: true
14+
runId:
15+
description: "GitHub Actions run ID to fetch the OAS artifact from"
16+
required: true
17+
buildSandbox:
18+
description: "Whether to build the sandbox OAS spec"
19+
required: false
20+
default: false
821

922
runs:
1023
using: composite
@@ -25,46 +38,87 @@ runs:
2538
shell: bash
2639
run: |
2740
41+
ENV="${{ inputs.environment }}"
42+
if [[ "$ENV" == "internal-dev" || "$ENV" == pr* ]]; then
43+
echo "TARGET_DOMAIN=suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
44+
elif [[ "$ENV" == "uat" ]]; then
45+
echo "TARGET_DOMAIN=suppliers.nonprod.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
46+
elif [[ "$ENV" == "prod" ]]; then
47+
echo "TARGET_DOMAIN=suppliers.prod.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
48+
else
49+
echo "TARGET_DOMAIN=suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
50+
fi
51+
2852
if [ -z $PR_NUMBER ]
2953
then
3054
echo "INSTANCE=$PROXYGEN_API_NAME" >> $GITHUB_ENV
31-
echo "TARGET=https://main.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
55+
echo "TARGET=https://main.$TARGET_DOMAIN" >> $GITHUB_ENV
3256
echo "SANDBOX_TAG=latest" >> $GITHUB_ENV
3357
echo "MTLS_NAME=notify-supplier-mtls" >> $GITHUB_ENV
3458
else
35-
echo "TARGET=https://pr$PR_NUMBER.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV
59+
echo "TARGET=https://pr$PR_NUMBER.$TARGET_DOMAIN" >> $GITHUB_ENV
3660
echo "INSTANCE=$PROXYGEN_API_NAME-PR-$PR_NUMBER" >> $GITHUB_ENV
3761
echo "SANDBOX_TAG=pr$PR_NUMBER" >> $GITHUB_ENV
3862
echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV
3963
fi
4064
41-
- name: Install Proxygen client
42-
shell: bash
43-
run: |
44-
# Install proxygen cli
45-
pip install pipx
46-
pipx install proxygen-cli
65+
# - name: Install Proxygen client
66+
# shell: bash
67+
# run: |
68+
# # Install proxygen cli
69+
# pip install pipx
70+
# pipx install proxygen-cli
4771

48-
# Setup proxygen auth and settings
49-
mkdir -p ${HOME}/.proxygen
50-
echo -n $PROXYGEN_PRIVATE_KEY | base64 --decode > ${HOME}/.proxygen/key
51-
envsubst < ./.github/proxygen-credentials-template.yaml > ${HOME}/.proxygen/credentials.yaml
52-
envsubst < ./.github/proxygen-credentials-template.yaml | cat
53-
envsubst < ./.github/proxygen-settings.yaml > ${HOME}/.proxygen/settings.yaml
54-
envsubst < ./.github/proxygen-settings.yaml | cat
72+
# # Setup proxygen auth and settings
73+
# mkdir -p ${HOME}/.proxygen
74+
# echo -n $PROXYGEN_PRIVATE_KEY | base64 --decode > ${HOME}/.proxygen/key
75+
# envsubst < ./.github/proxygen-credentials-template.yaml > ${HOME}/.proxygen/credentials.yaml
76+
# envsubst < ./.github/proxygen-credentials-template.yaml | cat
77+
# envsubst < ./.github/proxygen-settings.yaml > ${HOME}/.proxygen/settings.yaml
78+
# envsubst < ./.github/proxygen-settings.yaml | cat
5579

56-
- name: Build sandbox oas
80+
- name: Build ${{ inputs.apimEnv }} oas
5781
working-directory: .
5882
shell: bash
5983
run: |
60-
make build-json-oas-spec APIM_ENV=sandbox
84+
if [ ${{ inputs.apimEnv }} == "internal-dev-sandbox" ] && [ ${{ inputs.buildSandbox }} == true ]
85+
then
86+
echo "Building sandbox OAS spec"
87+
make build-json-oas-spec APIM_ENV=sandbox
88+
else
89+
echo "Building env specific OAS spec"
90+
make build-json-oas-spec APIM_ENV=${{ inputs.apimEnv }}
91+
fi
6192
62-
- name: Set docker tag
63-
shell: bash
64-
run: |
65-
jq --arg newtag "$SANDBOX_TAG" '.["x-nhsd-apim"].target.containers[0].image.tag = $newtag' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
93+
- name: Upload OAS Spec
94+
uses: actions/upload-artifact@v4
95+
with:
96+
name: ${{ inputs.apimEnv }}-build-output
97+
path: ./build
6698

67-
- name: Deploy to Internal Dev Sandbox
99+
- name: Trigger deploy proxy
100+
env:
101+
PR_TRIGGER_PAT: ${{ secrets.PR_TRIGGER_PAT }}
68102
shell: bash
69103
run: |
70-
proxygen instance deploy internal-dev-sandbox $INSTANCE build/notify-supplier.json --no-confirm
104+
#Change this back to proxy-deploy.yaml after testing
105+
.github/scripts/dispatch_internal_repo_workflow.sh \
106+
--infraRepoName "$(echo ${{ github.repository }} | cut -d'/' -f2)" \
107+
--internalRef "feature/CCM-11938_workflow" \
108+
--targetWorkflow "dispatch-deploy-notify-account-provisioning.yaml" \
109+
--targetEnvironment "${{ inputs.environment }}" \
110+
--runId "${{ inputs.runId }}" \
111+
--buildSandbox ${{ inputs.buildSandbox }} \
112+
--apimEnvironment "${{ inputs.apimEnv }}" \
113+
--boundedContext "notify-supplier" \
114+
--targetDomain "$TARGET_DOMAIN"
115+
116+
# - name: Set docker tag
117+
# shell: bash
118+
# run: |
119+
# jq --arg newtag "$SANDBOX_TAG" '.["x-nhsd-apim"].target.containers[0].image.tag = $newtag' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
120+
121+
# - name: Deploy to Internal Dev Sandbox
122+
# shell: bash
123+
# run: |
124+
# proxygen instance deploy internal-dev-${{ inputs.apimEnv }} $INSTANCE build/notify-supplier.json --no-confirm

.github/scripts/dispatch_internal_repo_workflow.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ while [[ $# -gt 0 ]]; do
6868
internalRef="$2"
6969
shift 2
7070
;;
71+
--runId) # Github Run ID (optional)
72+
runId="$2"
73+
shift 2
74+
;;
7175
--overrides) # Terraform overrides for passing in extra variables (optional)
7276
overrides="$2"
7377
shift 2
@@ -80,6 +84,10 @@ while [[ $# -gt 0 ]]; do
8084
overrideRoleName="$2"
8185
shift 2
8286
;;
87+
--buildSandbox) # Build sandbox flag (optional)
88+
buildSandbox="$2"
89+
shift 2
90+
;;
8391
*)
8492
echo "[ERROR] Unknown argument: $1"
8593
exit 1
@@ -101,6 +109,14 @@ if [[ -z "$internalRef" ]]; then
101109
internalRef="main"
102110
fi
103111

112+
if [[ -z "$runId" ]]; then
113+
runId="$GITHUB_RUN_ID"
114+
fi
115+
116+
if [[ -z "$buildSandbox" ]]; then
117+
buildSandbox=""
118+
fi
119+
104120
echo "==================== Workflow Dispatch Parameters ===================="
105121
echo " infraRepoName: $infraRepoName"
106122
echo " releaseVersion: $releaseVersion"
@@ -114,6 +130,8 @@ echo " overrides: $overrides"
114130
echo " overrideProjectName: $overrideProjectName"
115131
echo " overrideRoleName: $overrideRoleName"
116132
echo " targetProject: $targetProject"
133+
echo " runId: $runId"
134+
echo " buildSandbox: $buildSandbox"
117135

118136
DISPATCH_EVENT=$(jq -ncM \
119137
--arg infraRepoName "$infraRepoName" \
@@ -127,6 +145,8 @@ DISPATCH_EVENT=$(jq -ncM \
127145
--arg overrideProjectName "$overrideProjectName" \
128146
--arg overrideRoleName "$overrideRoleName" \
129147
--arg targetProject "$targetProject" \
148+
--arg runId "$runId" \
149+
--arg buildSandbox "$buildSandbox" \
130150
'{
131151
"ref": "'"$internalRef"'",
132152
"inputs": (
@@ -135,13 +155,13 @@ DISPATCH_EVENT=$(jq -ncM \
135155
(if $overrideProjectName != "" then { "overrideProjectName": $overrideProjectName } else {} end) +
136156
(if $overrideRoleName != "" then { "overrideRoleName": $overrideRoleName } else {} end) +
137157
(if $targetProject != "" then { "targetProject": $targetProject } else {} end) +
138-
{
139-
"releaseVersion": $releaseVersion,
140-
"targetEnvironment": $targetEnvironment,
141-
"targetAccountGroup": $targetAccountGroup,
142-
"targetComponent": $targetComponent,
143-
"overrides": $overrides,
144-
}
158+
(if $releaseVersion != "" then { "releaseVersion": $releaseVersion } else {} end) +
159+
(if $targetComponent != "" then { "targetComponent": $targetComponent } else {} end) +
160+
(if $overrides != "" then { "overrides": $overrides } else {} end) +
161+
(if $runId != "" then { "runId": $runId } else {} end) +
162+
(if $buildSandbox != "" then { "buildSandbox": $buildSandbox } else {} end) +
163+
{ "targetEnvironment": $targetEnvironment } +
164+
{ "targetAccountGroup": $targetAccountGroup }
145165
)
146166
}')
147167

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Deploy proxy to environment
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
environment:
7+
description: Name of the environment to deploy
8+
required: true
9+
type: choice
10+
options:
11+
- internal-dev
12+
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
deploy-environment:
19+
runs-on: ubuntu-latest
20+
name: Deploy to Environment
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- uses: actions/setup-node@v4
26+
with:
27+
node-version: 24
28+
29+
- name: Npm install
30+
working-directory: .
31+
run: npm ci
32+
shell: bash
33+
34+
- name: "Check if pull request exists for this branch"
35+
id: pr_exists
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
run: |
39+
branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')}
40+
echo "Current branch is '$branch_name'"
41+
42+
pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1)
43+
pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty')
44+
45+
if [[ -n "$pr_number" ]]; then
46+
echo "Pull request exists: #$pr_number"
47+
echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT
48+
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
49+
else
50+
echo "Pull request doesn't exist"
51+
echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT
52+
echo "pr_number=" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Set APIM_ENV
56+
shell: bash
57+
run: |
58+
if [ -z "${{ steps.pr_exists.outputs.pr_number }}" ]; then
59+
echo "APIM_ENV=${{ inputs.environment }}" >> $GITHUB_ENV
60+
else
61+
echo "APIM_ENV=${{ inputs.environment }}-pr" >> $GITHUB_ENV
62+
fi
63+
- name: Build environment oas
64+
working-directory: .
65+
shell: bash
66+
run: make build-json-oas-spec APIM_ENV=${{ env.APIM_ENV }}
67+
- name: "Build proxies"
68+
uses: ./.github/actions/build-proxies
69+
with:
70+
version: "${{ inputs.version }}"
71+
environment: "${{ env.APIM_ENV }}"
72+
apim_env: "${{ env.APIM_ENV }}"
73+
run_id: "${{ github.run_id }}"
74+
build_sandbox: false
75+
76+
# - name: Set target and cert
77+
# shell: bash
78+
# run: |
79+
# jq --arg newurl "$TARGET" '.["x-nhsd-apim"].target.url = $newurl' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
80+
# jq --arg newmtls "$MTLS_NAME" '.["x-nhsd-apim"].target.security.secret = $newmtls' build/notify-supplier.json > build/notify-supplier_target.json && mv build/notify-supplier_target.json build/notify-supplier.json
81+
82+
# - name: Deploy to Internal Dev
83+
# shell: bash
84+
# run: |
85+
# proxygen instance deploy internal-dev $INSTANCE build/notify-supplier.json --no-confirm

0 commit comments

Comments
 (0)