diff --git a/.github/workflows/reactive_forms.yaml b/.github/workflows/reactive_forms.yaml index 838c900..3b28c56 100644 --- a/.github/workflows/reactive_forms.yaml +++ b/.github/workflows/reactive_forms.yaml @@ -1,13 +1,13 @@ name: reactive_forms on: - # Trigger the workflow on push - # but only for the master branch push: branches: - master - develop - "feature/**" + tags: + - '*' pull_request: branches: - master @@ -15,9 +15,7 @@ on: jobs: test: - # Job name is Running Tests name: Tests - # This job runs on Linux runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -58,3 +56,40 @@ jobs: run: dart format lib --set-exit-if-changed - name: Format test run: dart format test --set-exit-if-changed + + publish-warnings: + name: Publish warnings + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: subosito/flutter-action@v2 + with: + flutter-version: "3.16.0" + channel: "stable" + - run: flutter pub get + - name: Check publish warnings + run: dart pub publish --dry-run + + deployment: + if: ${{ github.ref_type == 'tag' }} + needs: [test, analyze, format, publish-warnings] + name: Deploy package + runs-on: ubuntu-latest + + steps: + - name: Configure enviroment + uses: actions/checkout@v3 + - name: Download flutter + uses: subosito/flutter-action@v2 + with: + flutter-version: "3.16.0" + channel: "stable" + - name: Setup pub credentials + shell: bash + env: + PUB_DEV_PUBLISH_ACCESS_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_ACCESS_TOKEN }} + PUB_DEV_PUBLISH_REFRESH_TOKEN: ${{ secrets.PUB_DEV_PUBLISH_REFRESH_TOKEN }} + run: | + sh ./tool/pub_login.sh + - name: Publish package + run: dart pub publish -v -f diff --git a/tool/pub_login.sh b/tool/pub_login.sh new file mode 100644 index 0000000..2853b25 --- /dev/null +++ b/tool/pub_login.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +# This script creates/updates credentials.json file which is used +# to authorize publisher when publishing packages to pub.dev + +# Checking whether the secrets are available as environment +# variables or not. +if [ -z "${PUB_DEV_PUBLISH_ACCESS_TOKEN}" ]; then + echo "Missing PUB_DEV_PUBLISH_ACCESS_TOKEN environment variable" + exit 1 +fi + +if [ -z "${PUB_DEV_PUBLISH_REFRESH_TOKEN}" ]; then + echo "Missing PUB_DEV_PUBLISH_REFRESH_TOKEN environment variable" + exit 1 +fi + +# Create credentials.json file. +mkdir -p ~/.config/dart +cat < ~/.config/dart/pub-credentials.json +{ + "accessToken": "${PUB_DEV_PUBLISH_ACCESS_TOKEN}", + "refreshToken": "${PUB_DEV_PUBLISH_REFRESH_TOKEN}", + "tokenEndpoint": "https://accounts.google.com/o/oauth2/token", + "scopes": ["https://www.googleapis.com/auth/userinfo.email","openid"], + "expiration": 1655303397262 +} +EOF