diff --git a/.github/scripts/increment_build_number.sh b/.github/scripts/increment_build_number.sh new file mode 100644 index 0000000..520455f --- /dev/null +++ b/.github/scripts/increment_build_number.sh @@ -0,0 +1,8 @@ +export newVersion="$1" + +if [[ -n "$newVersion" ]]; then + #https://stackoverflow.com/a/30214769/13167574 + perl -i -pe 's/^(version:\s+)(\d+\.\d+\.\d+)(\+)(\d+)$/$1.$ENV{'newVersion'}.$3.($4+1)/e' pubspec.yaml +else + echo "argument error" +fi diff --git a/.github/scripts/stub_iap.sh b/.github/scripts/stub_iap.sh new file mode 100644 index 0000000..210e1ea --- /dev/null +++ b/.github/scripts/stub_iap.sh @@ -0,0 +1,2 @@ +# https://unix.stackexchange.com/questions/435708/regex-multiline-pattern-and-substitution-replacement +perl -0777 -i -pe 's/( m3_lightmeter_iap:\n)( git:\n url: "https:\/\/github.com\/vodemn\/m3_lightmeter_iap"\n ref: main)/$1 path: iap/sg' pubspec.yaml \ No newline at end of file diff --git a/.github/workflows/build_apk.yml b/.github/workflows/build_apk.yml index e61b38b..6acb464 100644 --- a/.github/workflows/build_apk.yml +++ b/.github/workflows/build_apk.yml @@ -27,6 +27,10 @@ jobs: runs-on: macos-11 timeout-minutes: 15 steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Connect private iap package uses: webfactory/ssh-agent@v0.8.0 if: ${{ inputs.include-iap }} @@ -35,13 +39,8 @@ jobs: - name: Override iap package with stub if: ${{ !inputs.include-iap }} - run: | - echo "\ndependency_overrides:\n m3_lightmeter_iap:\n path: iap" >> pubspec.yaml - - - uses: actions/checkout@v3 - with: - submodules: recursive - + run: bash ./.github/scripts/stub_iap.sh + - uses: actions/setup-java@v2 with: distribution: "zulu" diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index e0281e3..69a672b 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -46,6 +46,10 @@ jobs: runs-on: macos-11 timeout-minutes: 30 steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Connect private iap package uses: webfactory/ssh-agent@v0.8.0 if: ${{ inputs.include-iap }} @@ -54,12 +58,7 @@ jobs: - name: Override iap package with stub if: ${{ !inputs.include-iap }} - run: | - echo "\ndependency_overrides:\n m3_lightmeter_iap:\n path: iap" >> pubspec.yaml - - - uses: actions/checkout@v3 - with: - submodules: recursive + run: bash ./.github/scripts/stub_iap.sh - uses: actions/setup-java@v3 with: @@ -98,7 +97,7 @@ jobs: # Therefore here we have to increment it as well to build an apk with the same build number. - name: Increment build number & replace version number if: ${{ inputs.github-release }} - run: perl -i -pe 's/^(version:\s+)(\d+\.\d+\.\d+)(\+)(\d+)$/$1."${{ github.event.inputs.version }}".$3.($4+1)/e' pubspec.yaml + run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} - name: Install Flutter uses: subosito/flutter-action@v2 @@ -160,7 +159,7 @@ jobs: submodules: recursive - name: Increment build number & replace version number - run: perl -i -pe 's/^(version:\s+)(\d+\.\d+\.\d+)(\+)(\d+)$/$1."${{ github.event.inputs.version }}".$3.($4+1)/e' pubspec.yaml + run: bash ./.github/scripts/increment_build_number.sh ${{ github.event.inputs.version }} - name: Commit changes run: | diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index e6f0294..70e6fa4 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -11,30 +11,25 @@ on: pull_request: branches: ["main"] -env: - # Stub iap package if this worlflow is running from the PR from a fork - STUB_IAP: ${{ github.event.pull_request.head.repo.full_name != github.repository }} - jobs: analyze_and_test: name: Analyze & test runs-on: macos-11 timeout-minutes: 10 steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Connect private iap package uses: webfactory/ssh-agent@v0.8.0 - if: !env.STUB_IAP + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} with: ssh-private-key: ${{ secrets.M3_LIGHTMETER_IAP_KEY }} - name: Override iap package with stub - if: env.STUB_IAP - run: | - echo "\ndependency_overrides:\n m3_lightmeter_iap:\n path: iap" >> pubspec.yaml - - - uses: actions/checkout@v3 - with: - submodules: recursive + if: ${{ github.event.pull_request.head.repo.full_name != github.repository }} + run: bash ./.github/scripts/stub_iap.sh - uses: subosito/flutter-action@v2 with: diff --git a/iap/lib/src/data/models/iap_product.dart b/iap/lib/src/data/models/iap_product.dart index 706e3f1..ba24c17 100644 --- a/iap/lib/src/data/models/iap_product.dart +++ b/iap/lib/src/data/models/iap_product.dart @@ -1,5 +1,13 @@ +enum IAPProductStatus { + purchasable, + pending, + purchased, +} + enum IAPProductType { paidFeatures } -class IAPProduct { - IAPProduct(); +abstract class IAPProduct { + const IAPProduct._(); + + IAPProductStatus get status => IAPProductStatus.purchasable; } diff --git a/iap/lib/src/providers/iap_products_provider.dart b/iap/lib/src/providers/iap_products_provider.dart index 4ea3c98..3014cd9 100644 --- a/iap/lib/src/providers/iap_products_provider.dart +++ b/iap/lib/src/providers/iap_products_provider.dart @@ -35,7 +35,7 @@ class IAPProducts extends InheritedModel { super.key, }); - static IAPProduct? of(BuildContext context, IAPProductType type) => null; + static IAPProduct? productOf(BuildContext context, IAPProductType type) => null; static bool isPurchased(BuildContext context, IAPProductType type) => false;