Skip to content

Commit

Permalink
Feature/publish-command-teams
Browse files Browse the repository at this point in the history
* chore: version bump

* feature: create teams publish command

* feature: initial teams publish command

* feature: extend teams-build command

* refactor: minor reordering

* refactor: improve parameter names

* refactor: change build-command text slightly

to better differentiate between the two types of messages

* feature: refine teams-publish command

* refactor: format project

* refactor: improve output message

* refactor: reformat project

* chore: complete version bump-up

* feature: remove artifact link from publish message

* refactor: rename jscm sub-commands

* refactor: rename to match command-names

* refactor: reformat files

* feature: improve message quality

* wip

* chore: add test artifact-links

* feature: adapt command to use environment variables

* chore: move isUrlValid to utility

* chore: simplify everything

* refactor: use semis

* refactor: use functions instead of classes

* test: add tests for teams messaging

* chore: formatting

* chore: formatting

* refactor: use correct artifact links file in testing

* feature: improve artifact type check

---------

Co-authored-by: Julian König <[email protected]>
  • Loading branch information
erbenjak and jkoenig134 authored Jan 3, 2024
1 parent 74682c5 commit 884fd37
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"printWidth": 120,
"tabWidth": 2,
"trailingComma": "none",
"semi": false
"semi": true
}
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,48 @@ npm install @js-soft/codemagic-tools

## Usage

### Teams Messaging

#### Develop Messages

```bash
jscm teams-develop --platform <platform> --projectName <projectName>
```

This command will inform about a new development build and additionally provide a link to the build. In case of a failed build it will also provide a link to the build log.

### Production Messages

```bash
jscm teams-publish --platform <platform> --projectName <projectName>
```

This command will inform about an app version, that was released in a store. It additionally provides a link to the build logs.

## Testing

For testing a JSON like created in Codemagic is provided. Additionally a bash-script, which
can be used to test the command is provided. Upon execution the
test script will ask you to specify the following variables:

- webhook - webhook url you want to send to / or just some valid https-address
- BuildId - a string
- ProjectId - a string
- buildNumber - a number

After preparation of your local environment the script will execute the jscm command.

It will execute both possible command:

- teams-develop (in failed/successful state)
- teams-production (in failed/successful state)

&rarr; This will result in 4 messages being sent to the specified teams channel

### Calling the test script

```bash
jscm --help
./test/test_teams_messaging.sh
```

## License
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@js-soft/codemagic-tools",
"version": "0.0.2",
"version": "0.0.3",
"description": "Codemagic extended tooling",
"homepage": "https://github.com/js-soft/codemagic-tools#readme",
"bugs": {
Expand Down
8 changes: 8 additions & 0 deletions src/CmArtifactLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface CmArtifactLink {
name: string;
type: string;
url: string;
md5: string;
versionName: string;
bundleId: string;
}
4 changes: 4 additions & 0 deletions src/commands/TeamsCommandLineOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface TeamsCommandLineOptions {
platform: string;
projectName: string;
}
57 changes: 57 additions & 0 deletions src/commands/TeamsDevelopMessaging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import axios from "axios";
import { isUrlValid } from "./isUrlValid";

export interface TeamsDevelopMessagingOptions {
projectName: string;
webhook: string;
artifactUrl: string;
buildUrl: string;
buildWasSuccessful: boolean;
platform: string;
buildNumber: number;
}

export async function runTeamsDevelopMessagingCommand(options: TeamsDevelopMessagingOptions): Promise<void> {
if (!isUrlValid(options.webhook)) {
console.error("The given webhook is not valid.");
process.exit(1);
}

if (!isUrlValid(options.artifactUrl)) {
console.error("The given artifactUrl is not valid.");
process.exit(1);
}

if (!isUrlValid(options.buildUrl)) {
console.error("The given buildUrl is not valid.");
process.exit(1);
}

const statusIdentifier = options.buildWasSuccessful ? "Successful" : "Failed";
const platformIdentifier = options.platform.toUpperCase();

const messageContents = {
title: `New ${statusIdentifier.toLowerCase()} ${options.platform} debug build for the "${options.projectName}" App`,
summary: `${options.projectName}: ${statusIdentifier} build - ${platformIdentifier}`,
text: options.buildWasSuccessful
? `New Build: #${options.buildNumber} - ${platformIdentifier} <br/> The latest version build successfully and is now available as an artifact.`
: `New Build: #${options.buildNumber} - ${platformIdentifier} <br/> A problem occurred while building the newly released version. The corresponding logs are available.`,
potentialAction: [
{
"@type": "OpenUri",
name: options.buildWasSuccessful ? `Download ${options.platform}-App` : "Download Flutter Logs",
targets: [{ os: "default", uri: options.artifactUrl }]
},
{
"@type": "OpenUri",
name: "Open Build",
targets: [{ os: "default", uri: options.buildUrl }]
}
]
};

await axios.post(options.webhook, messageContents).catch((_) => {
console.log("Could not send message to teams channel.");
process.exit(1);
});
}
81 changes: 0 additions & 81 deletions src/commands/TeamsMessaging.ts

This file was deleted.

43 changes: 43 additions & 0 deletions src/commands/TeamsProductionMessaging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import axios from "axios";
import { isUrlValid } from "./isUrlValid";

export interface TeamsProductionMessagingOptions {
projectName: string;
platform: string;
buildUrl: string;
buildNumber: number;
webhook: string;
}

export async function runTeamsProductionMessagingCommand(options: TeamsProductionMessagingOptions): Promise<void> {
if (!isUrlValid(options.webhook)) {
console.error("The given webhook is not valid.");
process.exit(1);
}

if (!isUrlValid(options.buildUrl)) {
console.error("The given buildUrl is not valid.");
process.exit(1);
}

const platformIdentifier = options.platform.toUpperCase();
const storeName = platformIdentifier === "IOS" ? "App Store" : "Google Play Store";
const messageContents = {
title: `${options.projectName}: New release is now available in the ${storeName} [${platformIdentifier}]`,
summary: `New Release - ${platformIdentifier}`,
text: `New Release: #${options.buildNumber} - ${platformIdentifier} <br/>
The newly released version is now available in the ${storeName}. `,
potentialAction: [
{
"@type": "OpenUri",
name: "Open Build",
targets: [{ os: "default", uri: options.buildUrl }]
}
]
};

await axios.post(options.webhook, messageContents).catch((_) => {
console.log("Could not send message to teams channel.");
process.exit(1);
});
}
9 changes: 9 additions & 0 deletions src/commands/isUrlValid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function isUrlValid(url: string): boolean {
try {
// eslint-disable-next-line no-new
new URL(url);
return true;
} catch (err) {
return false;
}
}
Loading

0 comments on commit 884fd37

Please sign in to comment.