-
Notifications
You must be signed in to change notification settings - Fork 0
149 lines (123 loc) · 5.32 KB
/
deployment.yml
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: 'Deployment'
# Only trigger, when the build workflow succeeded
on:
# workflow_run:
# workflows: ["PHP Code Analysis"]
# types:
# - completed
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-20.04
outputs:
ip: ${{ steps.expose_ip.outputs.ip}}
steps:
# Configure AWS credentials
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
mask-aws-account-id: true
# Checkout plugin-infrastructure repository to the GitHub Actions runner
- uses: actions/checkout@v4
with:
repository: AltaPay/plugin-infrastructure
token: ${{ secrets.ACCESS_TOKEN }}
ref: 'main'
# Install version 1.0.8 of Terraform CLI
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.0.8
# Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc.
- name: Terraform Init
run: terraform init
working-directory: provision/plugins
# Select a Terraform workspace
- name: Terraform workspace
run: terraform workspace select wordpress
working-directory: provision/plugins
# Generates an execution plan for Terraform
- name: Terraform Plan
run: terraform plan
working-directory: provision/plugins
# Run Terraform Apply
# On push to main, build or change infrastructure according to Terraform configuration files
# Note: It is recommended to set up a required "strict" status check in your repository for "Terraform Cloud". See the documentation on "strict" required status checks for more information: https://help.github.com/en/github/administering-a-repository/types-of-required-status-checks
- name: Terraform Apply
#if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -var ec2_type=t3.micro -auto-approve
working-directory: provision/plugins
# Add a sleep of 20 seconds, in case instance needs to warm up
- name: Sleep for 20 seconds
uses: jakejarvis/wait-action@master
with:
time: '20s'
# Setting branch name for running cypress tests
- name: Set env TEST_BRANCH_NAME
run: |
if [[ $GITHUB_EVENT_NAME == 'pull_request' ]]; then
echo "TEST_BRANCH_NAME=${{ github.head_ref }}" >> "$GITHUB_ENV"
else
echo "TEST_BRANCH_NAME=main" >> "$GITHUB_ENV"
fi
#Run Ansible playbook
- name: Run playbook
uses: dawidd6/action-ansible-playbook@v2
with:
playbook: wordpress.yml
directory: deploy/plugins
key: ${{secrets.SSHKEY}}
options: |
-u ubuntu
-i inventory
--extra-vars "branch_name=${{env.TEST_BRANCH_NAME}} gatewayURL=${{ secrets.GATEWAYURL }} gatewayUser=${{ secrets.GATEWAYUSER }} gatewayPass=${{ secrets.GATEWAYPASS }} wp_user=${{secrets.CMS_ADMIN_USER}} wp_pass=${{secrets.CMS_ADMIN_PASS}} wp_email=${{secrets.CMS_ADMIN_EMAIL}}"
# Export IP for use in cypress tests config
- name: Export IP
run: |
testvar=$(sed '4!d' inventory)
echo $testvar
echo "IP=$testvar">> $GITHUB_ENV
echo $IP
working-directory: deploy/plugins
- name: Expose IP
id: expose_ip
run: echo "ip=${{ env.IP }}" >> $GITHUB_OUTPUT
cypress:
name: 'Cypress'
runs-on: ubuntu-latest
needs: terraform
steps:
# Run Cypress tests
- uses: actions/checkout@v4
with:
ref: '${{env.TEST_BRANCH_NAME}}'
- name: Create Cypress fixture config json
id: create-json-2 # Second ID
uses: jsdaniell/create-json@v1.2.2
with:
name: "config.json"
json: '{"shopURL": "http://${{ needs.terraform.outputs.ip }}/wordpress","adminURL": "http://${{ needs.terraform.outputs.ip }}/wordpress/wp-admin","adminUsername": "${{secrets.CMS_ADMIN_USER}}","adminPass": "${{secrets.CMS_ADMIN_PASS}}", "CC_TERMINAL_NAME": "${{secrets.CC_TERMINAL_NAME}}", "KLARNA_DKK_TERMINAL_NAME": "${{secrets.KLARNA_DKK_TERMINAL_NAME}}", "iDEAL_EUR_TERMINAL": "${{secrets.IDEAL_EUR_TERMINAL_NAME}}"}'
dir: "tests/integration-test/cypress/fixtures/"
- name: Install Cypress
run: npm i
working-directory: "tests/integration-test"
- name: Run Cypress tests
run: ./node_modules/.bin/cypress run --config video=false
working-directory: "tests/integration-test"
# after the test run completes
# store screenshots
# NOTE: screenshots will be generated only if E2E test failed
- uses: actions/upload-artifact@v3
if: failure() || true
with:
name: cypress-screenshots
path: "./tests/integration-test/cypress/screenshots"
if-no-files-found: ignore