Skip to content

Commit

Permalink
GooglePlayReleaseV4 - override release notes (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisRumyantsev authored Jan 31, 2023
1 parent cb884cc commit 4f013a1
Show file tree
Hide file tree
Showing 12 changed files with 584 additions and 67 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,35 @@ $(Specified Directory)

12. **Language Code** *(String, Optional)* - An IETF language tag identifying the language of the release notes as specified in the BCP-47 document. Default value is _en-US_. Only visible if `Update metadata` option is disabled.

13. **Update Metadata** *(Boolean, Optional)* - Allows automating metadata updates to the Google Play store by leveraging the contents of the `Metadata Root Directory`.
13. **Release notes contain language tags** *(Boolean, Optional)* - Allows adding the release notes file containing language tags. Only visible if `Update metadata` option is disabled.

* The `releaseNotesContainLanguageTags` input:

![releaseNotesContainLanguageTags](images/releaseNotesContainLanguageTags.png)

* The `Release Notes` file content example:

```xml
<en-US>
Minor updates, bug fixes, and performance improvements.
</en-US>
<fr-FR>
Mises à jour mineures, corrections de bogues et améliorations des performances.
</fr-FR>
<it-IT>
Aggiornamenti minori, correzioni di bug e miglioramenti delle prestazioni.
</it-IT>
```

* Result if the `releaseNotesContainLanguageTags` input is set to `false` (by default):

![releaseNotesContainLanguageTags is false](images/releaseNotesContainLanguageTags-is-false.png)

* Result if the `releaseNotesContainLanguageTags` input is set to `true` (the `Language Code` input will be ignored):

![releaseNotesContainLanguageTags is true](images/releaseNotesContainLanguageTags-is-true.png)

14. **Update Metadata** *(Boolean, Optional)* - Allows automating metadata updates to the Google Play store by leveraging the contents of the `Metadata Root Directory`.

![Update Metadata](images/update-metadata.png)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"loc.input.help.changeLogFile": "Path to the file specifying the release notes (change log) for the application you are publishing.",
"loc.input.label.languageCode": "Language code",
"loc.input.help.languageCode": "An IETF language tag identifying the language of the release notes as specified in the BCP-47 document. Default value is _en-US_",
"loc.input.label.releaseNotesContainLanguageTags": "Release notes contain language tags",
"loc.input.help.releaseNotesContainLanguageTags": "Select this option if the release notes file contains language tags.",
"loc.input.label.metadataRootPath": "Metadata root directory",
"loc.input.help.metadataRootPath": "The path to the metadata folder with the fastlane metadata structure.",
"loc.input.label.changeUpdatePriority": "Set in-app update priority",
Expand Down
5 changes: 3 additions & 2 deletions Tasks/GooglePlayReleaseV4/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function run(): Promise<void> {

let changelogFile: string = null;
let languageCode: string = null;
let releaseNotesContainLanguageTags: boolean = false;
let metadataRootPath: string = null;

if (shouldAttachMetadata) {
Expand All @@ -56,6 +57,7 @@ async function run(): Promise<void> {
changelogFile = tl.getInput('changelogFile', false);
const defaultLanguageCode = 'en-US';
languageCode = tl.getInput('languageCode', false) || defaultLanguageCode;
releaseNotesContainLanguageTags = tl.getBoolInput('releaseNotesContainLanguageTags', false);
}

// Advanced inputs
Expand Down Expand Up @@ -193,8 +195,7 @@ async function run(): Promise<void> {
requireTrackUpdate = action !== 'OnlyStoreListing';
} else if (changelogFile) {
tl.debug(`Uploading the common change log ${changelogFile} to all versions`);
const commonNotes = await metadataHelper.getCommonReleaseNotes(languageCode, changelogFile);
releaseNotes = commonNotes && [commonNotes];
releaseNotes = await metadataHelper.getCommonReleaseNotes(languageCode, changelogFile, releaseNotesContainLanguageTags);
requireTrackUpdate = true;
}

Expand Down
53 changes: 35 additions & 18 deletions Tasks/GooglePlayReleaseV4/modules/metadataHelper.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
import * as fs from 'fs';
import * as path from 'path';
import { JSDOM } from 'jsdom';
import * as tl from 'azure-pipelines-task-lib/task';

import { androidpublisher_v3 as pub3 } from 'googleapis';

/**
* Uploads change log files if specified for all the version codes in the update
* @param changelogFile
* @param versionCodes
* @returns nothing
* @param {string} languageCode
* @param {string} changelogFile
* @param {boolean} releaseNotesContainLanguageTags
* @returns {pub3.Schema$LocalizedText[]} `[{ language: 'en-US|fr-FR|it-IT|...', text: 'Localized_Release_Notes' }, ...]`
*/
export async function getCommonReleaseNotes(languageCode: string, changelogFile: string): Promise<pub3.Schema$LocalizedText | null> {
export async function getCommonReleaseNotes(languageCode: string, changelogFile: string, releaseNotesContainLanguageTags: boolean): Promise<pub3.Schema$LocalizedText[]> {
const stats: tl.FsStats = tl.stats(changelogFile);
const releaseNotes: pub3.Schema$LocalizedText[] = [];

let releaseNotes: pub3.Schema$LocalizedText = null;
if (stats && stats.isFile()) {
console.log(tl.loc('AppendChangelog', changelogFile));
releaseNotes = {
language: languageCode,
text: getChangelog(changelogFile)
};
const changelog: string = getChangelog(changelogFile);

if (changelog) {
if (releaseNotesContainLanguageTags) {
for (const node of new JSDOM(changelog).window.document.body.childNodes.values()) {
const language = node['tagName'];
const text = node.textContent.trim();

if (language && text) {
releaseNotes.push({ language, text });
}
}
} else {
releaseNotes.push({
language: languageCode,
text: changelog
});
}
}
} else {
tl.debug(`The change log path ${changelogFile} either does not exist or points to a directory. Ignoring...`);
}

return releaseNotes;
}

Expand All @@ -36,7 +53,7 @@ export async function getCommonReleaseNotes(languageCode: string, changelogFile:
function getChangelog(changelogFile: string): string {
tl.debug(`Reading change log from ${changelogFile}`);
try {
return fs.readFileSync(changelogFile).toString();
return fs.readFileSync(changelogFile).toString().trim();
} catch (e) {
tl.debug(`Change log reading from ${changelogFile} failed`);
tl.debug(e);
Expand Down Expand Up @@ -211,14 +228,14 @@ async function uploadMetadataWithLanguageCode(edits: pub3.Resource$Edits, versio
async function addLanguageListing(edits: pub3.Resource$Edits, languageCode: string, directory: string) {
const listingResource: pub3.Schema$Listing = createListingResource(languageCode, directory);

const isPatch:boolean = (!listingResource.fullDescription) ||
(!listingResource.shortDescription) ||
(!listingResource.title);
const isPatch: boolean = (!listingResource.fullDescription) ||
(!listingResource.shortDescription) ||
(!listingResource.title);

const isEmpty:boolean = (!listingResource.fullDescription) &&
(!listingResource.shortDescription) &&
(!listingResource.video) &&
(!listingResource.title);
const isEmpty: boolean = (!listingResource.fullDescription) &&
(!listingResource.shortDescription) &&
(!listingResource.video) &&
(!listingResource.title);

const listingRequestParameters: pub3.Params$Resource$Edits$Listings$Patch = {
language: languageCode,
Expand Down Expand Up @@ -371,7 +388,7 @@ function getImageList(directory: string): { [key: string]: string[] } {
const acceptedExtensions: string[] = ['.png', '.jpg', '.jpeg'];

const imageDirectory: string = path.join(directory, 'images');
const imageList: { [key: string]: string[] } = {};
const imageList: { [key: string]: string[] } = {};

for (const imageType of imageTypes) {
let shouldAttemptUpload: boolean = false;
Expand Down
Loading

0 comments on commit 4f013a1

Please sign in to comment.