forked from TaskingAI/TaskingAI
-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (154 loc) · 5.88 KB
/
test-plugin.yml
File metadata and controls
176 lines (154 loc) · 5.88 KB
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
name: Plugin - Build and Test
on:
pull_request_target:
branches: ["master"]
paths:
- "plugin/**"
- ".github/workflows/test-plugin.yml"
- "!**.md"
- "!**.svg"
- "!**.jpg"
- "!**.png"
env:
WORK_DIR: plugin
AES_ENCRYPTION_KEY: b90e4648ad699c3bdf62c0860e09eb9efc098ee75f215bf750847ae19d41e4b0
permissions:
contents: read
jobs:
build-and-test:
runs-on: ubuntu-latest
environment: test
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
repository: ${{ github.repository }}
- name: Checkout forked repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
path: fork
- name: Set working directory
run: echo "WORKING_DIRECTORY=fork/${{ env.WORK_DIR }}" >> $GITHUB_ENV
- name: Get list of changed files
id: files
run: |
cd ${{ env.WORKING_DIRECTORY }}
git fetch origin +${{ github.event.pull_request.base.sha }}:refs/remotes/origin/pr-base +${{ github.event.pull_request.head.sha }}:refs/remotes/origin/pr-head
git diff --name-only origin/pr-base origin/pr-head > /tmp/changed_files.txt
echo "CHANGED_FILES<<EOF" >> $GITHUB_ENV
cat /tmp/changed_files.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "::set-output name=changed_files::$(cat /tmp/changed_files.txt)"
- name: Set short SHA for image tag
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV
- name: Check for git tag version
run: |
cd ${{ env.WORKING_DIRECTORY }}
TAG=$(git describe --tags --exact-match 2> /dev/null || echo "")
if [[ -n "$TAG" ]]; then
echo "IMAGE_TAG=${TAG}" >> $GITHUB_ENV
fi
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install Dependencies
run: |
cd ${{ env.WORKING_DIRECTORY }}
pip install -r requirements.txt
- name: Build Docker image
run: |
cd ${{ env.WORKING_DIRECTORY }}
docker build -t taskingai/taskingai-plugin:$IMAGE_TAG .
echo "Build success: taskingai/taskingai-plugin:${IMAGE_TAG}"
- name: Run Local Docker image
env:
PLUGIN_BUNDLE_CREDENTIALS: ${{ secrets.PLUGIN_BUNDLE_CREDENTIALS }}
AES_ENCRYPTION_KEY: ${{ env.AES_ENCRYPTION_KEY }}
TEST_S3_SECRET_R2: ${{ secrets.TEST_S3_SECRET_R2 }}
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "$PLUGIN_BUNDLE_CREDENTIALS" > .env
echo "$TEST_S3_SECRET_R2" >> .env
docker run -d --name test_container --network=host \
--env-file .env \
-e PATH_TO_VOLUME=./test \
-e HOST_URL=http://localhost:8030 \
-e OBJECT_STORAGE_TYPE=local \
-e AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
taskingai/taskingai-plugin:$IMAGE_TAG
sleep 10 # Wait for service to start
- name: Run Tests
run: |
cd ${{ env.WORKING_DIRECTORY }}
bash ./test/run_test.sh /tmp/changed_files.txt
- name: Run Local Tests
run: |
cd ${{ env.WORKING_DIRECTORY }}
export PATH_TO_VOLUME=./test
export HOST_URL=http://localhost:8030
bash ./test/run_local_test.sh
- name: Stop Docker container
run: |
cd ${{ env.WORKING_DIRECTORY }}
docker stop test_container
sleep 5
- name: Run S3 without public domain Docker image
env:
PLUGIN_BUNDLE_CREDENTIALS: ${{ secrets.PLUGIN_BUNDLE_CREDENTIALS }}
AES_ENCRYPTION_KEY: ${{ env.AES_ENCRYPTION_KEY }}
TEST_S3_SECRET_AWS: ${{ secrets.TEST_S3_SECRET_AWS }}
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "$PLUGIN_BUNDLE_CREDENTIALS" > 1.env
echo "$TEST_S3_SECRET_AWS" >> 1.env
docker run -d --name aws_s3_docker --network=host \
--env-file 1.env \
-e PATH_TO_VOLUME="./test" \
-e OBJECT_STORAGE_TYPE="s3" \
-e PROJECT_ID="taskingai" \
-e AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
taskingai/taskingai-plugin:$IMAGE_TAG
sleep 5 # Wait for service to start
- name: Run S3 without public domain Tests
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "$TEST_S3_SECRET_AWS" > .env
bash ./test/run_s3_without_test.sh
- name: Stop Docker container
run: |
cd ${{ env.WORKING_DIRECTORY }}
docker stop aws_s3_docker
sleep 5
- name: Run S3 with public domain Docker image
env:
PLUGIN_BUNDLE_CREDENTIALS: ${{ secrets.PLUGIN_BUNDLE_CREDENTIALS }}
AES_ENCRYPTION_KEY: ${{ env.AES_ENCRYPTION_KEY }}
TEST_S3_SECRET_R2: ${{ secrets.TEST_S3_SECRET_R2 }}
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "$PLUGIN_BUNDLE_CREDENTIALS" > 2.env
echo "$TEST_S3_SECRET_R2" >> 2.env
docker run -d --name r2_docker --network=host \
--env-file 2.env \
-e PATH_TO_VOLUME="./test" \
-e OBJECT_STORAGE_TYPE="s3" \
-e PROJECT_ID="taskingai" \
-e AES_ENCRYPTION_KEY=$AES_ENCRYPTION_KEY \
taskingai/taskingai-plugin:$IMAGE_TAG
sleep 5 # Wait for service to start
- name: Run S3 with public domain Tests
run: |
cd ${{ env.WORKING_DIRECTORY }}
echo "$TEST_S3_SECRET_R2" > .env
bash ./test/run_s3_with_test.sh
- name: Stop Docker container
run: |
cd ${{ env.WORKING_DIRECTORY }}
docker stop r2_docker
sleep 5