Skip to content

test: improve E2E CI #23

test: improve E2E CI

test: improve E2E CI #23

Workflow file for this run

name: E2E Tests
on:
pull_request:
branches:
- '**'
push:
branches:
- 'main'
env:
TEAM_MEMBERS: "nachoaldamav"
permissions:
issues: write
pull-requests: write
jobs:
check-author:
runs-on: ubuntu-latest
outputs:
is-external: ${{ steps.check-author.outputs.is-external }}
steps:
- name: Check if PR is from a team member
id: check-author
run: |
if [ "${{ github.event.pull_request }}" != "" ]; then
if echo "$TEAM_MEMBERS" | grep -q "${{ github.actor }}"; then
echo "PR is from a team member."
echo "is-external=false" >> $GITHUB_ENV
else
echo "PR is from an external contributor."
echo "is-external=true" >> $GITHUB_ENV
fi
else
echo "Not a PR, running the workflow."
echo "is-external=false" >> $GITHUB_ENV
fi
require-approval:
runs-on: ubuntu-latest
needs: check-author
steps:
- name: Check for existing approval comment
id: check-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const approvalComment = comments.data.find(comment => comment.body.includes('Please approve this PR by reacting with an "👍".') && comment.user.login === 'github-actions[bot]');
if (approvalComment) {
core.setOutput('commentExists', 'true');
core.setOutput('commentId', approvalComment.id);
return approvalComment.id;
} else {
core.setOutput('commentExists', 'false');
return '';
}
- name: Create Approval Comment
if: steps.check-comment.outputs.commentExists == 'false'
id: create-comment
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: 'Please approve this PR by reacting with an "👍".'
});
core.setOutput('commentCreated', 'true');
- name: Get Comment ID
if: steps.create-comment.outputs.commentCreated == 'true'
id: get-comment-id
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = context.issue.number;
await new Promise(r => setTimeout(r, 5000)); // 5-second delay
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
});
const approvalComment = comments.data.find(comment => comment.body.includes('Please approve this PR by reacting with an "👍".') && comment.user.login === 'github-actions[bot]');
if (approvalComment) {
core.setOutput('commentId', approvalComment.id.toString());
}
- name: Wait for Approval
run: |
comment_id=${{ steps.check-comment.outputs.result || steps.get-comment-id.outputs.commentId}}
echo "Comment ID: $comment_id"
counter=0
while [ $counter -lt 15 ]; do
echo "Checking for approvals, attempt $((counter + 1))"
response=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github.squirrel-girl-preview+json" "https://api.github.com/repos/${{ github.repository }}/issues/comments/$comment_id/reactions")
echo "Response: $response"
approved=$(echo "$response" | jq '.[] | select(.content == "+1") | .user.login')
echo "Approved: $approved"
if [ -n "$approved" ]; then
echo "PR has been approved by a team member."
break
fi
sleep 60
((counter++))
done
if [ $counter -ge 15 ]; then
echo "Timeout reached for Approval - 15m. Exiting..."
exit 1
fi
windows-tests:
needs: [require-approval]
uses: ./.github/workflows/windows.yml
secrets: inherit
macos-tests:
needs: [require-approval]
uses: ./.github/workflows/macos.yml
linux-tests:
needs: [require-approval]
uses: ./.github/workflows/linux.yml
secrets: inherit