Skip to content

Commit 9c5c3aa

Browse files
committed
eja - experimenting with slack webhook
1 parent 9e9b679 commit 9c5c3aa

1 file changed

Lines changed: 44 additions & 107 deletions

File tree

Lines changed: 44 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
# Description: Deploys merged code to the dev environment.
2-
# Triggered on push to main. Tags the commit with a dev-<timestamp> label.
3-
# Does not create GitHub Releases or production tags (v1.x.x).
4-
51
name: "CI/CD publish"
62

73
on:
8-
push:
4+
pull_request:
5+
types: [closed]
96
branches:
107
- main
118

129
jobs:
1310
metadata:
1411
name: "Set CI/CD metadata"
1512
runs-on: ubuntu-latest
13+
if: github.event.pull_request.merged == true
1614
timeout-minutes: 1
1715
outputs:
1816
build_datetime: ${{ steps.variables.outputs.build_datetime }}
@@ -25,7 +23,6 @@ jobs:
2523
steps:
2624
- name: "Checkout code"
2725
uses: actions/checkout@v4
28-
2926
- name: "Set CI/CD variables"
3027
id: variables
3128
run: |
@@ -36,120 +33,60 @@ jobs:
3633
echo "nodejs_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
3734
echo "python_version=$(grep "^nodejs" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
3835
echo "terraform_version=$(grep "^terraform" .tool-versions | cut -f2 -d' ')" >> $GITHUB_OUTPUT
39-
echo "version=dev-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
40-
36+
# TODO: Get the version, but it may not be the .version file as this should come from the CI/CD Pull Request Workflow
37+
echo "version=$(head -n 1 .version 2> /dev/null || echo unknown)" >> $GITHUB_OUTPUT
4138
- name: "List variables"
4239
run: |
43-
echo "Deploying to: DEV"
44-
echo "VERSION=${{ steps.variables.outputs.version }}"
45-
40+
export BUILD_DATETIME="${{ steps.variables.outputs.build_datetime }}"
41+
export BUILD_TIMESTAMP="${{ steps.variables.outputs.build_timestamp }}"
42+
export BUILD_EPOCH="${{ steps.variables.outputs.build_epoch }}"
43+
export NODEJS_VERSION="${{ steps.variables.outputs.nodejs_version }}"
44+
export PYTHON_VERSION="${{ steps.variables.outputs.python_version }}"
45+
export TERRAFORM_VERSION="${{ steps.variables.outputs.terraform_version }}"
46+
export VERSION="${{ steps.variables.outputs.version }}"
47+
make list-variables
4648
publish:
47-
name: "Publish to dev"
49+
name: "Publish packages"
4850
runs-on: ubuntu-latest
4951
needs: [metadata]
50-
timeout-minutes: 10
51-
environment: "dev"
52-
permissions:
53-
id-token: write
54-
contents: read
52+
if: github.event.pull_request.merged == true
53+
timeout-minutes: 3
5554
steps:
56-
- name: "Setup Terraform"
57-
uses: hashicorp/setup-terraform@v3
58-
with:
59-
terraform_version: ${{ needs.metadata.outputs.terraform_version }}
60-
61-
- name: "Set up Python"
62-
uses: actions/setup-python@v5
63-
with:
64-
python-version: '3.13'
65-
66-
- name: "Checkout Repository"
55+
- name: "Checkout code"
6756
uses: actions/checkout@v4
68-
69-
- name: "Build lambda artefact"
57+
- name: "Get the artefacts"
7058
run: |
71-
make dependencies install-python
72-
make build
73-
74-
- name: "Upload lambda artefact"
75-
uses: actions/upload-artifact@v4
76-
with:
77-
name: lambda
78-
path: dist/lambda.zip
79-
80-
- name: "Download Built Lambdas"
81-
uses: actions/download-artifact@v4
82-
with:
83-
name: lambda
84-
path: ./build
85-
86-
- name: "Configure AWS Credentials"
87-
uses: aws-actions/configure-aws-credentials@v4
88-
with:
89-
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/service-roles/github-actions-api-deployment-role
90-
aws-region: eu-west-2
91-
92-
- name: "Terraform Plan Stacks"
59+
echo "Getting the artefacts created by the build stage ..."
60+
# TODO: Use either action/cache or action/upload-artifact
61+
- name: "Create release"
62+
id: create_release
63+
uses: actions/create-release@v1
9364
env:
94-
ENVIRONMENT: dev
95-
WORKSPACE: "default"
96-
TF_VAR_API_CA_CERT: ${{ secrets.API_CA_CERT }}
97-
TF_VAR_API_CLIENT_CERT: ${{ secrets.API_CLIENT_CERT }}
98-
TF_VAR_API_PRIVATE_KEY_CERT: ${{ secrets.API_PRIVATE_KEY_CERT }}
99-
100-
# just planning for now for safety and until review
101-
run: |
102-
mkdir -p ./build
103-
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=networking tf-command=plan"
104-
make terraform env=$ENVIRONMENT stack=networking tf-command=plan workspace=$WORKSPACE
105-
echo "Running: make terraform env=$ENVIRONMENT workspace=$WORKSPACE stack=api-layer tf-command=plan"
106-
make terraform env=$ENVIRONMENT stack=api-layer tf-command=plan workspace=$WORKSPACE
107-
working-directory: ./infrastructure
108-
109-
- name: "Tag the dev deployment"
110-
run: |
111-
git config user.name "github-actions"
112-
git config user.email "github-actions@github.com"
113-
git tag ${{ needs.metadata.outputs.version }}
114-
git push origin ${{ needs.metadata.outputs.version }}
115-
116-
# --- Keeping these just in case: Uncomment to release to GitHub ---
117-
# - name: "Create release"
118-
# id: create_release
119-
# uses: actions/create-release@v1
120-
# env:
121-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122-
# with:
123-
# tag_name: ${{ needs.metadata.outputs.version }}
124-
# release_name: Release ${{ needs.metadata.outputs.version }}
125-
# body: |
126-
# Release of ${{ needs.metadata.outputs.version }}
127-
# draft: false
128-
# prerelease: true
129-
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
with:
67+
tag_name: ${{ needs.metadata.outputs.version }}
68+
release_name: Release ${{ needs.metadata.outputs.version }}
69+
body: |
70+
Release of ${{ needs.metadata.outputs.version }}
71+
draft: false
72+
prerelease: false
13073
# - name: "Upload release asset"
13174
# uses: actions/upload-release-asset@v1
13275
# env:
13376
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13477
# with:
13578
# upload_url: "${{ steps.create_release.outputs.upload_url }}"
136-
# asset_path: ./build/lambda.zip
137-
# asset_name: lambda-${{ needs.metadata.outputs.version }}.zip
138-
# asset_content_type: application/zip
139-
success:
140-
name: "Success notification"
141-
runs-on: ubuntu-latest
142-
needs: [publish]
143-
steps:
144-
- name: "Check prerequisites for notification"
145-
id: check
146-
run: echo "secret_exist=${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL != '' }}" >> $GITHUB_OUTPUT
147-
- name: "Notify on publishing packages"
148-
if: steps.check.outputs.secret_exist == 'true'
149-
uses: nhs-england-tools/notify-msteams-action@v1.0.0
79+
# asset_path: ./*
80+
# asset_name: repository-template-${{ needs.metadata.outputs.version }}.tar.gz
81+
# asset_content_type: "application/gzip"
82+
- name: "Notify Slack on PR merge"
83+
uses: slackapi/slack-github-action@v2.1.0
15084
with:
151-
github-token: ${{ secrets.GITHUB_TOKEN }}
152-
teams-webhook-url: ${{ secrets.TEAMS_NOTIFICATION_WEBHOOK_URL }}
153-
message-title: "Notification title"
154-
message-text: "This is a notification body"
155-
link: ${{ github.event.pull_request.html_url }}
85+
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
86+
webhook-type: webhook-trigger
87+
payload: |
88+
status: "${{ job.status }}"
89+
link: "${{ github.event.pull_request.html_url }}"
90+
Author: "${{ github.event.pull_request.user.login }}"
91+
title: "${{ github.event.pull_request.title }}"
92+
version: "${{ needs.metadata.outputs.version }}"

0 commit comments

Comments
 (0)