Skip to content

Commit 0250b6d

Browse files
author
GitLab CI
committed
feat: Add automatic Twitter/X posting for releases
- Add post-to-twitter job to release workflow - Auto-post release announcements with version, install commands, and link - Uses Twitter API v2 with Bearer Token authentication - Add comprehensive setup guide in docs/TWITTER_SETUP.md - Includes troubleshooting and security best practices
1 parent 54e22c8 commit 0250b6d

3 files changed

Lines changed: 267 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,53 @@ jobs:
467467
release-assets/*
468468
env:
469469
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
470+
471+
# Post release announcement to X (Twitter)
472+
post-to-twitter:
473+
needs: [prepare, create-release]
474+
runs-on: ubuntu-latest
475+
continue-on-error: true # Don't block if Twitter posting fails
476+
steps:
477+
- uses: actions/checkout@v4
478+
479+
- name: Extract changelog entry
480+
id: changelog
481+
run: |
482+
VERSION="${{ needs.prepare.outputs.version }}"
483+
484+
# Extract version section from CHANGELOG.md
485+
ENTRY=$(awk "/^## $VERSION/,/^## /" CHANGELOG.md | sed '1d;$d' | head -n 10)
486+
487+
# Create tweet text (280 char limit for Twitter/X)
488+
cat > tweet.txt << 'EOF'
489+
🚀 Flutter Skill v$VERSION released!
490+
491+
AI agents → Flutter apps bridge via Dart VM Service
492+
493+
📦 Install:
494+
npm i -g flutter-skill-mcp
495+
brew install ai-dashboad/flutter-skill/flutter-skill
496+
winget install AIDashboard.FlutterSkill
497+
498+
🔗 https://github.com/ai-dashboad/flutter-skill/releases/tag/v$VERSION
499+
500+
#Flutter #AI #MCP #DartLang
501+
EOF
502+
503+
# Replace version placeholder
504+
sed -i "s/\$VERSION/$VERSION/g" tweet.txt
505+
506+
# Read and truncate to 280 chars if needed
507+
TWEET=$(cat tweet.txt | head -c 280)
508+
509+
echo "tweet<<EOFTWEET" >> $GITHUB_OUTPUT
510+
echo "$TWEET" >> $GITHUB_OUTPUT
511+
echo "EOFTWEET" >> $GITHUB_OUTPUT
512+
513+
- name: Post to X (Twitter)
514+
run: |
515+
# Twitter API v2 endpoint for creating tweets
516+
curl -X POST "https://api.twitter.com/2/tweets" \
517+
-H "Authorization: Bearer ${{ secrets.TWITTER_BEARER_TOKEN }}" \
518+
-H "Content-Type: application/json" \
519+
-d "{\"text\": $(echo '${{ steps.changelog.outputs.tweet }}' | jq -Rs .)}"

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
## Unreleased
2+
3+
### 🤖 CI/CD Improvements
4+
- 🐦 **Automated Twitter/X Posting**: Release workflow now auto-posts release announcements to Twitter/X
5+
- Posts tweet with version, installation commands, and release link
6+
- Uses Twitter API v2 for reliable posting
7+
- Includes relevant hashtags (#Flutter #AI #MCP #DartLang)
8+
- Comprehensive setup guide in `docs/TWITTER_SETUP.md`
9+
10+
### 📚 Documentation
11+
- 📖 Added `docs/TWITTER_SETUP.md` with complete Twitter API configuration guide
12+
- Step-by-step Bearer Token setup
13+
- Troubleshooting guide
14+
- Security best practices
15+
- Tweet customization instructions
16+
117
## 0.5.3
218

319
**Add automated Winget PR submission to release workflow**

docs/TWITTER_SETUP.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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

Comments
 (0)