Skip to content

.github/workflows/build-and-release.yml #13

.github/workflows/build-and-release.yml

.github/workflows/build-and-release.yml #13

name: Deploy website
on:
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
set-vars:
runs-on: ubuntu-latest
outputs:
app-name: ${{ steps.export.outputs.app-name }}
ec2-instance-type: ${{ steps.export.outputs.ec2-instance-type }}
version: ${{ steps.export.outputs.version }}
runner-size: ${{ steps.export.outputs.runner-size }}
infra-config-repo: ${{ steps.export.outputs.infra-config-repo }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: main
- id: export
run: |
cd main
. ./.github/.github.env
echo "ec2-instance-type=${EC2_INSTANCE_TYPE}" >> $GITHUB_OUTPUT
echo "app-name=${APP_NAME}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "runner-size=${RUNNER_SIZE}" >> $GITHUB_OUTPUT
echo "infra-config-repo=${INFRA_CONFIG_REPO}" >> $GITHUB_OUTPUT
start-runner:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/start-runner.yml@main
needs: set-vars
with:
EC2_INSTANCE_TYPE: ${{ needs.set-vars.outputs.ec2-instance-type }}
RUNNER_SIZE: ${{ needs.set-vars.outputs.runner-size }}
ENVIRONMENT: dev
secrets:
AWS_GITHUBRUNNER_USER_ACCESS_KEY: ${{ secrets.AWS_GITHUBRUNNER_USER_ACCESS_KEY }}
AWS_GITHUBRUNNER_USER_SECRET_ID: ${{ secrets.AWS_GITHUBRUNNER_USER_SECRET_ID }}
AWS_GITHUBRUNNER_PAT: ${{ secrets.AWS_GITHUBRUNNER_PAT }}
AWS_REGION: ${{ secrets.AWS_REGION }}
publish-website:
runs-on: ${{ needs.start-runner.outputs.label }}
needs:
- set-vars
- start-runner
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install NPM
uses: actions/setup-node@v4
with:
node-version: latest
- name: Create .env
run: |
echo CONTENTFUL_SPACE="${{ secrets.CONTENTFUL_SPACE }}" >> .env
echo CONTENTFUL_ACCESS_TOKEN="${{ secrets.CONTENTFUL_ACCESS_TOKEN }}" >> .env
- name: NPM clean install
run: npm ci
- name: NPM build
run: npm run build --if-present
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: NPM run tests
run: |
npx playwright test
- name: Copy terraform logs to s3
run: |
cd _site
aws s3 cp . ${{ secrets.S3_BUCKET_LOCATION }} --recursive
notify-slack:
needs:
- set-vars
- start-runner
- publish-website
runs-on: ${{ needs.start-runner.outputs.label }}
steps:
- name: notify slack failure
id: slack-failure
uses: slackapi/[email protected]
if: ${{ failure() }}
with:
channel-id: 'C063JD08S6T'
payload: |
{
"text": "Failed to deploy",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Failed to deploy main to the ai gov uk website :aaaaaaaaaa:"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATIONS_TOKEN }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- name: notify slack pass
id: slack-pass
uses: slackapi/[email protected]
if: ${{ success() }}
with:
channel-id: 'C063JD08S6T'
payload: |
{
"text": "Deployment succeeded :airplane:",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "Deployed main to ai gov uk website :hype-elmo:"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_NOTIFICATIONS_TOKEN }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
stop-runner:
uses: i-dot-ai/i-dot-ai-core-github-actions/.github/workflows/stop-runner.yml@main
if: needs.start-runner.outputs.use-persisted == 0 && always()
needs:
- set-vars
- start-runner
- publish-website
- notify-slack
with:
RUNNER_LABEL: ${{ needs.start-runner.outputs.label }}
EC2_INSTANCE_ID: ${{ needs.start-runner.outputs.ec2-instance-id }}
secrets:
AWS_GITHUBRUNNER_USER_ACCESS_KEY: ${{ secrets.AWS_GITHUBRUNNER_USER_ACCESS_KEY }}
AWS_GITHUBRUNNER_USER_SECRET_ID: ${{ secrets.AWS_GITHUBRUNNER_USER_SECRET_ID }}
AWS_GITHUBRUNNER_PAT: ${{ secrets.AWS_GITHUBRUNNER_PAT}}
AWS_REGION: ${{ secrets.AWS_REGION }}