From b3e510673d272c0aae8f8ed6fa95af3c43128c28 Mon Sep 17 00:00:00 2001 From: Shahroz Khan Date: Fri, 6 Sep 2024 15:32:10 +0500 Subject: [PATCH] ci: fixed the automated deployment workflow (#144) --- .github/workflows/deploy_pubspec.yml | 86 ------------- ...{deploy_git_tag.yml => tag-and-deploy.yml} | 115 +++++++++++++++--- apps/amiapp_flutter/pubspec.lock | 4 +- 3 files changed, 98 insertions(+), 107 deletions(-) delete mode 100644 .github/workflows/deploy_pubspec.yml rename .github/workflows/{deploy_git_tag.yml => tag-and-deploy.yml} (51%) diff --git a/.github/workflows/deploy_pubspec.yml b/.github/workflows/deploy_pubspec.yml deleted file mode 100644 index d8482dc..0000000 --- a/.github/workflows/deploy_pubspec.yml +++ /dev/null @@ -1,86 +0,0 @@ -name: Publish Package - -on: - release: - types: [published] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup-flutter - - name: Publish - uses: k-paxian/dart-package-publisher@v1.6 - with: - credentialJson: ${{ secrets.CREDENTIAL_JSON }} - flutter: true - - name: Notify team of successful deployment - uses: slackapi/slack-github-action@v1.26.0 - if: ${{ success() }} - with: - # Use block kit to format the Slack message: https://app.slack.com/block-kit-builder - payload: | - { - "text": "Flutter SDK deployed to pub.dev", - "username": "Flutter deployment bot", - "icon_url": "https://img.icons8.com/color/512/flutter.png", - "channel": "#mobile-deployments", - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Flutter* SDK deployed to pub.dev! (deployment step 2 of 2)" - } - }, - { - "type": "divider" - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Version ${{ github.event.release.tag_name }}*\n\nFlutter SDK deployment progress:\n ~1. ~\n~2. deploy to pub.dev~\n\n" - } - } - ] - } - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK - - - name: Notify team of failure - uses: slackapi/slack-github-action@v1.26.0 - if: ${{ failure() }} # only run this if any previous step failed - with: - # Use block kit to format the Slack message: https://app.slack.com/block-kit-builder - payload: | - { - "text": "Flutter SDK deployment failure", - "username": "Flutter deployment bot", - "icon_url": "https://img.icons8.com/color/512/flutter.png", - "channel": "#mobile-deployments", - "blocks": [ - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "*Flutter* SDK deployment :warning: failure :warning:" - } - }, - { - "type": "divider" - }, - { - "type": "section", - "text": { - "type": "mrkdwn", - "text": "Flutter SDK failed deployment during step *deploy to pub.dev*. View to learn why and fix the issue. ." - } - } - ] - } - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK diff --git a/.github/workflows/deploy_git_tag.yml b/.github/workflows/tag-and-deploy.yml similarity index 51% rename from .github/workflows/deploy_git_tag.yml rename to .github/workflows/tag-and-deploy.yml index dc0e2b1..84716d7 100644 --- a/.github/workflows/deploy_git_tag.yml +++ b/.github/workflows/tag-and-deploy.yml @@ -1,34 +1,28 @@ -name: Deploy git tag +name: Deploy Flutter SDK -# Only run after a pull request has been merged. This is because -# bot account runs write operations on the github repo to push a tag. on: push: branches: [main] permissions: - contents: write # access to push the git tag - issues: write # Bot creates an issue if there is an issue during deployment process - pull-requests: write # allow bot to make comments on PRs after they get deployed + contents: write + issues: write + pull-requests: write jobs: deploy-git-tag: name: Deploy git tag runs-on: ubuntu-latest outputs: - new_release_git_head: ${{ steps.semantic-release.outputs.new_release_git_head }} new_release_published: ${{ steps.semantic-release.outputs.new_release_published }} new_release_version: ${{ steps.semantic-release.outputs.new_release_version }} steps: - uses: actions/checkout@v4 - # CLI to replace strings in files. The CLI recommends using `cargo install` which is slow. This Action is fast because it downloads pre-built binaries. - # If using sd on macos, "brew install" works great. for Linux, this is the recommended way. - - name: Install sd CLI to use later in the workflow - # uses: kenji-miyake/setup-sd@v1 - uses: levibostian/setup-sd@add-file-extension # Using fork until upstream Action has bug fixed in it. + - name: Install sd CLI + uses: levibostian/setup-sd@add-file-extension - - name: Deploy git tag via semantic release + - name: Deploy git tag via semantic-release uses: cycjimmy/semantic-release-action@v4 id: semantic-release with: @@ -38,14 +32,12 @@ jobs: @semantic-release/github @semantic-release/exec env: - # Needs to push git commits to repo. Needs write access. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Notify team of git tag being created + - name: Notify team of git tag creation uses: slackapi/slack-github-action@v1.26.0 if: steps.semantic-release.outputs.new_release_published == 'true' with: - # Use block kit to format the Slack message: https://app.slack.com/block-kit-builder payload: | { "text": "Flutter SDK git tag created", @@ -78,7 +70,7 @@ jobs: - name: Send Velocity Deployment uses: codeclimate/velocity-deploy-action@v1.0.0 - if: steps.semantic-release.outputs.new_release_published == 'true' # only run if a git tag was made. + if: steps.semantic-release.outputs.new_release_published == 'true' with: token: ${{ secrets.VELOCITY_DEPLOYMENT_TOKEN }} version: ${{ steps.semantic-release.outputs.new_release_version }} @@ -86,9 +78,8 @@ jobs: - name: Notify team of failure uses: slackapi/slack-github-action@v1.26.0 - if: ${{ failure() }} # only run this if any previous step failed + if: ${{ failure() }} with: - # Use block kit to format the Slack message: https://app.slack.com/block-kit-builder payload: | { "text": "Flutter SDK deployment failure", @@ -118,3 +109,89 @@ jobs: env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + + deploy-to-pub-dev: + name: Deploy to pub.dev + needs: [deploy-git-tag] + if: needs.deploy-git-tag.outputs.new_release_published == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ needs.deploy-git-tag.outputs.new_release_version }} + + - uses: ./.github/actions/setup-flutter + + - name: Publish to pub.dev + uses: k-paxian/dart-package-publisher@v1.6 + with: + credentialJson: ${{ secrets.CREDENTIAL_JSON }} + flutter: true + + - name: Notify team of successful deployment + uses: slackapi/slack-github-action@v1.26.0 + if: ${{ success() }} + with: + payload: | + { + "text": "Flutter SDK deployed to pub.dev", + "username": "Flutter deployment bot", + "icon_url": "https://img.icons8.com/color/512/flutter.png", + "channel": "#mobile-deployments", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Flutter* SDK deployed to pub.dev! (deployment step 2 of 2)" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Version ${{ needs.deploy-git-tag.outputs.new_release_version }}*\n\nFlutter SDK deployment progress:\n ~1. ~\n~2. deploy to pub.dev~\n\n" + } + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + + - name: Notify team of failure + uses: slackapi/slack-github-action@v1.26.0 + if: ${{ failure() }} + with: + payload: | + { + "text": "Flutter SDK deployment failure", + "username": "Flutter deployment bot", + "icon_url": "https://img.icons8.com/color/512/flutter.png", + "channel": "#mobile-deployments", + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "*Flutter* SDK deployment :warning: failure :warning:" + } + }, + { + "type": "divider" + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Flutter SDK failed deployment during step *deploy to pub.dev*. View to learn why and fix the issue. ." + } + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK \ No newline at end of file diff --git a/apps/amiapp_flutter/pubspec.lock b/apps/amiapp_flutter/pubspec.lock index 05cd0f8..e3501bf 100644 --- a/apps/amiapp_flutter/pubspec.lock +++ b/apps/amiapp_flutter/pubspec.lock @@ -616,10 +616,10 @@ packages: dependency: transitive description: name: vm_service - sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.4" + version: "14.2.5" web: dependency: transitive description: