The "INFINITE_LOOP_DETECTED" error you're encountering typically happens when there is a repetitive request pattern that the system detects as a loop. Given the context of your GitHub Actions workflow and the information provided, here are a few potential reasons and solutions for this issue:
Since the workflow can be triggered in parallel by multiple events, and each run uses the same VERCEL_TOKEN, it’s possible that these concurrent requests are causing Vercel to detect an infinite loop.
Solution: Add a delay or rate limiting to the Get deployment details step to prevent too many simultaneous requests. You can introduce a short sleep before making the API call:
yaml
Copy code
- name: Get deployment details
run: |
sleep $(( RANDOM % 5 ))
curl -L -X GET "https://api.vercel.com/v13/deployments/${{ steps.build-and-deploy.outputs.DEPLOYMENT_URL }}?slug=***&teamId=***&withGitRepoInfo=true" \
-H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" -H "Content-Type: application/json"
If the Get deployment details step is being called multiple times within the same workflow run, this could cause the system to detect a loop.
Solution: Ensure that the API call is made only once. You can use an environment variable or a context value to control the execution:
yaml
Copy code
- name: Set environment variable
run: echo "CALL_API=true" >> $GITHUB_ENV
- name: Get deployment details
if: env.CALL_API == 'true'
run: |
echo "CALL_API=false" >> $GITHUB_ENV
curl -L -X GET "https://api.vercel.com/v13/deployments/${{ steps.build-and-deploy.outputs.DEPLOYMENT_URL }}?slug=***&teamId=***&withGitRepoInfo=true" \
-H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" -H "Content-Type: application/json"
If the Get deployment details step somehow triggers another deployment or another workflow run, it could create a loop.
Solution: Make sure that the workflow is not set to trigger itself or other workflows that would result in calling the Vercel API repeatedly. Check your GitHub workflow configuration to ensure no such triggers are set.
Ensure that you are not hitting the Vercel API rate limits, which might cause it to behave unexpectedly.
Solution: Check the Vercel API rate limits and adjust your workflow to stay within those limits.
Here’s an updated workflow with the delay and single-call check:
Copy code
name: Build and Deploy
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Install vercel cli
run: |
npm install --global vercel@34.0.0
- name: Link local directory to vercel project and pull environment variables
id: link-local-directory-to-vercel
run: |
vercel link --yes --project ${{ inputs.vercel_project_name }} --token=${{ secrets.VERCEL_TOKEN }} --scope=***
vercel pull --environment=${{ inputs.environment }} $([[ ${{ inputs.environment }} != 'production' ]] && echo "--git-branch=${{ github.ref_name }}") --yes --token=${{ secrets.VERCEL_TOKEN }} --scope=***
- name: Build and deploy
id: build-and-deploy
run: |
vercel build $([[ ${{ inputs.environment }} == 'production' ]] && echo "--prod") --debug --token=${{ secrets.VERCEL_TOKEN }} --scope=***
DEPLOYMENT_URL=$(vercel deploy --prebuilt $([[ ${{ inputs.environment }} == 'production' ]] && echo "--prod") --yes --token=${{ secrets.VERCEL_TOKEN }} --scope=***)
echo "DEPLOYMENT_URL=${DEPLOYMENT_URL}" >> "$GITHUB_OUTPUT"
- name: Assign aliases
id: assign-alias
run: |
vercel alias ${{ steps.build-and-deploy.outputs.DEPLOYMENT_URL }} ${BRANCH_NAME}.xyz.com --token=${{ secrets.VERCEL_TOKEN }} --scope=***
- name: Set environment variable
run: echo "CALL_API=true" >> $GITHUB_ENV
- name: Get deployment details
if: env.CALL_API == 'true'
run: |
echo "CALL_API=false" >> $GITHUB_ENV
sleep $(( RANDOM % 5 ))
curl -L -X GET "https://api.vercel.com/v13/deployments/${{ steps.build-and-deploy.outputs.DEPLOYMENT_URL }}?slug=***&teamId=***&withGitRepoInfo=true" \
-H "Authorization: Bearer ${{ secrets.VERCEL_TOKEN }}" -H "Content-Type: application/json"
By implementing these changes, you should be able to avoid the "INFINITE_LOOP_DETECTED" error and ensure your workflow executes as expected.