-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
207 lines (168 loc) · 7.9 KB
/
Copy pathaction.yml
File metadata and controls
207 lines (168 loc) · 7.9 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# Copyright 2023 Rezilion
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Rezilion Validate V2.15.1
name: 'Rezilion'
description: 'Rezilion for github'
inputs:
mode:
description: 'Rezilion CI mode'
required: true
command:
description: 'User command to validate'
required: false
default: ""
image_name:
description: 'Image name to validate'
required: false
default: ""
runs:
using: "composite"
steps:
- if: ${{ (inputs.mode != 'start') && (inputs.mode != 'validate') && (inputs.mode != 'sca') }}
run: |
echo "Ran Rezilion with bad mode! Possible options: 'start|sca'"
echo "Please check https://rezilion.my.site.com/support/s/article/Rezilion-in-GitHub-User-Guide-Part-One for more info"
false
shell: sh
- if: ${{ (inputs.mode == 'start') || (inputs.mode == 'validate') || (inputs.mode == 'sca') }}
run: |
REZILION_EXECUTABLE_URL="https://rezilion-ci-us-storage.s3.amazonaws.com/instrument/2.15.1/validate_ci_agent"
REZILION_OUTPUTS_FOLDER=/tmp/rezilion/outputs
REZILION_AGENT_PATH=/tmp/rezilion/validate_ci_agent
if [ -f /etc/alpine-release ] ; then
REZILION_EXECUTABLE_URL="https://rezilion-ci-us-storage.s3.amazonaws.com/instrument/2.15.1/validate_ci_alpine_agent"
fi
mkdir -p $REZILION_OUTPUTS_FOLDER
# curl isn't installed
if ! command -v curl > /dev/null 2>&1 && ! command -v wget > /dev/null 2>&1 ; then
# install curl with apt-get
if command -v apt-get > /dev/null 2>&1 ; then
apt-get update
apt-get install curl -y
# install curl with yum
elif command -v yum > /dev/null 2>&1 ; then
yum install curl -y
# install curl with apk
elif command -v apk > /dev/null 2>&1 ; then
apk add curl
else
echo "Impossible to install Rezilion without curl"
exit 1
fi
fi
if command -v curl > /dev/null 2>&1 ; then
curl -s $REZILION_EXECUTABLE_URL --output $REZILION_AGENT_PATH
elif command -v wget > /dev/null 2>&1 ; then
wget -q $REZILION_EXECUTABLE_URL -O $REZILION_AGENT_PATH
else
echo "Impossible to install Rezilion without curl or wget. Please install it and try again."
exit 1
fi
chmod +x $REZILION_AGENT_PATH || true
shell: sh
- if: ${{ (inputs.mode == 'start') }}
run: |
REZILION_OUTPUTS_FOLDER=/tmp/rezilion/outputs
REZILION_AGENT_PATH=/tmp/rezilion/validate_ci_agent
STOP_MINING_FLAG_FILE_PATH=/tmp/rezilion/stop_mining
MINERS_LOG_PATH="$REZILION_OUTPUTS_FOLDER"/"$GITHUB_JOB"/"$GITHUB_JOB"_miners.log
AGENT_STDOUT_OUTPUT_PATH="/tmp/rezilion_agent.logs"
USER_COMMAND_PATH=/tmp/rezilion/command.sh
if [ -f $STOP_MINING_FLAG_FILE_PATH ]; then
rm $STOP_MINING_FLAG_FILE_PATH
fi
if [ -f $USER_COMMAND_PATH ]; then
rm $USER_COMMAND_PATH
fi
cat << REZILIONEOFTOKEN > $USER_COMMAND_PATH
${{ inputs.command }}
REZILIONEOFTOKEN
if [ $(wc -c <"$USER_COMMAND_PATH") -eq 1 ]; then
echo "Missing 'command' parameter for rezilion start, not running Rezilion..."
exit 1
fi
chmod +x $USER_COMMAND_PATH
cat "$USER_COMMAND_PATH"
RUN_REZILION_CMDLINE="$REZILION_AGENT_PATH --log-path $MINERS_LOG_PATH --license-key "$REZILION_LICENSE_KEY" --ci-environment github miners --current-job-name $GITHUB_JOB --miners-directory $REZILION_OUTPUTS_FOLDER --stop-dynamic-mining-flag-path $STOP_MINING_FLAG_FILE_PATH --shell-command-to-mine $USER_COMMAND_PATH --shell-command-output-file-path /tmp/rezilion/shell_command_output --shell-command-exit-code-file-path /tmp/rezilion/shell_command_exit_code"
if [ ! -z "${{ inputs.image_name }}" ]; then
RUN_REZILION_CMDLINE="$RUN_REZILION_CMDLINE --container-image-name "${{ inputs.image_name }}""
fi
$RUN_REZILION_CMDLINE >> "$AGENT_STDOUT_OUTPUT_PATH" 2>&1 || REZILION_FAILED_RUNNING=1
if [ -z "$REZILION_FAILED_RUNNING" ]; then
cat /tmp/rezilion/shell_command_output
echo Command Exit Code: "$(cat </tmp/rezilion/shell_command_exit_code)"
if [ "$(cat </tmp/rezilion/shell_command_exit_code)" != "0" ]; then
echo "Command failed"
exit 1
fi
else
echo "Failed running Rezilion"
cat "$AGENT_STDOUT_OUTPUT_PATH"
sh -c "$USER_COMMAND_PATH"
fi
shell: sh
- if: ${{ (inputs.mode == 'sca') }}
run: |
REZILION_OUTPUTS_FOLDER=/tmp/rezilion/outputs
REZILION_AGENT_PATH=/tmp/rezilion/validate_ci_agent
STOP_MINING_FLAG_FILE_PATH=/tmp/rezilion/stop_mining
MINERS_LOG_PATH="$REZILION_OUTPUTS_FOLDER"/"$GITHUB_JOB"/"$GITHUB_JOB"_miners.log
AGENT_STDOUT_OUTPUT_PATH="/tmp/rezilion_agent.logs"
if [ -f $STOP_MINING_FLAG_FILE_PATH ]; then
rm $STOP_MINING_FLAG_FILE_PATH
fi
RUN_REZILION_CMDLINE="$REZILION_AGENT_PATH --log-path $MINERS_LOG_PATH --license-key "$REZILION_LICENSE_KEY" --ci-environment github miners --sca-mode --current-job-name $GITHUB_JOB --miners-directory $REZILION_OUTPUTS_FOLDER --stop-dynamic-mining-flag-path $STOP_MINING_FLAG_FILE_PATH"
if [ ! -z "${{ inputs.image_name }}" ]; then
RUN_REZILION_CMDLINE="$RUN_REZILION_CMDLINE --container-image-name "${{ inputs.image_name }}""
fi
$RUN_REZILION_CMDLINE >> "$AGENT_STDOUT_OUTPUT_PATH" 2>&1 || cat "$AGENT_STDOUT_OUTPUT_PATH"
shell: sh
- if: ${{ (inputs.mode == 'start') || (inputs.mode == 'sca') }}
name: Upload output file
uses: actions/upload-artifact@v3
with:
name: Rezilion Test Artifacts
path: /tmp/rezilion/outputs
- if: ${{ inputs.mode == 'validate' }}
name: Download artifacts
uses: actions/download-artifact@v3
with:
name: Rezilion Test Artifacts
path: /tmp/rezilion/outputs
- if: ${{ (inputs.mode == 'validate')}}
run: |
REZILION_OUTPUTS_FOLDER=/tmp/rezilion/outputs
REZILION_AGENT_PATH=/tmp/rezilion/validate_ci_agent
if [ -z "$(ls -A $REZILION_OUTPUTS_FOLDER)" ]; then
echo "Rezilion found no images to validate..."
exit 0
fi
ARTIFACT_PATH=/tmp/rezilion/artifacts
mkdir -p $ARTIFACT_PATH
export REZILION_BACKEND_API_GATEWAY_URL="https://api.rezilion.com"
export REZILION_BACKEND_API_EUROPE_GATEWAY_URL="https://api.eu.rezilion.com"
$REZILION_AGENT_PATH --log-path "$REZILION_OUTPUTS_FOLDER"/validate.log --license-key $REZILION_LICENSE_KEY --ci-environment github validate --tests-directory $REZILION_OUTPUTS_FOLDER --output-directory $ARTIFACT_PATH --scanner-name Rezilion
shell: sh
- if: ${{ always() && (inputs.mode == 'validate')}}
name: Upload output file
uses: actions/upload-artifact@v3
with:
name: Rezilion Test Artifacts
path: /tmp/rezilion/outputs
- if: ${{ always() && (inputs.mode == 'validate')}}
name: Upload output file
uses: actions/upload-artifact@v3
with:
name: Rezilion Reports
path: /tmp/rezilion/artifacts