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