Skip to content

Commit

Permalink
Merge pull request #6 from lcuis/master
Browse files Browse the repository at this point in the history
more stars for k-paxian dart-package-publisher
  • Loading branch information
k-paxian authored Feb 25, 2020
2 parents 8a71b2a + b054616 commit c7569fb
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
*.swp
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
[![Build Status][ci-badge]][ci-badge-url]

## Description

Continuously Test & Publish Dart and Flutter Package To Pub.dev When Version Changed

## The Challenge

Usually, when you are trying to `pub lish` your package and your `pubspec.yaml` has *the same* version as already published, you'll have a non zero exit code from `pub` tool and your workflow is **red**.
Usually, when you are trying to `pub lish` your Dart package (or `pub publish` your Flutter package) and your `pubspec.yaml` has *the same* version as already published, you'll have a non zero exit code from `pub` tool and
your workflow is **red**.
So you cannot directly hook publish command as an re-action to `on: push` event.

To keep a workflow **green** on each push, you have to prevent publishing step if versions are the same,
Expand All @@ -16,6 +21,8 @@ on: [push, pull_request]
```
and forget about it. When you need to publish a package, just bump the version in `pubspec.yaml`.

![dart-package-publisher](doc/images/dart-package-publisher.png)

## Inputs

### `accessToken`
Expand All @@ -34,6 +41,14 @@ Put it as `secrets.OAUTH_REFRESH_TOKEN` on your repo [secrets section][1]
You can find the credentials.json within `.pub-cache` in the User's home directory.
You can use `open ~/.pub-cache`.

### `credentialJson`

Replaces `accessToken` and `refreshToken` and contains the whole content of the `~/.pub-cache/credentials.json` file
Put it as `secrets.CREDENTIAL_JSON` on your repo [secrets section][1]

You can find the credentials.json within `.pub-cache` in the User's home directory.
You can use `open ~/.pub-cache` after your first publication either through `pub lish` command for Dart or `pub publish` for Flutter.

### `relativePath`

**Optional** Path to your package root in your repository. In case you have a mono-repo, like this [one][2]
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Dart Package Publisher'
description: 'Continuously Test & Publish Dart Package To Pub.dev'
name: 'Dart and Flutter Package Publisher'
description: 'Continuously Test & Publish Dart and Flutter Package To Pub.dev When Version Changed'
author: 'k-paxian'
branding:
color: 'blue'
Expand All @@ -11,6 +11,9 @@ inputs:
refreshToken:
description: '(Required) Token from ~/.pub-cache/credentials.json. Use secrets.OAUTH_REFRESH_TOKEN'
required: true
credentialJson:
description: '(Optional) Overrides accessToken and refreshToken. Whole content of ~/.pub-cache/credentials.json. Use secrets.CREDENTIAL_JSON'
required: false
relativePath:
description: '(Optional) Path to your package root in your repository'
required: false
Expand Down
1 change: 1 addition & 0 deletions doc/images/dart-package-publisher.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<mxfile host="www.draw.io" modified="2020-02-25T10:40:54.854Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.26 Safari/537.36" etag="RFamyJlJbimA4pnClt8r" version="12.7.4" type="device"><diagram id="C5RBs43oDa-KdzZeNtuy" name="Page-1">7Vtbd6M2EP4tffBjcgABth83F++2zW63zW6T9KVHBtnQCOSCHNv99ZWMuEkYX2JgHeecnBx0QRIz842+mUl64DpYfozgzPtMXIR7huYue+CmZxi6aRg9/qO5q6THHvSTjmnku2JS3nHv/4dEpyZ6576L4tJESgim/qzc6ZAwRA4t9cEoIovytAnB5V1ncIqUjnsHYrX3wXepl/QOjH7e/wn5Uy/dWbeHyUgA08niS2IPumRR6AK3PXAdEUKTp2B5jTAXXiqXh59XD/ju2f74y+/xv/D71a/fvvx5kSw22ueV7BMiFNKDl/7y3bh7sX8jf3wOHv8aadpziLSLVLsvEM+FwMTH0lUqwYjMQxfxVbQeuFp4PkX3M+jw0QWzGdbn0QCzls4exXIoomgpKWDL6fVMpMwWEQkQjVbsPbGKLZSwyHVoA9HnFfRnpnYHhd1Ms6Vy2bAHIZ49tLC3pApS+QdRuhLYgHNKWBeJqE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HAd921jVeR5jKsG6PQplnSmqFGKbrVJoVWszHn5vCaprCDXf1NW/XbulOeXP32+BA1+3qZ9Heeqhkqunmv37ZQv23OJexO1jfEte0XcE2rjIoGC7jVklDzle8V3OYruD8CBoxaDLRYw+1LGDi4hmub0kIN1XBtXS46H7eGW6vYcy3itsBIWi3i1oDydVXcrkt9UhXXtdDANZV4k40MjDGw7QYVbFlSUqBzyqlX/T3n6ai2KUWB4Q+nqB0ylidVx7WMsrPrvI6r/ungsQTcWSHX2pSE7KqQq6vZxBrfcYrM/ewruamj2sr3B9Wm+8q8uwUkDnVoKdcaSv6p5Tj4PWH7lmq5teRre2hstYKVg4u5XWNFTWqfLVbeQDW3NhDtCiu2RFcPrudaugS6luu5ulplEAVdl3HVC1HtuVhHgXFS4U3DPQlSb7uCa1pWSU8NVnBZM/836kTP+T+jg9v/AQ==</diagram></mxfile>
Binary file added doc/images/dart-package-publisher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 34 additions & 27 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ export PATH="$PATH":"$HOME/.pub-cache/bin"

check_required_inputs() {
echo "Check inputs..."
if [ -z "$INPUT_ACCESSTOKEN" ]; then
echo "Missing accessToken"
exit 1
fi
if [ -z "$INPUT_REFRESHTOKEN" ]; then
echo "Missing refreshToken"
exit 1
if [ -z "$INPUT_CREDENTIALJSON" ]; then
echo "Missing credentialJson, trying tokens"
if [ -z "$INPUT_ACCESSTOKEN" ]; then
echo "Missing accessToken"
exit 1
fi
if [ -z "$INPUT_REFRESHTOKEN" ]; then
echo "Missing refreshToken"
exit 1
fi
fi
echo "OK"
}
Expand All @@ -22,7 +25,7 @@ switch_working_directory() {
:
else
echo "Switching to package directory '$INPUT_RELATIVEPATH'"
cd "$INPUT_RELATIVEPATH"
cd "$INPUT_RELATIVEPATH"
fi
echo "Package dir: $PWD"
}
Expand All @@ -46,16 +49,16 @@ get_local_package_version() {
PACKAGE_INFO=`echo "$DEPS_OUTPUT" | cut -d'|' -f1 | cut -d"'" -f1 | sed '/^\s*$/d'`
IFS=$'\n\r' read -d '' -r -a lines <<< "$PACKAGE_INFO"
lastIndex=`expr ${#lines[@]}-1`
echo "$PACKAGE_INFO"
echo "$PACKAGE_INFO"
DART_VERSION=`echo "$PACKAGE_INFO" | perl -n -e'/^Dart SDK (.*)$/ && print $1'`
FLUTTER_VERSION=`echo "$PACKAGE_INFO" | perl -n -e'/^Flutter SDK (.*)$/ && print $1'`
PACKAGE_INFO="${lines[$lastIndex]}"
PACKAGE=`echo "$PACKAGE_INFO" | cut -d' ' -f1`
LOCAL_PACKAGE_VERSION=`echo "$PACKAGE_INFO" | cut -d' ' -f2`
PACKAGE_INFO="${lines[$lastIndex]}"
PACKAGE=`echo "$PACKAGE_INFO" | cut -d' ' -f1`
LOCAL_PACKAGE_VERSION=`echo "$PACKAGE_INFO" | cut -d' ' -f2`
if [ -z "$PACKAGE" ]; then
echo "No package found. :("
exit 0
fi
fi
echo "::set-output name=dartVersion::$DART_VERSION"
if [ "$FLUTTER_VERSION" != "" ]; then
echo "::set-output name=flutterVersion::$FLUTTER_VERSION"
Expand Down Expand Up @@ -86,8 +89,8 @@ run_unit_tests() {
fi
else
echo "No unit test related dependencies detected, skip unit testing."
fi
fi
fi
fi
fi
}

Expand All @@ -101,7 +104,7 @@ get_remote_package_version() {
if [ -z "$REMOTE_PACKAGE_VERSION" ]; then
REMOTE_PACKAGE_VERSION=""
fi
echo "Local version: [$LOCAL_PACKAGE_VERSION]"
echo "Local version: [$LOCAL_PACKAGE_VERSION]"
echo "Remote version: [$REMOTE_PACKAGE_VERSION]"
echo "::set-output name=remoteVersion::$REMOTE_PACKAGE_VERSION"
}
Expand All @@ -111,15 +114,19 @@ publish() {
echo "Remote & Local versions are equal, skip publishing."
else
mkdir -p ~/.pub-cache
cat <<-EOF > ~/.pub-cache/credentials.json
{
"accessToken":"$INPUT_ACCESSTOKEN",
"refreshToken":"$INPUT_REFRESHTOKEN",
"tokenEndpoint":"https://accounts.google.com/o/oauth2/token",
"scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ],
"expiration": 1577149838000
}
if [ -z "$INPUT_CREDENTIALJSON" ]; then
cat <<-EOF > ~/.pub-cache/credentials.json
{
"accessToken":"$INPUT_ACCESSTOKEN",
"refreshToken":"$INPUT_REFRESHTOKEN",
"tokenEndpoint":"https://accounts.google.com/o/oauth2/token",
"scopes": [ "openid", "https://www.googleapis.com/auth/userinfo.email" ],
"expiration": 1577149838000
}
EOF
else
echo "$INPUT_CREDENTIALJSON" > ~/.pub-cache/credentials.json
fi
if [ "$INPUT_FLUTTER" = "true" ]; then
flutter pub publish --dry-run
else
Expand All @@ -130,7 +137,7 @@ EOF
else
echo "Dry Run Failed, skip real publishing."
exit 0
fi
fi
if [ "$INPUT_DRYRUNONLY" = "true" ]; then
echo "Dry run only, skip publishing."
else
Expand All @@ -143,9 +150,9 @@ EOF
echo "::set-output name=success::true"
else
echo "::set-output name=success::false"
fi
fi
fi
fi
fi
}

check_required_inputs
Expand Down

0 comments on commit c7569fb

Please sign in to comment.