-
Notifications
You must be signed in to change notification settings - Fork 14
95 lines (83 loc) · 2.92 KB
/
deploy-to-environment.yaml
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
name: Deploy to environment
on:
workflow_call:
inputs:
environment_code:
required: true
type: string
environment_name:
required: true
type: string
environment_url:
required: true
type: string
deploy_self_hosted:
type: boolean
secrets:
AWS_REGION:
required: true
AWS_ROLE_TO_ASSUME:
required: true
BUCKET_NAME:
required: true
CLOUDFRONT_DISTRIBUTION_ID:
required: true
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment_name }}
url: ${{ inputs.environment_url }}
permissions:
contents: read
id-token: write
env:
DOC_ENV: ${{ inputs.environment_code }}
WP_OPTIONS_API_URL: ${{ vars.WP_OPTIONS_API_URL }}
RELEASE_BRANCH_NAME: ${{ inputs.environment_code == 'prod' && 'self-hosted-releases-prod' || 'self-hosted-releases-preprod' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout Self-Hosted Releases
if: ${{ inputs.deploy_self_hosted }}
uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_BRANCH_NAME }}
path: ${{ env.RELEASE_BRANCH_NAME }}
- name: Set Python up
uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install Material for MkDocs
run: pip install --requirement requirements.txt
# We need to remove any files that shouldn't be displayed in the SaaS section of the site before building
- name: Remove Self-Hosted specific files
run: ./scripts/remove-files-based-on-distribution.sh
env:
SPACELIFT_DISTRIBUTION: SAAS
- name: Build documentation
run: mkdocs build
- name: Copy self-hosted documentation
if: ${{ inputs.deploy_self_hosted }}
run: |
mkdir -p site/self-hosted
cp -r ${{ env.RELEASE_BRANCH_NAME }}/latest site/self-hosted
cp -r ${{ env.RELEASE_BRANCH_NAME }}/v* site/self-hosted
cp ${{ env.RELEASE_BRANCH_NAME }}/versions.json site/self-hosted
- name: Transform the URLs
run: python ./scripts/transform_urls.py
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
role-session-name: GitHubActionUserDocDeployment
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
- name: Copy files to the test website with the AWS CLI
run: aws s3 sync --delete --quiet ./site s3://${{ secrets.BUCKET_NAME }}
# KLUDGE: Clearing the whole cache is overkill but determining what items to invalidate is hard
- name: Invalidate CloudFront cache
run: |
aws cloudfront create-invalidation \
--distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \
--paths "/*"