name: Release
on: [workflow_dispatch]
        
jobs:
  release_version:
    runs-on: macOS-latest
    steps:
      - uses: actions/checkout@v2
          
      - name: Publish release
        id: publish_release
        uses: release-drafter/release-drafter@v5
        with: 
          publish: true
        env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Update podspec 
        run: fastlane bump_version next_version:${{ steps.publish_release.outputs.tag_name }}

      - name: Commit changes
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          branch: 'main'
          commit_message: 'Bump version ${{ steps.publish_release.outputs.tag_name }}'
        env:
         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}      

      - name: Deploy to Cocoapods
        env:
          COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
        run: |
          set -eo pipefail
          pod lib lint --allow-warnings
          pod trunk push --allow-warnings  
          
      - name: Tweet the release
        uses: ethomson/send-tweet-action@v1
        with:
          consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
          consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }}
          access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }}
          access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
          status: |
            🎉 New release ${{ steps.publish_release.outputs.tag_name }} is out 🚀
            Check out all the changes here: 
            ${{ steps.publish_release.outputs.html_url }} 
