From 57dc95eafbe8abb4e1013149371a196f1ef8e0f5 Mon Sep 17 00:00:00 2001 From: Efra Espada Date: Sun, 6 Oct 2024 20:45:14 +0200 Subject: [PATCH] feature: added publish workflow --- .github/workflows/tag_version_and_publish.yml | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .github/workflows/tag_version_and_publish.yml diff --git a/.github/workflows/tag_version_and_publish.yml b/.github/workflows/tag_version_and_publish.yml new file mode 100644 index 0000000..92192dd --- /dev/null +++ b/.github/workflows/tag_version_and_publish.yml @@ -0,0 +1,116 @@ +name: Tag Version and Publish on Push to Master + +on: + push: + branches: + - master + +jobs: + tag_version_and_publish: + + runs-on: self-hosted + + steps: + - uses: actions/checkout@v4 + + - name: Read version from pubspec.yml + id: read_version + run: | + VERSION=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2) + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Create tag + id: create_tag + run: | + # Checks if the tag already exists in the remote repository + if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then + echo "Error: Tag v${{ env.VERSION }} already exists." + exit 1 + fi + + # Check if the version was found + if [ -z "${{ env.VERSION }}" ]; then + echo "Error: No version found in pubspec.yml" + exit 1 + fi + + git tag "v${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" + + - name: Handle job completion + if: always() + run: | + if [ "${{ job.status }}" == "failure" ]; then + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🔴 Creation Tag Failed" \ + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + elif [ "${{ job.status }}" == "cancelled" ]; then + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🟠 Creation Tag Canceled" \ + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + else + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🟢 Creation Tag Passed" \ + --body "${{ github.repository }}: Tag v${{ env.VERSION }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + fi + + - run: flutter pub get + + - run: dart pub publish --dry-run + + - run: dart pub publish -f + + - name: Handle publish job completion + if: always() + run: | + if [ "${{ job.status }}" == "failure" ]; then + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🔴 Pub Publish Failed" \ + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + elif [ "${{ job.status }}" == "cancelled" ]; then + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🟠 Pub Publish Canceled" \ + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + else + landa-messenger-api chat-send \ + --id "${{ secrets.CHAT_ID }}" \ + --api_key "${{ secrets.CHAT_KEY }}" \ + --title "🟢 Pub Publish Passed" \ + --body "${{ github.repository }}: ${{ github.event.head_commit.message }}" \ + --url "https://github.com/landamessenger/catalog/actions/workflows/tag_version_and_publish.yml" \ + --image "https://avatars.githubusercontent.com/u/63705403?s=200&v=4" \ + --background_color "#55000000" \ + --text_color "#FFFFFFFF" + fi + +