|
| 1 | +name: Tag Version and Publish on Push to Master |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - closed |
| 7 | + branches: |
| 8 | + - master |
| 9 | + |
| 10 | +jobs: |
| 11 | + tag_version_and_publish: |
| 12 | + if: github.event.pull_request.merged == true |
| 13 | + |
| 14 | + runs-on: self-hosted |
| 15 | + |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Read version from pubspec.yml |
| 20 | + id: read_version |
| 21 | + run: | |
| 22 | + VERSION=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2) |
| 23 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 24 | +
|
| 25 | + - name: Create tag |
| 26 | + id: create_tag |
| 27 | + run: | |
| 28 | + # Check if the tag already exists in the remote repository |
| 29 | + if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then |
| 30 | + echo "Tag v${{ env.VERSION }} already exists." |
| 31 | + else |
| 32 | + # Create and push the new tag |
| 33 | + git tag "v${{ env.VERSION }}" |
| 34 | + git push origin "v${{ env.VERSION }}" |
| 35 | + fi |
| 36 | +
|
| 37 | + - name: Create release |
| 38 | + if: ${{ steps.create_tag.outcome == 'success' }} |
| 39 | + uses: softprops/action-gh-release@v2 |
| 40 | + with: |
| 41 | + tag_name: "v${{ env.VERSION }}" |
| 42 | + name: "${{ github.event.pull_request.title }}" |
| 43 | + body: "${{ github.event.pull_request.body }}" |
| 44 | + env: |
| 45 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Handle job completion |
| 48 | + if: always() |
| 49 | + run: | |
| 50 | + if [ "${{ job.status }}" == "failure" ]; then |
| 51 | + landa-messenger-api chat-send \ |
| 52 | + --id "${{ secrets.CHAT_ID }}" \ |
| 53 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 54 | + --title "🔴 Creation Tag Failed" \ |
| 55 | + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ |
| 56 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 57 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 58 | + --background_color "#55000000" \ |
| 59 | + --text_color "#FFFFFFFF" |
| 60 | + elif [ "${{ job.status }}" == "cancelled" ]; then |
| 61 | + landa-messenger-api chat-send \ |
| 62 | + --id "${{ secrets.CHAT_ID }}" \ |
| 63 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 64 | + --title "🟠 Creation Tag Canceled" \ |
| 65 | + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ |
| 66 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 67 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 68 | + --background_color "#55000000" \ |
| 69 | + --text_color "#FFFFFFFF" |
| 70 | + else |
| 71 | + landa-messenger-api chat-send \ |
| 72 | + --id "${{ secrets.CHAT_ID }}" \ |
| 73 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 74 | + --title "🟢 Creation Tag Passed" \ |
| 75 | + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ |
| 76 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 77 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 78 | + --background_color "#55000000" \ |
| 79 | + --text_color "#FFFFFFFF" |
| 80 | + fi |
| 81 | +
|
| 82 | + - run: flutter pub get |
| 83 | + |
| 84 | + - run: dart pub publish --dry-run |
| 85 | + |
| 86 | + - run: dart pub publish -f |
| 87 | + |
| 88 | + - name: Handle publish job completion |
| 89 | + if: always() |
| 90 | + run: | |
| 91 | + if [ "${{ job.status }}" == "failure" ]; then |
| 92 | + landa-messenger-api chat-send \ |
| 93 | + --id "${{ secrets.CHAT_ID }}" \ |
| 94 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 95 | + --title "🔴 Pub Publish Failed" \ |
| 96 | + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ |
| 97 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 98 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 99 | + --background_color "#55000000" \ |
| 100 | + --text_color "#FFFFFFFF" |
| 101 | + elif [ "${{ job.status }}" == "cancelled" ]; then |
| 102 | + landa-messenger-api chat-send \ |
| 103 | + --id "${{ secrets.CHAT_ID }}" \ |
| 104 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 105 | + --title "🟠 Pub Publish Canceled" \ |
| 106 | + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ |
| 107 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 108 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 109 | + --background_color "#55000000" \ |
| 110 | + --text_color "#FFFFFFFF" |
| 111 | + else |
| 112 | + landa-messenger-api chat-send \ |
| 113 | + --id "${{ secrets.CHAT_ID }}" \ |
| 114 | + --api_key "${{ secrets.CHAT_KEY }}" \ |
| 115 | + --title "🟢 Pub Publish Passed" \ |
| 116 | + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ |
| 117 | + --url "https://github.com/landamessenger/firebase_cloud_firestore/actions/workflows/tag_version_and_publish.yml" \ |
| 118 | + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ |
| 119 | + --background_color "#55000000" \ |
| 120 | + --text_color "#FFFFFFFF" |
| 121 | + fi |
| 122 | + |
| 123 | + |
0 commit comments