|
27 | 27 | GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} |
28 | 28 | BUILD_BASE: ${{ (contains(github.event.pull_request.body, 'ci:build-base') || github.event_name == 'schedule') && '1' || '0' }} |
29 | 29 | BASE_IMAGE: ${{ secrets.REGISTRY_HOST }}/processmaker/processmaker:base |
30 | | - K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }} |
| 30 | + K8S_BRANCH: ${{ contains(github.event.pull_request.body, 'ci:next') && 'next' || 'develop' }} |
31 | 31 | concurrency: |
32 | 32 | group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
33 | 33 | cancel-in-progress: true |
@@ -145,6 +145,76 @@ jobs: |
145 | 145 | run: | |
146 | 146 | echo "Instance URL: '${INSTANCE_URL}'" |
147 | 147 | bash argocd/gh_comment.sh "$CI_PROJECT" "$pull_req_id" |
| 148 | + runAPITest: |
| 149 | + name: Run API Tests |
| 150 | + needs: [deployEKS] |
| 151 | + if: contains(github.event.pull_request.body, 'ci:api-test') |
| 152 | + runs-on: self-hosted |
| 153 | + steps: |
| 154 | + - name: Clone private repository |
| 155 | + run: | |
| 156 | + git clone --depth 1 -b eng "https://$GITHUB_TOKEN@github.com/ProcessMaker/argocd.git" argocd |
| 157 | + - name: Install pm4-tools |
| 158 | + run: | |
| 159 | + git clone --depth 1 -b "$K8S_BRANCH" "https://$GITHUB_TOKEN@github.com/ProcessMaker/pm4-k8s-distribution.git" pm4-k8s-distribution |
| 160 | + echo "versionHelm=$(grep "version:" "pm4-k8s-distribution/charts/enterprise/Chart.yaml" | awk '{print $2}' | sed 's/\"//g')" >> $GITHUB_ENV |
| 161 | + cd pm4-k8s-distribution/images/pm4-tools |
| 162 | + composer install --no-interaction |
| 163 | + cd .. |
| 164 | + - name: Configure AWS credentials |
| 165 | + uses: aws-actions/configure-aws-credentials@v1 |
| 166 | + with: |
| 167 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID1 }} |
| 168 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY1 }} |
| 169 | + aws-region: ${{ secrets.AWS_REGION }} |
| 170 | + - name: Set up kubectl |
| 171 | + run: | |
| 172 | + curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" |
| 173 | + chmod +x kubectl |
| 174 | + sudo mv kubectl /usr/local/bin/ |
| 175 | + - name: Authenticate with Amazon EKS |
| 176 | + run: aws eks update-kubeconfig --region us-east-1 --name pm4-eng |
| 177 | + - name: Run the API tests |
| 178 | + run: | |
| 179 | + cd argocd |
| 180 | + deploy=$(echo -n ${{env.IMAGE_TAG}} | md5sum | head -c 10) |
| 181 | + namespace="ci-$deploy-ns-pm4" |
| 182 | + pr_body=$(jq -r .pull_request.body < "$GITHUB_EVENT_PATH" | base64) |
| 183 | + kubectl get pods --namespace=$namespace |
| 184 | + pod_names=$(kubectl get pods --namespace=$namespace --field-selector=status.phase=Running -o jsonpath="{.items[*].metadata.name}" | tr ' ' '\n' | grep -E '(-processmaker-scheduler-)') |
| 185 | + for pod in $pod_names; do |
| 186 | + code=' |
| 187 | + has_processmaker=$(ls /opt | grep processmaker) |
| 188 | + has_sudo=$(ls /usr/bin | grep sudo) |
| 189 | + has_php=$(ls /usr/bin | grep php) |
| 190 | + if [ ! -z "$has_processmaker" ] && [ ! -z "$has_sudo" ] && [ ! -z "$has_php" ]; then |
| 191 | + echo $pr_body | base64 -d > /tmp/pr_body |
| 192 | + cd /opt/processmaker |
| 193 | + sudo -u nginx php artisan pm4-api-testing:run --body="$pr_body" |
| 194 | + else |
| 195 | + exit 1 |
| 196 | + fi' |
| 197 | + kubectl exec -n $namespace $pod -- /bin/sh -c "pr_body='${pr_body}';${code}" | tee /tmp/comment.md && break || true |
| 198 | + done |
| 199 | + # Send the content of /tmp/comment.md as a PR comment |
| 200 | + MESSAGE=$(cat /tmp/comment.md) |
| 201 | + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} |
| 202 | + GITHUB_REPOSITORY=${{ github.repository }} |
| 203 | + PR_NUMBER=$(jq -r .number < "$GITHUB_EVENT_PATH") |
| 204 | +
|
| 205 | + if [ -z "$PR_NUMBER" ]; then |
| 206 | + echo "The PR number is not available. Make sure this script is executed in a context of Pull Request." |
| 207 | + exit 1 |
| 208 | + fi |
| 209 | +
|
| 210 | + URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" |
| 211 | + json_payload=$(jq -n --arg message "$MESSAGE" '{"body": $message}') |
| 212 | +
|
| 213 | + curl -s \ |
| 214 | + -H "Authorization: token ${GITHUB_TOKEN}" \ |
| 215 | + -H "Accept: application/vnd.github.v3+json" \ |
| 216 | + -d "$json_payload" \ |
| 217 | + "${URL}" |
148 | 218 | deleteEKS: |
149 | 219 | name: Delete Instance |
150 | 220 | if: github.event.action == 'closed' |
|
0 commit comments