Skip to content

Commit

Permalink
Fixed IAP stub in workflows (#110)
Browse files Browse the repository at this point in the history
* try using script for iap stub

* typo

* typo

* typo

* removed working dir

* added comment to stub_iap.sh

* checkout first

* increment build number by script

* Update increment_build_number.sh

* fixed iap repo

* stub
  • Loading branch information
vodemn committed Sep 2, 2023
1 parent 4bb080a commit da4fcfc
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
8 changes: 8 additions & 0 deletions .github/scripts/increment_build_number.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .github/scripts/stub_iap.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 6 additions & 7 deletions .github/workflows/build_apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
if: ${{ inputs.include-iap }}
Expand All @@ -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"
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
if: ${{ inputs.include-iap }}
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
19 changes: 7 additions & 12 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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:
Expand Down
12 changes: 10 additions & 2 deletions iap/lib/src/data/models/iap_product.dart
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion iap/lib/src/providers/iap_products_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class IAPProducts extends InheritedModel<IAPProductType> {
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;

Expand Down

0 comments on commit da4fcfc

Please sign in to comment.