diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index ef78517..7ca31f5 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -24,9 +24,6 @@ on: prefix: description: 'The storage bucket path to back up Allure results and history files' required: false - slack_channel: - description: 'Slack channel ID' - required: false jobs: test-docker: @@ -89,13 +86,15 @@ jobs: - name: Allure Deployer Action uses: ./apps/action env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} SLACK_TOKEN: ${{secrets.SLACK_TOKEN}} - GOOGLE_CREDENTIALS_JSON: ${{ secrets.GCP_CREDENTIALS}} + GOOGLE_CREDENTIALS_JSON: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS}} with: allure_results_path: 'assets/allure-results' storage_bucket: ${{github.event.inputs.storage-bucket}} report_name: ${{ github.event.inputs.report-name }} - slack_channel: ${{github.event.inputs.slack_channel}} + slack_channel: ${{secrets.SLACK_CHANNEL}} show_retries: ${{github.event.inputs.show-retries}} show_history: ${{github.event.inputs.show-history}} - prefix: ${{github.event.inputs.prefix}} \ No newline at end of file + prefix: ${{github.event.inputs.prefix}} + update_pr: 'comment' \ No newline at end of file diff --git a/apps/cli/src/commands/deploy.command.ts b/apps/cli/src/commands/deploy.command.ts index a93d667..09e8bb4 100644 --- a/apps/cli/src/commands/deploy.command.ts +++ b/apps/cli/src/commands/deploy.command.ts @@ -6,13 +6,13 @@ import fs from "fs/promises"; import path from "node:path"; import {KEY_BUCKET, KEY_PROJECT_ID, KEY_SLACK_CHANNEL, KEY_SLACK_TOKEN} from "../utilities/constants.js"; import chalk from "chalk"; -import {ArgsInterface, GitHubPRUpdateType} from "../interfaces/args.interface.js"; +import {ArgsInterface} from "../interfaces/args.interface.js"; const ERROR_MESSAGES = { EMPTY_RESULTS: "Error: The specified results directory is empty.", NO_RESULTS_DIR: "Error: No Allure result files in the specified directory.", MISSING_CREDENTIALS: "Error: Firebase/GCP credentials must be set using 'gcp-json:set' or provided via '--gcp-json'.", - MISSING_BUCKET: "Error: A Firebase/GCP bucket must be set using 'bucket:set' or provided via '--bucket'.", + MISSING_BUCKET: "Storage bucket not provided. History and Retries will not be available in report.", INVALID_SLACK_CRED: `Invalid Slack credential. ${chalk.blue('slack_channel')} and ${chalk.blue('slack_token')} must be provided together`, NO_JAVA: 'Error: JAVA_HOME not found. Allure 2.32 requires JAVA installed' }; @@ -48,7 +48,7 @@ async function getFirebaseCredentials(gcpJson: string | undefined): Promise Promise): Command { return defaultProgram .command("deploy") @@ -82,15 +90,7 @@ export function addDeployCommand(defaultProgram: Command, onCommand: (args: Args .addOption(new Option("-st, --slack-token ","Slack token")) .addOption(new Option("-p, --prefix ", "The storage bucket path to back up Allure results and history files")) .addOption(new Option("--update-pr ", "Update pull request with report url and info") - .default(GitHubPRUpdateType.summary.toString(), 'summary/comment').hideHelp() - .argParser((value)=> { - if(Object.values(GitHubPRUpdateType).includes(value)){ - return value - } - // Fallback to default if value is invalid - console.warn(`Invalid value "${value}" for --update-pr. Falling back to "summary".`); - return 'summary' - })) + .default('comment', 'summary/comment').hideHelp().argParser(validateUpdatePR)) .action(async (resultPath, reportName, options) => { try { if(!isJavaInstalled()){ @@ -125,7 +125,7 @@ export function addDeployCommand(defaultProgram: Command, onCommand: (args: Args slack_channel: options.slackChannel || db.get(KEY_SLACK_CHANNEL, undefined), slack_token: options.slackToken || db.get(KEY_SLACK_TOKEN, undefined), buildUrl: getGitHubBuildUrl(), - updatePr: options.updatePr as GitHubPRUpdateType + updatePr: options.updatePr }; await onCommand(cliArgs); diff --git a/apps/cli/src/features/hosting/firebase-host.ts b/apps/cli/src/features/hosting/firebase-host.ts index 6afd1c4..7c97193 100644 --- a/apps/cli/src/features/hosting/firebase-host.ts +++ b/apps/cli/src/features/hosting/firebase-host.ts @@ -7,7 +7,7 @@ import {ArgsInterface} from "../../interfaces/args.interface.js"; import path from "node:path"; import {generate} from "random-words"; import {StringBuilder} from "../../utilities/string-builder.js"; -import {FirebaseService} from "../../services/firebase.service.js"; +import {FirebaseInterface} from "../../interfaces/firebase.interface.js"; // Max allowed Firebase sites to prevent exceeding quota // https://firebase.google.com/docs/hosting/multisites @@ -20,13 +20,13 @@ export class FirebaseHost implements HostingProvider { private hostedSiteUrl: string | undefined; private configPath?: string; private readonly newSiteId: string; - private readonly service: FirebaseService; + private readonly service: FirebaseInterface; // Initialize class properties from input arguments - constructor(readonly args: ArgsInterface, service?: FirebaseService) { + constructor(readonly args: ArgsInterface, service: FirebaseInterface) { this.reportDir = this.args.REPORTS_DIR; this.newSiteId = this.getSiteId(); - this.service = service ?? new FirebaseService(this.args.firebaseProjectId); + this.service = service } // Generates a unique site ID using random words and timestamps diff --git a/apps/cli/src/features/messaging/github-notifier.ts b/apps/cli/src/features/messaging/github-notifier.ts index b03191c..dad8afb 100644 --- a/apps/cli/src/features/messaging/github-notifier.ts +++ b/apps/cli/src/features/messaging/github-notifier.ts @@ -1,6 +1,6 @@ import {Notifier} from "../../interfaces/notifier.interface.js"; import {NotificationData} from "../../models/notification.model.js"; -import {ArgsInterface, GitHubPRUpdateType} from "../../interfaces/args.interface.js"; +import {ArgsInterface} from "../../interfaces/args.interface.js"; import {GithubInterface} from "../../interfaces/github.interface.js"; export class GitHubNotifier implements Notifier { @@ -32,15 +32,12 @@ export class GitHubNotifier implements Notifier { const promises: Promise[] = []; promises.push(this.client.updateOutput(`report_url=${data.reportUrl}`)) - if(this.args.updatePr === GitHubPRUpdateType.comment){ - const githubToken = process.env.GITHUB_TOKEN; - if (githubToken) { - promises.push(this.client.updatePr({message: markdown, token: githubToken})) - } + const githubToken = process.env.GITHUB_TOKEN; + if(githubToken && this.args.updatePr === 'comment'){ + promises.push(this.client.updatePr({message: markdown, token: githubToken})) } else { promises.push(this.client.updateSummary(markdown.trim())) } - await Promise.all(promises) } } \ No newline at end of file diff --git a/apps/cli/src/interfaces/args.interface.ts b/apps/cli/src/interfaces/args.interface.ts index 9a69aba..4fce904 100644 --- a/apps/cli/src/interfaces/args.interface.ts +++ b/apps/cli/src/interfaces/args.interface.ts @@ -18,9 +18,5 @@ export interface ArgsInterface { slack_channel?: string slack_token?: string buildUrl?: string; - updatePr?: GitHubPRUpdateType; -} -export enum GitHubPRUpdateType { - comment, - summary + updatePr?: string; } diff --git a/apps/cli/src/interfaces/firebase.interface.ts b/apps/cli/src/interfaces/firebase.interface.ts new file mode 100644 index 0000000..f1c5bd4 --- /dev/null +++ b/apps/cli/src/interfaces/firebase.interface.ts @@ -0,0 +1,6 @@ +export interface FirebaseInterface { + deleteSite({siteId, configPath}:{siteId: string, configPath: string}): Promise + deployHosting(configPath: string): Promise + createSite(siteId: string): Promise + listSites(): Promise +} \ No newline at end of file diff --git a/apps/cli/src/main.ts b/apps/cli/src/main.ts index f197e50..8db3712 100644 --- a/apps/cli/src/main.ts +++ b/apps/cli/src/main.ts @@ -20,6 +20,7 @@ import {Storage as GCPStorage} from '@google-cloud/storage' import {readJsonFile} from "./utilities/file-util.js"; import {ResultsStatus} from "./interfaces/counter.interface.js"; import {GitHubService} from "./services/github.service.js"; +import {FirebaseService} from "./services/firebase.service.js"; // Entry point for the application export function main() { @@ -49,7 +50,8 @@ function setupCommands(program: Command) { // Executes the deployment process async function runDeploy(args: ArgsInterface) { const allure = new Allure({args}); - const firebaseHost = new FirebaseHost(args); + const firebaseService = new FirebaseService(args.firebaseProjectId); + const firebaseHost = new FirebaseHost(args, firebaseService); try { const cloudStorage = await initializeCloudStorage(args); // Initialize storage bucket const [reportUrl, resultsStatus] = await setupStaging(firebaseHost, cloudStorage, allure, args); diff --git a/apps/cli/src/services/firebase.service.ts b/apps/cli/src/services/firebase.service.ts index 4764b70..b9090c5 100644 --- a/apps/cli/src/services/firebase.service.ts +++ b/apps/cli/src/services/firebase.service.ts @@ -1,7 +1,8 @@ // @ts-ignore import firebase from 'firebase-tools' +import {FirebaseInterface} from "../interfaces/firebase.interface.js"; -export class FirebaseService { +export class FirebaseService implements FirebaseInterface{ constructor(private readonly projectId: string) {} /** diff --git a/apps/cli/src/services/github.service.ts b/apps/cli/src/services/github.service.ts index 1b43d8e..02287c8 100644 --- a/apps/cli/src/services/github.service.ts +++ b/apps/cli/src/services/github.service.ts @@ -1,6 +1,7 @@ import {GithubInterface} from "../interfaces/github.interface.js"; import fs from "fs/promises"; import github from "@actions/github"; +import process from "node:process"; export class GitHubService implements GithubInterface { outputPath: string; @@ -20,8 +21,9 @@ export class GitHubService implements GithubInterface { } async updatePr({message, token}: { message: string, token: string }): Promise { - const {owner, repo} = github.context.repo + try { + const [owner, repo] = process.env.GITHUB_REPOSITORY!.split('/') const pr = github.context.payload.pull_request! const octokit = github.getOctokit(token) // Update the PR body @@ -34,8 +36,6 @@ export class GitHubService implements GithubInterface { console.log(`Pull Request #${pr.number} updated successfully!`); } catch (e) { console.warn('Failed to update PR:', e); - console.log(`Repository Owner: ${owner}`); - console.log(`Repository Name: ${repo}`); } }