|
| 1 | +name: Deploy proxy to internal-dev |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + deploy-internal-dev: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + name: Deploy to Internal Dev |
| 13 | + env: |
| 14 | + PROXYGEN_PRIVATE_KEY: ${{ secrets.PROXYGEN_ENCODED_NOTIFY_SUPPLIER_PRIVATE_KEY }} |
| 15 | + PROXYGEN_KID: notify-supplier-key-1 |
| 16 | + PROXYGEN_CLIENT_ID: nhs-notify-supplier-client |
| 17 | + PROXYGEN_API_NAME: nhs-notify-supplier |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: 24 |
| 25 | + |
| 26 | + - name: Npm install |
| 27 | + working-directory: . |
| 28 | + run: npm ci |
| 29 | + shell: bash |
| 30 | + |
| 31 | + - name: "Check if pull request exists for this branch" |
| 32 | + id: pr_exists |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + run: | |
| 36 | + branch_name=${GITHUB_HEAD_REF:-$(echo $GITHUB_REF | sed 's#refs/heads/##')} |
| 37 | + echo "Current branch is '$branch_name'" |
| 38 | +
|
| 39 | + pr_json=$(gh pr list --head "$branch_name" --state open --json number --limit 1) |
| 40 | + pr_number=$(echo "$pr_json" | jq -r '.[0].number // empty') |
| 41 | +
|
| 42 | + if [[ -n "$pr_number" ]]; then |
| 43 | + echo "Pull request exists: #$pr_number" |
| 44 | + echo "does_pull_request_exist=true" >> $GITHUB_OUTPUT |
| 45 | + echo "pr_number=$pr_number" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "Pull request doesn't exist" |
| 48 | + echo "does_pull_request_exist=false" >> $GITHUB_OUTPUT |
| 49 | + echo "pr_number=" >> $GITHUB_OUTPUT |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Setup Proxy Name and target |
| 53 | + shell: bash |
| 54 | + env: |
| 55 | + PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }} |
| 56 | + run: | |
| 57 | + if [ -z $PR_NUMBER ] |
| 58 | + then |
| 59 | + echo "INSTANCE=$PROXYGEN_API_NAME" >> $GITHUB_ENV |
| 60 | + echo "TARGET=https://main.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV |
| 61 | + echo "SANDBOX_TAG=latest" >> $GITHUB_ENV |
| 62 | + echo "MTLS_NAME=notify-supplier-mtls" >> $GITHUB_ENV |
| 63 | + else |
| 64 | + echo "TARGET=https://pr$PR_NUMBER.suppliers.dev.nhsnotify.national.nhs.uk" >> $GITHUB_ENV |
| 65 | + echo "INSTANCE=$PROXYGEN_API_NAME-PR-$PR_NUMBER" >> $GITHUB_ENV |
| 66 | + echo "SANDBOX_TAG=pr$PR_NUMBER" >> $GITHUB_ENV |
| 67 | + echo "MTLS_NAME=notify-supplier-mtls-pr$PR_NUMBER" >> $GITHUB_ENV |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Install Proxygen client |
| 71 | + shell: bash |
| 72 | + run: | |
| 73 | + # Install proxygen cli |
| 74 | + pip install pipx |
| 75 | + pipx install proxygen-cli |
| 76 | +
|
| 77 | + # Setup proxygen auth and settings |
| 78 | + mkdir -p ${HOME}/.proxygen |
| 79 | + echo -n $PROXYGEN_PRIVATE_KEY | base64 --decode > ${HOME}/.proxygen/key |
| 80 | + envsubst < ./.github/proxygen-credentials-template.yaml > ${HOME}/.proxygen/credentials.yaml |
| 81 | + envsubst < ./.github/proxygen-credentials-template.yaml | cat |
| 82 | + envsubst < ./.github/proxygen-settings.yaml > ${HOME}/.proxygen/settings.yaml |
| 83 | + envsubst < ./.github/proxygen-settings.yaml | cat |
| 84 | +
|
| 85 | + - name: Build internal dev oas |
| 86 | + working-directory: . |
| 87 | + shell: bash |
| 88 | + env: |
| 89 | + PR_NUMBER: ${{ steps.pr_exists.outputs.pr_number }} |
| 90 | + run: | |
| 91 | + if [ -z $PR_NUMBER ] |
| 92 | + then |
| 93 | + make build-json-oas-spec APIM_ENV=internal-dev |
| 94 | + else |
| 95 | + make build-json-oas-spec APIM_ENV=internal-dev-pr |
| 96 | + fi |
| 97 | +
|
| 98 | + - name: Set target and cert |
| 99 | + shell: bash |
| 100 | + run: | |
| 101 | + 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 |
| 102 | + 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 |
| 103 | +
|
| 104 | + - name: Deploy to Internal Dev |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + proxygen instance deploy internal-dev $INSTANCE build/notify-supplier.json --no-confirm |
0 commit comments