Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# GitHub Actions Configuration

This directory contains GitHub Actions workflows used for automating various tasks in the BLT project.

## Setting Up Custom GitHub Token

For some workflows like adding labels to issues and pull requests, you may need to set up a custom GitHub token with elevated permissions.

### Why Custom Token?

The default `GITHUB_TOKEN` provided by GitHub Actions has certain permission limitations. For operations like creating labels or adding labels to issues and PRs, we recommend using a Personal Access Token (PAT) with appropriate permissions.

### Creating a Custom GitHub Token

1. Go to your GitHub account settings
2. Navigate to Developer settings > Personal Access Tokens > Fine-grained tokens
3. Click "Generate new token"
4. Provide a suitable name like "BLT Workflow Token"
5. Set the expiration as needed
6. For repository access, select "Only select repositories" and choose the BLT repository
7. Under permissions, grant the following:
- Repository permissions:
- Issues: Read and write
- Pull requests: Read and write
- Contents: Read and write
- Administration: Read and write (needed for label management)
- Metadata: Read-only (automatically selected)

8. Click "Generate token" and copy the token value

### Adding the Token to GitHub Secrets

1. Go to the BLT repository on GitHub
2. Navigate to Settings > Secrets and variables > Actions
3. Click "New repository secret"
4. Name it `CUSTOM_GITHUB_TOKEN`
5. Paste the token value and click "Add secret"

### Using the Custom Token

The workflows are configured to use `CUSTOM_GITHUB_TOKEN` if available, falling back to the default `GITHUB_TOKEN` if not.

Example usage in workflow:
```yaml
env:
GITHUB_TOKEN: ${{ secrets.CUSTOM_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
```

## Troubleshooting

If you encounter permission errors like `Resource not accessible by integration`, it's likely that:
1. The token doesn't have the necessary permissions
2. The token has expired
3. The workflow permissions at the top of the .yml file need to be adjusted

For label-related operations specifically:
1. Ensure your CUSTOM_GITHUB_TOKEN has "Administration: Read and write" permissions
2. Make sure the workflow has `repository-projects: write` permission as well as other necessary permissions

Review the permissions in both your custom token and at the workflow level to resolve such issues.
15 changes: 13 additions & 2 deletions .github/workflows/add-files-changed-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ permissions:
pull-requests: write
contents: read
issues: write
repository-projects: write

jobs:
add_files_changed_label:
Expand Down Expand Up @@ -88,6 +89,12 @@ jobs:
# Check if label creation was successful
if [[ "$CREATE_LABEL_RESPONSE" == *"message"* ]]; then
echo "Warning: There might be an issue creating the label. Response: $CREATE_LABEL_RESPONSE"

# Provide more detailed guidance for permission errors
if [[ "$CREATE_LABEL_RESPONSE" == *"Resource not accessible by integration"* ]]; then
echo "This appears to be a permissions issue with creating labels."
echo "Please check the .github/README.md file for instructions on setting up a CUSTOM_GITHUB_TOKEN with proper permissions."
fi
else
echo "Label '$LABEL' created successfully."
fi
Expand Down Expand Up @@ -144,8 +151,12 @@ jobs:

# Check if it's a permissions issue and suggest using a custom token
if [[ "$ADD_LABEL_RESPONSE" == *"Resource not accessible by integration"* ]]; then
echo "This appears to be a permissions issue. Please configure a CUSTOM_GITHUB_TOKEN secret with higher permissions."
echo "See the .github/README.md file for instructions on setting up the token."
echo "This appears to be a permissions issue. Please follow these steps:"
echo "1. Create a Personal Access Token (PAT) with 'repo' scope"
echo "2. Add the token to your repository secrets as CUSTOM_GITHUB_TOKEN"
echo "3. See the .github/README.md file for detailed instructions on setting up the token"
echo ""
echo "Note: The workflow is configured to use CUSTOM_GITHUB_TOKEN if available, falling back to GITHUB_TOKEN"
fi

exit 1
Expand Down