Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add deployment job to workflow #329

Merged
merged 4 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading