Skip to content

Commit

Permalink
Merge pull request #329 from deandreamatias/feature/198
Browse files Browse the repository at this point in the history
ci: Add deployment job to workflow
  • Loading branch information
joanpablo authored Mar 30, 2024
2 parents 40d917b + c9ae435 commit 1a3c954
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
43 changes: 39 additions & 4 deletions .github/workflows/reactive_forms.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
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
- develop

jobs:
test:
# Job name is Running Tests
name: Tests
# This job runs on Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -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
28 changes: 28 additions & 0 deletions tool/pub_login.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > ~/.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

0 comments on commit 1a3c954

Please sign in to comment.