-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow Google Services task to read an existing file or create one
- Loading branch information
Showing
5 changed files
with
148 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Google Firebase is an incredibly popular solution for app analytics and cross platform push notifications. Unfortunately we see a lot of developers following poor programming practices including the `google-services.json` and `GoogleService-Info.plist` in source control. The Mobile.BuildTools is all about empowering you to follow best practices while developing your mobile apps. | ||
|
||
To start be sure to add these files to your `.gitignore` that way the file isn't accidentally checked into source control while you use it for local development. The Mobile.BuildTools is able to bring these resources in at build time using your favorite CI Build service. To get started you'll want to come up with a variable name and set this in your `buildtools.json` like the following: | ||
|
||
```json | ||
{ | ||
"google": { | ||
"servicesJson": "GoogleServicesJson", | ||
"infoPlist": "GoogleServicesInfoPlist" | ||
} | ||
} | ||
``` | ||
|
||
If the variable exists locally or on your CI Server, the Mobile.BuildTools will automatically look it up and determine if it is a file path. If it is it will add the appropriate include for iOS/Android. Otherwise it will take the contents of the variable and add the file to the Intermediate Output Directory (the obj folder) during the build, and it will again add the appropriate platform include. | ||
|
||
!!! note | ||
Due to some build agents, such as all Windows agents on Azure DevOps, performing a ToUpper on all environment variable names, the Mobile.BuildTools will do a Case insensitive lookup to match the variable name. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
tests/Mobile.BuildTools.Tests/Fixtures/Tasks/GoogleTaskFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Mobile.BuildTools.Tasks; | ||
using Xunit; | ||
|
||
namespace Mobile.BuildTools.Tests.Fixtures.Tasks | ||
{ | ||
public class GoogleTaskFixture | ||
{ | ||
private readonly string IntermediateOutputDirectory = new FileInfo(Path.Combine("Generated", "GoogleTask")).FullName; | ||
|
||
[Fact] | ||
public void ReturnsIntermediateFileFromVariable() | ||
{ | ||
var contents = "SampleGoogleServices"; | ||
var environmentName = nameof(ReturnsIntermediateFileFromVariable); | ||
Environment.SetEnvironmentVariable(environmentName, contents, EnvironmentVariableTarget.Process); | ||
|
||
var path = GoogleTask.GetResourcePath(environmentName, IntermediateOutputDirectory, "google-services.json"); | ||
|
||
var expectedPath = Path.Combine(IntermediateOutputDirectory, "google-services", "google-services.json"); | ||
|
||
Assert.Equal(expectedPath, path); | ||
|
||
Assert.Equal(contents, File.ReadAllText(path)); | ||
} | ||
|
||
[Fact] | ||
public void ReturnsSpecifiedFileFromRelativePath() | ||
{ | ||
var contents = "SampleGoogleServices"; | ||
var directory = Path.Combine("Generated", "tests", nameof(ReturnsSpecifiedFileFromRelativePath)); | ||
Directory.CreateDirectory(directory); | ||
var expectedPath = Path.Combine(directory, "google-test.json"); | ||
File.WriteAllText(expectedPath, contents); | ||
var environmentName = nameof(ReturnsSpecifiedFileFromRelativePath); | ||
Environment.SetEnvironmentVariable(environmentName, expectedPath, EnvironmentVariableTarget.Process); | ||
|
||
var path = GoogleTask.GetResourcePath(environmentName, IntermediateOutputDirectory, "google-services.json"); | ||
|
||
Assert.Equal(new FileInfo(expectedPath).FullName, path); | ||
} | ||
|
||
[Fact] | ||
public void ReturnsSpecifiedFileFromAbsolutePath() | ||
{ | ||
var contents = "SampleGoogleServices"; | ||
var directory = Path.Combine("Generated", "tests", nameof(ReturnsSpecifiedFileFromAbsolutePath)); | ||
Directory.CreateDirectory(directory); | ||
var expectedPath = new FileInfo(Path.Combine(directory, "google-test.json")).FullName; | ||
File.WriteAllText(expectedPath, contents); | ||
var environmentName = nameof(ReturnsSpecifiedFileFromAbsolutePath); | ||
Environment.SetEnvironmentVariable(environmentName, expectedPath, EnvironmentVariableTarget.Process); | ||
|
||
var path = GoogleTask.GetResourcePath(environmentName, IntermediateOutputDirectory, "google-services.json"); | ||
|
||
Assert.Equal(expectedPath, path); | ||
} | ||
} | ||
} |