Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/enable teams message failed builds #6

Merged
merged 10 commits into from
Jan 12, 2024
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ After preparation of your local environment the script will execute the jscm com

It will execute both possible command:

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

→ This will result in 4 messages being sent to the specified teams channel
→ This will result in 4(2 failed/2 successful) messages being sent to the specified teams channel as well as 2 exceptions exceptions.
erbenjak marked this conversation as resolved.
Show resolved Hide resolved

### Calling the test script

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": "1.0.0",
"version": "1.0.1",
"description": "Codemagic extended tooling",
"homepage": "https://github.com/js-soft/codemagic-tools#readme",
"bugs": {
Expand Down
46 changes: 29 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import fs from "fs";
import os from "os";
import yargs from "yargs";
import { CmArtifactLink } from "./CmArtifactLink";

import { TeamsCommandLineOptions } from "./commands/TeamsCommandLineOptions";
import { runTeamsDevelopMessagingCommand } from "./commands/TeamsDevelopMessaging";
import { runTeamsProductionMessagingCommand } from "./commands/TeamsProductionMessaging";
Expand All @@ -17,24 +17,27 @@ async function run() {
const buildNumber = parseInt(process.env.BUILD_NUMBER!);
const buildUrl = `https://codemagic.io/app/${projectId}/build/${buildId}`;

if (process.env.CM_ARTIFACT_LINKS === undefined) {
console.error(
"To ensure correct execution the environment variable CM_ARTIFACT_LINKS must be present in the system"
);
process.exit(1);
}

let artifactUrl: string;
let artifactType: string;

const cmArtifactLinks: CmArtifactLink[] = JSON.parse(process.env.CM_ARTIFACT_LINKS!).filter(
(element: any) => element.type === "apk" || element.type === "ipa"
);
if (cmArtifactLinks.filter((element: any) => element.type === "apk" || element.type === "ipa").length !== 0) {
const pickedElement = cmArtifactLinks.filter((element: any) => element.type === "apk" || element.type === "ipa")[0];
artifactUrl = pickedElement.url;
artifactType = pickedElement.type;
let failedState = false;

if (process.env.CM_ARTIFACT_LINKS === undefined) {
failedState = true;
} else {
const cmArtifactLinks = JSON.parse(process.env.CM_ARTIFACT_LINKS);
if (cmArtifactLinks.filter((element: any) => element.type === "apk" || element.type === "ipa").length === 0) {
failedState = true;
} else {
const pickedElement = cmArtifactLinks.filter(
(element: any) => element.type === "apk" || element.type === "ipa"
)[0];
artifactUrl = pickedElement.url;
artifactType = pickedElement.type;
}
}

if (failedState) {
// should link to the workflow-log can be determined from buildId and projectId
artifactUrl = buildUrl;
artifactType = "logs";
Expand Down Expand Up @@ -80,14 +83,23 @@ async function run() {
() => {
return;
},
async (args) =>
async (args) => {
if (failedState) {
console.log("Cannot send production message for a build, which did not produce an artifact.");
process.exit(1);
erbenjak marked this conversation as resolved.
Show resolved Hide resolved
}
if (!buildWasSuccessful) {
console.log("Cannot send production message for failed build.");
process.exit(1);
erbenjak marked this conversation as resolved.
Show resolved Hide resolved
}
await runTeamsProductionMessagingCommand({
projectName: args.projectName,
platform: args.platform,
buildUrl,
buildNumber,
webhook
})
});
}
)
.demandCommand(1, "Must provide a valid command from the ones listed above.")
.scriptName("jscm")
Expand Down
13 changes: 10 additions & 3 deletions test/test_teams_messaging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ echo "Enter the BUILD_NUMBER :"
read BUILD_NUMBER_VALUE
export BUILD_NUMBER=$BUILD_NUMBER_VALUE

export CM_ARTIFACT_LINKS=$(cat artifactLinks.json)
# we want to test the execution without any artifacts present
echo "Testing without the artifactLinks environment variable"
jscm teams-develop --platform "ios" --projectName "Mein Codemagic Test Projekt"
jscm teams-production --platform "ios" --projectName "Mein Codemagic Test Projekt"
echo "Finished teams messaging tests without artifactLinks"

echo "webhook url: $teams_webhook_url"
echo "--------------------------------------------"
export CM_ARTIFACT_LINKS=$(cat artifactLinks.json)
echo "created the artifactLinks environment variable"
echo "--------------------------------------------"

echo "Starting teams messaging tests"
echo "Testing with the artifactLinks environment variable"
jscm teams-develop --platform "ios" --projectName "Mein Codemagic Test Projekt"
jscm teams-production --platform "ios" --projectName "Mein Codemagic Test Projekt"
touch ~/SUCCESS
Expand Down
Loading