Skip to content

Remove nginx dependency #471

Remove nginx dependency

Remove nginx dependency #471

name: Pull Request Comment Triggered Integration Test
on:
issue_comment:
types: [created]
env:
COMMENT_BODY: ${{ github.event.comment.body }}
permissions:
pull-requests: write
contents: read
issues: read
jobs:
pr-triggered-integration-test:
if: |
github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/run ')
runs-on: [self-hosted, linux, x64, dev, dmount]
name: PR-Comment-Integration-Tests
steps:
- name: Is comment allowed?
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
script: |
const actorPermission = (await github.rest.repos.getCollaboratorPermissionLevel({
...context.repo,
username: context.actor
})).data.permission
const isPermitted = ['write', 'admin'].includes(actorPermission)
if (!isPermitted) {
const errorMessage = 'Only users with write permission to the repository can run GitHub commands'
await github.rest.issues.createComment({
...context.repo,
issue_number: context.issue.number,
body: errorMessage,
})
core.setFailed(errorMessage)
return
}
- name: Get PR Info
id: pr
env:
PR_NUMBER: ${{ github.event.issue.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
COMMENT_AT: ${{ github.event.comment.created_at }}
run: |
pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})"
head_sha="$(echo "$pr" | jq -r .head.sha)"
pushed_at="$(echo "$pr" | jq -r .head.repo.pushed_at)"
if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then
echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)"
exit 1
fi
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
- name: Checkout the branch from the PR that triggered the job
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr checkout ${{ github.event.issue.number }}
- name: Validate the fetched branch HEAD revision
env:
EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }}
run: |
actual_sha="$(git rev-parse HEAD)"
if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then
echo "The HEAD of the checked out branch ($actual_sha) differs from the HEAD commit available at the time when trigger comment was submitted ($EXPECTED_SHA)"
exit 1
fi
- name: Print current branch
run: echo "$(git branch)"
- name: Install Python
uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6
with:
python-version: "3.12"
- name: Install tox
working-directory: library
run: |
pip install '.[dev]'
- name: Extract, Validate, and Run Integration Test
working-directory: library
id: tests
run: |
ALLOWED_TASKS=("all" "detection" "instance_segmentation" "semantic_segmentation" "multi_class_cls" "multi_label_cls" "h_label_cls" "anomaly_classification" "keypoint_detection")
# Ensure comment starts with "/run " and extract task name
if [[ "$COMMENT_BODY" =~ ^/run\ ([a-zA-Z0-9_-]+)$ ]]; then
TASK_NAME="${BASH_REMATCH[1]}"
else
echo "❌ Invalid format. Use '/run <task_name>'"
exit 1
fi
# Validate the extracted task name
if [[ ! " ${ALLOWED_TASKS[@]} " =~ " ${TASK_NAME} " ]]; then
echo "❌ Invalid task: $TASK_NAME. Allowed tasks: ${ALLOWED_TASKS[*]}"
exit 1
fi
echo "✅ Running integration test for: $TASK_NAME"
tox -vv -e "integration-test-${TASK_NAME}"
- name: Update PR description with workflow run link and result
if: always() # Ensure this runs even if the job fails
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # Or your PAT if needed
script: |
const status = '${{ steps.tests.outcome }}'; // success, failure, skipped
const emoji = {
success: "✅",
failure: "❌",
skipped: "⚠️",
}[status] || "❓";
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const lastCommit = commits[commits.length - 1];
const lastCommitMsg = lastCommit.commit.message.split('\n')[0];
const tag = "<!-- INTEGRATION-RUN-LINK -->";
const runSection = `${tag}
## 🚀 Integration Run Summary
- **Last Commit:** ${lastCommitMsg}
- **Result:** ${emoji} ${status.toUpperCase()}
- **Workflow Run:** [View Run](${runUrl})
`;
const newBody = pr.body.includes(tag)
? pr.body.replace(new RegExp(`${tag}[\\s\\S]*?(\n|$)`), runSection)
: `${pr.body}\n\n${runSection}`;
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
body: newBody
});