-
Notifications
You must be signed in to change notification settings - Fork 2
83 lines (80 loc) · 3.19 KB
/
publish.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
name: Publish
on:
workflow_dispatch:
push:
branches:
- master
pull_request:
concurrency:
cancel-in-progress: false
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
publish:
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: GitHub Slug Action
uses: rlespinasse/github-slug-action@v4
- name: Generate Domain Name
id: generate_domain_name
uses: actions/github-script@v6
with:
result-encoding: string
script: |
if (context.payload.ref == 'refs/heads/master') {
return 'horde-ng.org';
}
return process.env.GITHUB_REF_NAME_SLUG_URL + '.dev.horde-ng.org';
- name: Generate SLS Stage
id: generate_sls_stage
uses: actions/github-script@v6
with:
result-encoding: string
script: |
if (context.payload.ref == 'refs/heads/master') {
return 'prod';
}
return process.env.GITHUB_REF_NAME_SLUG_URL;
- name: Checkout code
uses: actions/checkout@v4
- name: Setup prod dependencies
run: yarn install
- name: Deploy infrastructure
uses: serverless/github-action@v3
with:
args: deploy --stage ${{ steps.generate_sls_stage.outputs.result }} --verbose
env:
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DOMAIN_ZONE: ${{ secrets.APP_DOMAIN_HOSTED_ZONE }}
DOMAIN_NAME: ${{ steps.generate_domain_name.outputs.result }}
- name: Create runtime version
run: echo "window['APP_VERSION'] = '$GITHUB_SHA';" >> src/assets/runtime-variables.js
- name: Build app
run: ./node_modules/.bin/ng build
- name: Copy files to S3
env:
STACK_NAME: HordeNG-${{ steps.generate_sls_stage.outputs.result }}
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
BUCKET=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='Bucket'].OutputValue" --output=text)
aws s3 sync dist/horde-gui/browser s3://$BUCKET --delete
- name: Create invalidation
env:
STACK_NAME: HordeNG-${{ steps.generate_sls_stage.outputs.result }}
AWS_REGION: eu-central-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
CDN_ID=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --query "Stacks[0].Outputs[?OutputKey=='Cdn'].OutputValue" --output=text)
aws cloudfront create-invalidation --distribution-id $CDN_ID --paths "/*" 2>&1 > /dev/null
- name: Post Link
uses: thollander/actions-comment-pull-request@v2
if: github.event_name == 'pull_request'
with:
message: This pull request has been deployed to https://${{ steps.generate_domain_name.outputs.result }}
comment_tag: post_link_comment