Skip to content

Extracting cmd module #470

Extracting cmd module

Extracting cmd module #470

name: Integration tests
permissions:
contents: read
pull-requests: read
statuses: write
on:
push:
branches: [ "main" ]
workflow_dispatch:
inputs:
GIT_REF:
description: 'Commit hash to run the tests'
required: true
issue_comment:
types: [created]
jobs:
check-comment:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/run-integration-tests' }}
outputs:
ref: ${{ steps.get-pr-ref.outputs.ref }}
steps:
- name: Get PR ref
id: get-pr-ref
run: |
PR_URL="${{ github.event.issue.pull_request.url }}"
PR_INFO=$(curl -s -H "Authorization: token ${{ github.token }}" $PR_URL)
echo "ref=$(echo $PR_INFO | jq -r .head.sha)" >> $GITHUB_OUTPUT
- name: Create pending status
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ steps.get-pr-ref.outputs.ref }} \
-d '{"state":"pending","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"Integration tests are running","context":"integration-tests"}'
build-quesma-docker-image:
needs: [check-comment]
if: ${{ always() && (github.event_name != 'issue_comment' || needs.check-comment.result == 'success') }}
uses: ./.github/workflows/build-quesma-docker-image.yml
with:
REF: ${{ github.event.inputs.GIT_REF || needs.check-comment.outputs.ref }}
integration-test-run:
runs-on: ubuntu-latest
needs: [build-quesma-docker-image, check-comment]
if: ${{ always() && (github.event_name != 'issue_comment' || needs.check-comment.result == 'success') }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.GIT_REF || needs.check-comment.outputs.ref }}
- name: Set up Go
uses: actions/setup-go@v5
with:
cache-dependency-path: smoke-test/go.sum
go-version: '1.24'
- name: Download images
uses: actions/download-artifact@v4
with:
path: /tmp/images
- name: Load images
run: |
for file in /tmp/images/*/*.tar; do
docker load --input $file
done
docker image ls -a
- name: Set environment variable
run: echo "EXECUTING_ON_GITHUB_CI=true" >> $GITHUB_ENV
- name: Get last commit author
id: get_author
run: >
echo "author=$(git log -1 --pretty=format:'%an <%ae>, commit URL: ${{ github.server_url }}/${{ github.repository }}/commit/%H')" >> $GITHUB_OUTPUT
- name: License Header Verification
working-directory: ci/it
run: |
LICENSE_COMMENT="// Copyright Quesma, licensed under the Elastic License 2.0.
// SPDX-License-Identifier: Elastic-2.0"
failed=false
while IFS= read -r -d '' file; do
file_content=$(< "$file")
if [[ "$file_content" != "$LICENSE_COMMENT"* ]]; then
echo "License header missing or incorrect in file: $file"
failed=true
fi
done < <(find . -type f -name "*.go" -print0)
if [ "$failed" = true ]; then
exit 1
fi
- name: Run integration tests
working-directory: ci/it
run: go test -v
- name: Send Slack notification on failure
if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: ":exclamation: *Integration tests failed.* :exclamation: <!channel>\n*Last commit by:* ${{ steps.get_author.outputs.author }}\n*Workflow run URL:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Send Slack notification on success
if: ${{ success() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: slackapi/slack-github-action@v2.0.0
with:
method: chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
channel: ${{ secrets.SLACK_CHANNEL_ID }}
text: ":white_check_mark: *Integration tests passed.* Good job team!\n*Last commit by:* ${{ steps.get_author.outputs.author }}\n*Workflow run URL:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
# Update status checks for the PR if the tests were triggered by a comment
- name: Update status check (success)
if: ${{ success() && github.event_name == 'issue_comment' }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ needs.check-comment.outputs.ref }} \
-d '{"state":"success","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"Integration tests passed","context":"integration-tests"}'
- name: Update status check (failure)
if: ${{ failure() && github.event_name == 'issue_comment' }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.api_url }}/repos/${{ github.repository }}/statuses/${{ needs.check-comment.outputs.ref }} \
-d '{"state":"failure","target_url":"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}","description":"Integration tests failed","context":"integration-tests"}'