|
| 1 | +# Twitter/X Auto-Posting Setup Guide |
| 2 | + |
| 3 | +This guide explains how to configure automatic Twitter/X posting for Flutter Skill releases. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +When you release a new version, GitHub Actions will automatically post a tweet announcing the release, including: |
| 8 | +- Version number |
| 9 | +- Installation commands (npm, Homebrew, Winget) |
| 10 | +- Release notes link |
| 11 | +- Relevant hashtags |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +You need a Twitter/X Developer account with API access. |
| 16 | + |
| 17 | +## Step 1: Create Twitter Developer Account |
| 18 | + |
| 19 | +1. **Go to Twitter Developer Portal** |
| 20 | + - Visit: https://developer.twitter.com/en/portal/dashboard |
| 21 | + - Sign in with your Twitter/X account |
| 22 | + |
| 23 | +2. **Create a Project** |
| 24 | + - Click "Create Project" |
| 25 | + - Project name: `Flutter Skill Auto-Release` |
| 26 | + - Use case: `Making a bot` |
| 27 | + - Project description: `Automatic release announcements for Flutter Skill` |
| 28 | + |
| 29 | +3. **Create an App** |
| 30 | + - App name: `flutter-skill-releases` (or any unique name) |
| 31 | + - Click "Complete" |
| 32 | + |
| 33 | +## Step 2: Enable OAuth 2.0 and Get Bearer Token |
| 34 | + |
| 35 | +### Method 1: Using OAuth 2.0 (Recommended) |
| 36 | + |
| 37 | +1. **Generate Bearer Token** |
| 38 | + - In your app settings, go to "Keys and tokens" tab |
| 39 | + - Under "Authentication Tokens", click "Generate" for Bearer Token |
| 40 | + - **IMPORTANT:** Copy the Bearer Token immediately - you won't see it again! |
| 41 | + - Format: `AAAAAAAAAAAAAAAAAAAAAxxxxxxxxxxxxxxxxxxxxxxxx` |
| 42 | + |
| 43 | +2. **Set App Permissions** |
| 44 | + - Go to "User authentication settings" |
| 45 | + - Click "Set up" |
| 46 | + - App permissions: Select "Read and write" |
| 47 | + - Type of App: "Web App, Automated App or Bot" |
| 48 | + - Callback URI: `https://github.com/ai-dashboad/flutter-skill` (required but not used) |
| 49 | + - Website URL: `https://github.com/ai-dashboad/flutter-skill` |
| 50 | + - Save |
| 51 | + |
| 52 | +### Method 2: Using OAuth 1.0a (Alternative) |
| 53 | + |
| 54 | +If OAuth 2.0 Bearer Token doesn't work, use API Keys: |
| 55 | + |
| 56 | +1. **Generate API Keys** |
| 57 | + - In "Keys and tokens" tab: |
| 58 | + - API Key (Consumer Key): `xxxxxxxxxxxxxxxxxxxx` |
| 59 | + - API Key Secret (Consumer Secret): `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
| 60 | + - Access Token: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
| 61 | + - Access Token Secret: `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |
| 62 | + |
| 63 | +2. **Note:** The GitHub Action uses Bearer Token by default. If using API Keys, you'll need to modify the workflow. |
| 64 | + |
| 65 | +## Step 3: Add Twitter Credentials to GitHub Secrets |
| 66 | + |
| 67 | +1. **Go to GitHub Repository Settings** |
| 68 | + - Visit: https://github.com/ai-dashboad/flutter-skill/settings/secrets/actions |
| 69 | + |
| 70 | +2. **Add the Bearer Token** |
| 71 | + - Click "New repository secret" |
| 72 | + - Name: `TWITTER_BEARER_TOKEN` |
| 73 | + - Value: Paste your Bearer Token |
| 74 | + - Click "Add secret" |
| 75 | + |
| 76 | +## Step 4: Test the Setup |
| 77 | + |
| 78 | +### Option 1: Test with Next Release |
| 79 | + |
| 80 | +Simply release a new version: |
| 81 | +```bash |
| 82 | +./scripts/release.sh 0.5.4 "Your release description" |
| 83 | +``` |
| 84 | + |
| 85 | +The GitHub Action will automatically post to Twitter. |
| 86 | + |
| 87 | +### Option 2: Manual Test (Advanced) |
| 88 | + |
| 89 | +Trigger the workflow manually to test: |
| 90 | + |
| 91 | +1. Go to: https://github.com/ai-dashboad/flutter-skill/actions/workflows/release.yml |
| 92 | +2. Click "Run workflow" |
| 93 | +3. Select branch: `main` |
| 94 | +4. Run workflow |
| 95 | + |
| 96 | +## Step 5: Verify |
| 97 | + |
| 98 | +After a release, check: |
| 99 | + |
| 100 | +1. **GitHub Actions Log** |
| 101 | + - https://github.com/ai-dashboad/flutter-skill/actions |
| 102 | + - Look for "Post to X (Twitter)" step |
| 103 | + - Check for success ✅ or errors ❌ |
| 104 | + |
| 105 | +2. **Your Twitter/X Profile** |
| 106 | + - Visit your Twitter profile |
| 107 | + - Verify the release announcement was posted |
| 108 | + |
| 109 | +## Troubleshooting |
| 110 | + |
| 111 | +### Error: "Unauthorized" (401) |
| 112 | + |
| 113 | +**Cause:** Invalid or expired Bearer Token |
| 114 | + |
| 115 | +**Fix:** |
| 116 | +1. Regenerate Bearer Token in Twitter Developer Portal |
| 117 | +2. Update `TWITTER_BEARER_TOKEN` secret in GitHub |
| 118 | + |
| 119 | +### Error: "Forbidden" (403) |
| 120 | + |
| 121 | +**Cause:** App permissions not set to "Read and write" |
| 122 | + |
| 123 | +**Fix:** |
| 124 | +1. Go to Twitter Developer Portal → Your App → Settings |
| 125 | +2. Set App permissions to "Read and write" |
| 126 | +3. Regenerate tokens after changing permissions |
| 127 | + |
| 128 | +### Error: "Too Many Requests" (429) |
| 129 | + |
| 130 | +**Cause:** Rate limit exceeded |
| 131 | + |
| 132 | +**Fix:** |
| 133 | +- Wait for rate limit to reset (15 minutes for most endpoints) |
| 134 | +- Twitter has strict rate limits for posting tweets |
| 135 | + |
| 136 | +### Tweet Not Posted but No Error |
| 137 | + |
| 138 | +**Cause:** Duplicate tweet detection |
| 139 | + |
| 140 | +**Fix:** |
| 141 | +- Twitter blocks duplicate tweets within a short time window |
| 142 | +- Each release should have unique content (version number changes) |
| 143 | + |
| 144 | +## Customizing Tweet Content |
| 145 | + |
| 146 | +To customize the tweet content, edit `.github/workflows/release.yml`: |
| 147 | + |
| 148 | +```yaml |
| 149 | +# In post-to-twitter job, find the "Extract changelog entry" step |
| 150 | +cat > tweet.txt << 'EOF' |
| 151 | +🚀 Your custom message here |
| 152 | +EOF |
| 153 | +``` |
| 154 | + |
| 155 | +**Important:** |
| 156 | +- Keep tweets under 280 characters |
| 157 | +- Include version variable: `v$VERSION` |
| 158 | +- Use hashtags for discoverability |
| 159 | + |
| 160 | +## Security Best Practices |
| 161 | + |
| 162 | +1. **Never commit tokens to git** |
| 163 | + - Always use GitHub Secrets |
| 164 | + - Never log tokens in Actions output |
| 165 | + |
| 166 | +2. **Use minimum required permissions** |
| 167 | + - Bearer Token only needs "Read and write" tweets permission |
| 168 | + - Don't grant DM or additional permissions unless needed |
| 169 | + |
| 170 | +3. **Rotate tokens periodically** |
| 171 | + - Regenerate Bearer Token every 6-12 months |
| 172 | + - Update GitHub Secret after rotation |
| 173 | + |
| 174 | +## Alternative: Using Twitter Action (Optional) |
| 175 | + |
| 176 | +If you prefer using a GitHub Action instead of curl, you can use: |
| 177 | + |
| 178 | +```yaml |
| 179 | +- name: Post to Twitter |
| 180 | + uses: nearform-actions/github-action-notify-twitter@v1 |
| 181 | + with: |
| 182 | + message: ${{ steps.changelog.outputs.tweet }} |
| 183 | + twitter-app-key: ${{ secrets.TWITTER_API_KEY }} |
| 184 | + twitter-app-secret: ${{ secrets.TWITTER_API_SECRET }} |
| 185 | + twitter-access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} |
| 186 | + twitter-access-token-secret: ${{ secrets.TWITTER_ACCESS_SECRET }} |
| 187 | +``` |
| 188 | +
|
| 189 | +This requires OAuth 1.0a credentials (4 separate secrets). |
| 190 | +
|
| 191 | +## Resources |
| 192 | +
|
| 193 | +- [Twitter API Documentation](https://developer.twitter.com/en/docs/twitter-api) |
| 194 | +- [Twitter API v2 - Create Tweet](https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets) |
| 195 | +- [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) |
| 196 | +
|
| 197 | +--- |
| 198 | +
|
| 199 | +**Questions or Issues?** |
| 200 | +
|
| 201 | +Open an issue: https://github.com/ai-dashboad/flutter-skill/issues |
0 commit comments