add root check, which was missing #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Revalidate Challenge README | |
| on: | |
| push: | |
| paths: | |
| - "README.md" | |
| branches: | |
| - "challenge-*" | |
| jobs: | |
| revalidate: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) | |
| steps: | |
| - name: Extract challenge name from branch | |
| id: extract_challenge | |
| run: | | |
| # Get the branch name | |
| if [ "${{ github.event_name }}" = "pull_request" ]; then | |
| BRANCH_NAME="${{ github.event.pull_request.base.ref }}" | |
| else | |
| BRANCH_NAME="${{ github.ref_name }}" | |
| fi | |
| # Extract challenge name from branch (e.g., challenge-tokenization -> tokenization) | |
| if [[ $BRANCH_NAME =~ ^challenge-(.+)$ ]]; then | |
| CHALLENGE_NAME="${BASH_REMATCH[1]}" | |
| echo "challenge_name=$CHALLENGE_NAME" >> $GITHUB_OUTPUT | |
| else | |
| echo "❌ Branch name does not match challenge pattern: $BRANCH_NAME" | |
| exit 1 | |
| fi | |
| - name: Revalidate speedrunethereum.com | |
| if: steps.extract_challenge.outputs.challenge_name != '' | |
| run: | | |
| CHALLENGE_NAME="${{ steps.extract_challenge.outputs.challenge_name }}" | |
| RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \ | |
| "https://speedrunethereum.com/api/revalidate?token=${{ secrets.REVALIDATION_TOKEN }}&path=/challenge/$CHALLENGE_NAME" \ | |
| -H "Content-Type: application/json") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| if [ "$HTTP_CODE" -eq 200 ]; then | |
| echo "✅ Successfully revalidated challenge $CHALLENGE_NAME" | |
| else | |
| RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1) | |
| echo "❌ Failed to revalidate challenge $CHALLENGE_NAME (HTTP $HTTP_CODE)" | |
| echo "Response: $RESPONSE_BODY" | |
| exit 1 | |
| fi | |
| - name: Add summary | |
| if: always() | |
| run: | | |
| echo "## 📄 README Revalidation" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ steps.extract_challenge.outputs.challenge_name }}" != "" ]; then | |
| echo "**Challenge:** \`${{ steps.extract_challenge.outputs.challenge_name }}\`" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ job.status }}" = "success" ]; then | |
| echo "✅ Successfully revalidated" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "❌ Failed to revalidate" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| else | |
| echo "❌ Could not extract challenge name from branch" >> $GITHUB_STEP_SUMMARY | |
| fi |