-
Notifications
You must be signed in to change notification settings - Fork 5
184 lines (155 loc) · 5.17 KB
/
ci.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
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
184
name: ci
permissions:
contents: write
issues: write
pull-requests: write
on:
pull_request:
branches-ignore: [ "dev/*" ]
# push:
# branches: [ "master" ]
env:
TF_VAR_ssh_private_key: ${{ secrets.CI_SSH_KEY }}
TF_VAR_linode_token: ${{ secrets.CI_LINODE_TOKEN }}
TF_VAR_root_password: ${{ secrets.CI_ROOT_PASSWORD }}
TF_DIR: "./tests/e2e"
TF_VAR_git_repository: "${{ github.event.pull_request.head.repo.full_name }}"
TF_VAR_git_commit_sha: "${{ github.sha }}"
TF_VAR_git_ref_name: "${{ github.event.pull_request.head.ref }}"
TV_VAR_artifact_dir: "/tmp/artifacts"
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.1.7"
- name: terraform init
working-directory: "${{ env.TF_DIR }}"
run: terraform init
- name: terraform plan
working-directory: "${{ env.TF_DIR }}"
run: terraform plan
- name: terraform apply
working-directory: "${{ env.TF_DIR }}"
run: terraform apply -auto-approve
- name: set CI_INSTANCE_IP variable
working-directory: "${{ env.TF_DIR }}"
run: |
echo "CI_INSTANCE_IP=$(cat terraform.tfstate | jq -r '.outputs.ci_instance_ip.value')" >> $GITHUB_ENV
- name: show CI_INSTANCE_IP
run: |
echo $CI_INSTANCE_IP
- name: run pytests
uses: appleboy/[email protected]
with:
host: ${{ env.CI_INSTANCE_IP }}
username: ci
key: ${{ secrets.CI_SSH_KEY }}
command_timeout: 60m
script: |
test -d ${{ env.TV_VAR_artifact_dir }} && rm -rfv ${{ env.TV_VAR_artifact_dir }}
mkdir -p ${{ env.TV_VAR_artifact_dir }}
echo 0 > ${{ env.TV_VAR_artifact_dir }}/exit_code
test -d ~/.kube || mkdir ~/.kube
test -d mindwm-gitops && rm -rf mindwm-gitops
git clone -b "${{ github.event.pull_request.head.ref }}" https://github.com/${{ github.event.pull_request.head.repo.full_name }}
cd mindwm-gitops
export KUBECONFIG=${HOME}/.kube/config
make mindwm_test
echo $? > ${{ env.TV_VAR_artifact_dir }}/exit_code
cd ${{ env.TV_VAR_artifact_dir }}
tar cvf /tmp/artifacts.tar .
- name: Download artifacts
uses: nicklasfrahm/scp-action@main
if: always()
continue-on-error: true
with:
direction: download
host: ${{ env.CI_INSTANCE_IP }}
insecure_ignore_fingerprint: true
username: ci
key: ${{ secrets.CI_SSH_KEY }}
source: /tmp/artifacts.tar
target: artifacts.tar
- name: Unpack artifacts
if: always()
continue-on-error: true
run: |
mkdir artifacts
tar xvf artifacts.tar -C artifacts
- name: Load test report history
uses: actions/checkout@v4
if: always()
continue-on-error: true
with:
token: ${{ secrets.MINDWM_TOKEN }}
repository: 'mindwm/mindwm.github.io'
ref: main
path: gh-pages
# - name: List 1
# run: |
# find .
- name: Build test report
uses: simple-elf/[email protected]
if: always()
with:
gh_pages: gh-pages/mindwm-gitops
allure_history: allure-history
allure_report: allure-report
allure_results: artifacts/allure-results
# - name: List 2
# run: |
# find .
- name: git commit workaround
run: |
sudo rm -rf mindwm-gitops/allure-history/.git
- name: Update mindwm.github.io
id: update_mindwm_github_io
uses: cpina/github-action-push-to-another-repository@target-branch
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
source-directory: allure-history
destination-github-username: 'mindwm'
destination-repository-name: 'mindwm.github.io'
user-email: [email protected]
commit-message: See ORIGIN_COMMIT from $GITHUB_REF
target-branch: main
target-directory: /mindwm-gitops
- name: prepare env variable for report.md
run: |
echo "REPORT_MD<<EOF" >> $GITHUB_ENV
echo "[allure report](https://mindwm.github.io/mindwm-gitops/${{ github.run_number }})" >> $GITHUB_ENV
echo '```'
grep -vE '^features' artifacts/report.md >> $GITHUB_ENV
echo '```'
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v7
env:
COMMENT_BODY: ${{env.REPORT_MD}}
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.COMMENT_BODY
})
- name: return exit code
run: |
exit `cat artifacts/exit_code`
- name: terraform destroy
if: always()
working-directory: "${{ env.TF_DIR }}"
run: terraform destroy -auto-approve