Skip to content

Commit

Permalink
feat(fastlane): update fastlane actions
Browse files Browse the repository at this point in the history
  • Loading branch information
crherman7 committed Mar 11, 2024
1 parent 238f947 commit dfbe2c9
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 227 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"eslint": "^8.25.0",
"eslint-config-eslint": "^7.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-jsdoc": "^39.3.12",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"format-package": "^7.0.0",
Expand Down
37 changes: 19 additions & 18 deletions packages/plugin-fastlane/assets/android/fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
default_platform :android

lane :assemble do
# assemble the release variant i.e. apk
gradle(task: "assembleRelease")
end

lane :bundle do
# bundle the release variant i.e. aab
gradle(task: "bundleRelease")
end

<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%>
lane :increment_build do
begin
version = appcenter_fetch_version_number(
owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>",
app_name: "<%= codePluginFastlane.plugin.android.appCenter.appName %>",
<%_ if (!release) { -%>
version: "<%- android.versioning?.version || "1.0.0" %>"
<%_ } -%>
version: "<%- android.versioning && android.versioning.version || "1.0.0" %>"
)
if version["build_number"]
Expand All @@ -20,11 +29,13 @@ lane :increment_build do
puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number"
end
end
<% } -%>
lane :appcenter do
<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.android && codePluginFastlane.plugin.android.appCenter) { -%>
lane :appcenter_assemble do
increment_build
# build the release variant
gradle(task: "app:assembleRelease")
assemble
appcenter_upload(
owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>",
Expand All @@ -35,12 +46,7 @@ lane :appcenter do
end
lane :appcenter_bundle do
<%_ if (!android.versioning?.build) { -%>
increment_build
<%_ } -%>
# build the release variant
gradle(task: "bundleRelease")
bundle
appcenter_upload(
owner_name: "<%= codePluginFastlane.plugin.android.appCenter.organization %>",
Expand All @@ -49,9 +55,4 @@ lane :appcenter_bundle do
destinations: "<%= codePluginFastlane.plugin.android.appCenter.destinations %>"
)
end

lane :build do
# build the release variant
gradle(task: "app:assembleRelease")

end
<% } -%>
77 changes: 61 additions & 16 deletions packages/plugin-fastlane/assets/ios/fastlane/Fastfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
default_platform :ios

# make a provisioned build and upload to appcenter
lane :build do
keychain_password = SecureRandom.uuid
keychain_name = 'ios-build.keychain'
@profiles = []

create_keychain(
name: keychain_name,
password: keychain_password,
unlock: true,
timeout: 3600
)

import_certificate(
certificate_path: 'ios-build-key.p12',
certificate_password: ENV['DISTRIBUTION_CERT_PASS'],
keychain_name: keychain_name,
keychain_password: keychain_password,
log_output: true
)

import_certificate(
certificate_path: 'ios-build-key.cer',
certificate_password: ENV['DISTRIBUTION_CERT_PASS'],
keychain_name: keychain_name,
keychain_password: keychain_password,
log_output: true
)

import_certificate(
certificate_path: 'AppleWWDRCA.cer',
keychain_name: keychain_name,
keychain_password: keychain_password,
log_output: true
)

@profiles.each { |profile| install_provisioning_profile(path: profile) }

gym(
clean: true,
export_method: "<%= ios.signing.exportMethod %>",
export_team_id: "<%= ios.signing.exportTeamId %>"
)

delete_keychain(name: keychain_name)
end

# make an unprovisioned build
lane :compile do
gym(
xcargs: "CODE_SIGN_IDENTITY='' CODE_SIGNING_REQUIRED='NO' CODE_SIGN_ENTITLEMENTS='' CODE_SIGNING_ALLOWED='NO'"
)
end

<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%>
lane :increment_build do
begin
version = appcenter_fetch_version_number(
owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>",
app_name: "<%= codePluginFastlane.plugin.ios.appCenter.appName %>",
version: "<%= ios.versioning.version %>"
version: "<%= ios.versioning && ios.versioning.version || "1.0.0" %>"
)
if version["build_number"]
build_number = increment_build_number(
Expand All @@ -17,16 +72,13 @@ lane :increment_build do
puts "Fastlane: did not find any applicable versions for appcenter_fetch_version_number"
end
end
<% } -%>
# make a provisioned build and upload to appcenter
<% if(codePluginFastlane.plugin && codePluginFastlane.plugin.ios && codePluginFastlane.plugin.ios.appCenter) { -%>
lane :appcenter do
increment_build
gym(
scheme: "<%= codePluginFastlane.plugin.ios.buildScheme %>",
clean: true,
export_method: "<%= ios.signing.exportMethod %>",
export_team_id: "<%= ios.signing.exportTeamId %>"
)
build
appcenter_upload(
owner_name: "<%= codePluginFastlane.plugin.ios.appCenter.organization %>",
Expand All @@ -35,11 +87,4 @@ lane :appcenter do
destinations: "<%= codePluginFastlane.plugin.ios.appCenter.destinations %>"
)
end

# make an unprovisioned build
lane :build do
xcodebuild(
scheme: "<%= codePluginFastlane.plugin.ios.buildScheme %>",
xcargs: "CODE_SIGN_IDENTITY='' CODE_SIGNING_REQUIRED='NO' CODE_SIGN_ENTITLEMENTS='' CODE_SIGNING_ALLOWED='NO'"
)
end
<% } -%>
86 changes: 85 additions & 1 deletion packages/plugin-fastlane/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import path from "path";
import { fsk, Config, path as pathk, summary } from "@brandingbrand/code-core";
import {
fsk,
Config,
path as pathk,
summary,
fs,
} from "@brandingbrand/code-core";
import { CodePluginFastlane } from "./types";

const ios = summary.withSummary(
Expand All @@ -21,6 +27,61 @@ plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
eval_gemfile(plugins_path) if File.exist?(plugins_path)
`
);

if (!config.ios.signing) {
throw Error("[CodePluginFastlane]: missing ios fastlane configuration");
}

// Get list of provisioning profiles files
const files = await fs.readdir(
pathk.config.resolve(config.ios.signing.profilesDir)
);

const profilesFiles = files.filter((it) =>
it.match(/(\w+\.mobileprovision)/)
);

// Throw error if there are no available provisioning profiles
if (!profilesFiles.length) {
throw Error(
`[CodePluginFastlane]: cannot find profiles that match *.mobileprovision in ${config.ios.signing.profilesDir}`
);
}

// Reduce list into a string that would be reprentative of a ruby array
const profiles = profilesFiles
.map(
(it) =>
`'${pathk.config.resolve(
config.ios.signing?.profilesDir as string,
it
)}'`
)
.join(",");

await fsk.update(
pathk.project.resolve("ios", "fastlane", "Fastfile"),
/(@profiles\s+=\s+\[).*(\])/,
`$1${profiles}$2`
);

await fsk.update(
pathk.project.resolve("ios", "fastlane", "Fastfile"),
/(certificate_path:\s+').*\.p12(')/,
`$1${pathk.config.resolve(config.ios.signing?.distP12)}$2`
);

await fsk.update(
pathk.project.resolve("ios", "fastlane", "Fastfile"),
/(certificate_path:\s+').*\.cer(')/,
`$1${pathk.config.resolve(config.ios.signing?.distCert)}$2`
);

await fsk.update(
pathk.project.resolve("ios", "fastlane", "Fastfile"),
/(certificate_path:\s+')AppleWWDRCA\.cer(')/,
`$1${pathk.config.resolve(config.ios.signing?.appleCert)}$2`
);
}
},
"plugin-fastlane",
Expand All @@ -47,6 +108,29 @@ eval_gemfile(plugins_path) if File.exist?(plugins_path)
`
);
}

if (!config.android.signing) {
throw Error(
"[CodePluginFastlane]: missing android signing configuration"
);
}

await fs.copyFile(
pathk.config.resolve(config.android.signing.storeFile),
pathk.project.resolve("android", "app", "release.keystore")
);

await fsk.update(
pathk.project.resolve("android", "app", "build.gradle"),
/(signingConfigs\s*{\s*)/m,
`$1release {
storeFile file('release.keystore')
storePassword System.getenv("STORE_PASSWORD")
keyAlias '${config.android.signing.keyAlias}'
keyPassword System.getenv("KEY_PASSWORD")
}
`
);
},
"plugin-fastlane",
"platform::android"
Expand Down
Empty file.
Empty file.
Empty file.
38 changes: 0 additions & 38 deletions packages/plugin-fastlane/test/index--increment.test.ts

This file was deleted.

33 changes: 0 additions & 33 deletions packages/plugin-fastlane/test/index--not-increment.test.ts

This file was deleted.

42 changes: 0 additions & 42 deletions packages/plugin-fastlane/test/index--not-release.test.ts

This file was deleted.

Loading

0 comments on commit dfbe2c9

Please sign in to comment.