|
| 1 | +name: Social Media Auto-Post |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [gh-pages] |
| 6 | + paths: |
| 7 | + - 'music.html' |
| 8 | + - 'assets/music/**' |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + message: |
| 12 | + description: 'Custom message to post' |
| 13 | + required: false |
| 14 | + default: '🎵 New track available on davidkrk.com' |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + issues: write |
| 19 | + |
| 20 | +jobs: |
| 21 | + detect-new-music: |
| 22 | + name: Detect New Music & Generate Social Post |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + ref: gh-pages |
| 29 | + fetch-depth: 2 |
| 30 | + |
| 31 | + - name: Check for music changes |
| 32 | + id: changes |
| 33 | + run: | |
| 34 | + if git diff HEAD^ HEAD -- music.html | grep -q 'music-item'; then |
| 35 | + echo "new_music=true" >> $GITHUB_OUTPUT |
| 36 | + echo "🎵 New music detected!" |
| 37 | + else |
| 38 | + echo "new_music=false" >> $GITHUB_OUTPUT |
| 39 | + echo "No new music found" |
| 40 | + fi |
| 41 | +
|
| 42 | + - name: Extract new track info |
| 43 | + if: steps.changes.outputs.new_music == 'true' |
| 44 | + id: track_info |
| 45 | + run: | |
| 46 | + # Extract the last added track title from music.html |
| 47 | + TRACK_TITLE=$(grep -oP '(?<=<h3>).*?(?=</h3>)' music.html | tail -1) |
| 48 | + echo "track_title=$TRACK_TITLE" >> $GITHUB_OUTPUT |
| 49 | + echo "Detected track: $TRACK_TITLE" |
| 50 | +
|
| 51 | + - name: Generate social media post content |
| 52 | + if: steps.changes.outputs.new_music == 'true' |
| 53 | + id: generate_post |
| 54 | + run: | |
| 55 | + TRACK="${{ steps.track_info.outputs.track_title }}" |
| 56 | + |
| 57 | + cat << SOCIALPOST > social_post.txt |
| 58 | + 🎵 NEW TRACK ALERT! 🎵 |
| 59 | + |
| 60 | + "$TRACK" is now available! |
| 61 | + |
| 62 | + 🎧 Listen now: https://www.davidkrk.com/music.html |
| 63 | + |
| 64 | + #DavidKRK #NewMusic #DJ #Producer #ElectronicMusic #TechHouse |
| 65 | + SOCIALPOST |
| 66 | + |
| 67 | + cat social_post.txt |
| 68 | +
|
| 69 | + - name: Create notification issue |
| 70 | + if: steps.changes.outputs.new_music == 'true' |
| 71 | + uses: actions/github-script@v7 |
| 72 | + with: |
| 73 | + script: | |
| 74 | + const fs = require('fs'); |
| 75 | + const postContent = fs.readFileSync('social_post.txt', 'utf8'); |
| 76 | + |
| 77 | + await github.rest.issues.create({ |
| 78 | + owner: context.repo.owner, |
| 79 | + repo: context.repo.repo, |
| 80 | + title: '📱 Ready to post: ${{ steps.track_info.outputs.track_title }}', |
| 81 | + body: `## Social Media Post Ready\n\n${postContent}\n\n---\n\n**Next steps:**\n1. Copy the content above\n2. Post manually on your social networks\n3. Close this issue when done\n\n**Auto-posting is ready but requires API keys for:**\n- Facebook Pages API\n- Instagram Graph API\n- Twitter API v2\n\nTo enable auto-posting, add these secrets to your repository.`, |
| 82 | + labels: ['social-media', 'automated', 'new-music'] |
| 83 | + }); |
| 84 | +
|
| 85 | + - name: Save post for future auto-posting |
| 86 | + if: steps.changes.outputs.new_music == 'true' |
| 87 | + run: | |
| 88 | + mkdir -p .social-posts |
| 89 | + DATE=$(date +%Y-%m-%d_%H-%M-%S) |
| 90 | + cp social_post.txt ".social-posts/post_$DATE.txt" |
| 91 | + echo "Social post saved for future auto-posting" |
| 92 | +
|
| 93 | + # Future: uncomment when API keys are configured |
| 94 | + # post-to-facebook: |
| 95 | + # needs: detect-new-music |
| 96 | + # if: needs.detect-new-music.outputs.new_music == 'true' |
| 97 | + # runs-on: ubuntu-latest |
| 98 | + # steps: |
| 99 | + # - name: Post to Facebook |
| 100 | + # env: |
| 101 | + # FB_PAGE_TOKEN: ${{ secrets.FB_PAGE_TOKEN }} |
| 102 | + # run: | |
| 103 | + # curl -X POST "https://graph.facebook.com/v18.0/me/feed" \ |
| 104 | + # -d "message=$(cat social_post.txt)" \ |
| 105 | + # -d "access_token=$FB_PAGE_TOKEN" |
0 commit comments