-
Notifications
You must be signed in to change notification settings - Fork 28
183 lines (161 loc) · 7.47 KB
/
scenario-test.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Scenario Tests - DC missions
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
permissions:
contents: read
issues: write
env:
# Credentials used by the Terraform script
BTP_USERNAME: ${{ secrets.BTP_USERNAME }}
BTP_PASSWORD: ${{ secrets.BTP_PASSWORD }}
CF_USER: ${{ secrets.BTP_USERNAME }}
CF_PASSWORD: ${{ secrets.BTP_PASSWORD }}
CUSTOM_IDP: ${{ secrets.CUSTOM_IDP }}
DEV_OVERRIDE: 'assets/provider-config-ghaction.txt'
jobs:
setup_infrastructure:
name: Test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
usecase:
- name: 'DC mission 4327'
folder: 'released/cicd/setup_subaccount_cf'
var_file: 'testsamples.tfvars'
use_custom_idp: false
steps:
- name: Check out Git repository
id: checkout_repo
uses: actions/checkout@v4
- name: Setup Terraform
id : setup_terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: latest
- name: Terraform Init
id: terraform_init
shell: bash
run: |
terraform -chdir=${{ matrix.usecase.folder }} init -no-color
- name: Terraform apply
id: terraform_apply
shell: bash
run: |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }}
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }}
export CF_USER=${{ secrets.BTP_USERNAME }}
export CF_PASSWORD=${{ secrets.BTP_PASSWORD }}
timestamp=$(date +"%Y%m%d%H%M%S")
sed -i "s/\(subaccount_name\s*=\s*\"\)[^\"]*\"/\1dcmtest_${timestamp}\"/" released/cicd/setup_subaccount_cf/testsamples.tfvars
sed -i "s/instance_name = \"my-cf-org-name\"/instance_name = \"cf-instance-$(($RANDOM % 9 + 1))\"/" released/cicd/setup_subaccount_cf/main.tf
sed -i '$a cf_org_user = ["dl_5731d5595f99b74a3c000020@exchange.sap.corp","DL_604F126B654D33027ECBD9B4@global.corp.sap"]' released/cicd/setup_subaccount_cf/testsamples.tfvars
sed -i '$a cf_space_manager = ["dl_5731d5595f99b74a3c000020@exchange.sap.corp","DL_604F126B654D33027ECBD9B4@global.corp.sap"]' released/cicd/setup_subaccount_cf/testsamples.tfvars
if [ "${{ matrix.usecase.use_custom_idp }}" = "true" ]
then
terraform -chdir=${{ matrix.usecase.folder }} apply -var-file="${{ matrix.usecase.var_file }}" -var "btp_user=${BTP_USERNAME}" -var "btp_pass=${BTP_PASSWORD}" -auto-approve -no-color
else
terraform -chdir=${{ matrix.usecase.folder }} apply -var-file="${{ matrix.usecase.var_file }}" -auto-approve -no-color
fi
- name: Terraform destroy
id: terraform_destroy
shell: bash
run: |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }}
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }}
export CF_USER=${{ secrets.BTP_USERNAME }}
export CF_PASSWORD=${{ secrets.BTP_PASSWORD }}
if [ ${{ matrix.usecase.use_custom_idp }} = true ]
then
terraform -chdir=${{ matrix.usecase.folder }} destroy -var-file='${{ matrix.usecase.var_file }}' -auto-approve -no-color
else
terraform -chdir=${{ matrix.usecase.folder }} destroy -var-file='${{ matrix.usecase.var_file }}' -auto-approve -no-color
fi
- name: Check out provider repository
id: checkout_provider_repo
uses: actions/checkout@v4
with:
repository: SAP/terraform-provider-btp
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Install local Terraform provider
id: build_provider
shell: bash
run: |
go mod tidy && make install
- name: Remove init data and place override
id: set_to_override
shell: bash
run: |
rm -rf .terraform && rm -rf .terraform.lock.hcl && cp ${{ env.DEV_OVERRIDE }} ~/.terraformrc
- name: Check out Github repository
id: checkout_github_repo
uses: actions/checkout@v4
- name: Terraform Init
id: init_terraform
shell: bash
run: |
terraform -chdir=${{ matrix.usecase.folder }} init -no-color
- name: Terraform apply for local provider
id: terraform_apply_against_local_provider
shell: bash
run: |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }}
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }}
export CF_USER=${{ secrets.BTP_USERNAME }}
export CF_PASSWORD=${{ secrets.BTP_PASSWORD }}
timestamp=$(date +"%Y%m%d%H%M%S")
sed -i "s/\(subaccount_name\s*=\s*\"\)[^\"]*\"/\1dcmtest_${timestamp}\"/" released/cicd/setup_subaccount_cf/testsamples.tfvars
sed -i '$a cf_org_user = ["dl_5731d5595f99b74a3c000020@exchange.sap.corp","DL_604F126B654D33027ECBD9B4@global.corp.sap"]' released/cicd/setup_subaccount_cf/testsamples.tfvars
sed -i '$a cf_space_manager = ["dl_5731d5595f99b74a3c000020@exchange.sap.corp","DL_604F126B654D33027ECBD9B4@global.corp.sap"]' released/cicd/setup_subaccount_cf/testsamples.tfvars
if [ "${{ matrix.usecase.use_custom_idp }}" = "true" ]
then
terraform -chdir=${{ matrix.usecase.folder }} apply -var-file="${{ matrix.usecase.var_file }}" -var "btp_user=${BTP_USERNAME}" -var "btp_pass=${BTP_PASSWORD}" -auto-approve -no-color
else
terraform -chdir=${{ matrix.usecase.folder }} apply -var-file="${{ matrix.usecase.var_file }}" -auto-approve -no-color
fi
- name: Terraform destroy for local provider
id: terraform_destroy_against_local_provider
shell: bash
run: |
export BTP_USERNAME=${{ secrets.BTP_USERNAME }}
export BTP_PASSWORD=${{ secrets.BTP_PASSWORD }}
export CF_USER=${{ secrets.BTP_USERNAME }}
export CF_PASSWORD=${{ secrets.BTP_PASSWORD }}
if [ ${{ matrix.usecase.use_custom_idp }} = true ]
then
terraform -chdir=${{ matrix.usecase.folder }} destroy -auto-approve -no-color
else
terraform -chdir=${{ matrix.usecase.folder }} destroy -var-file='${{ matrix.usecase.var_file }}' -auto-approve -no-color
fi
create_issue_on_failure:
runs-on: ubuntu-latest
needs: setup_infrastructure
if: ${{ always() && (needs.setup_infrastructure.result == 'failure') }}
steps:
- name: Create issue
uses: actions/github-script@v7
with:
script: |
const issueTitle = `Automated Issue Alert: DC Missions Scenario Tests Failure`;
const issueBody = `
## Failure Report
**Workflow:** [${process.env.GITHUB_WORKFLOW}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
**Run Number:** ${process.env.GITHUB_RUN_NUMBER}
**Trigger:** ${process.env.GITHUB_EVENT_NAME}
### Description
The DC mission scenario-tests workflow has failed during the ${process.env.GITHUB_EVENT_NAME} event. Please review the details linked above and investigate the root cause.
### Suggested Action
- Review the complete logs at the provided link.
`;
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody
});