Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function up(knex: Knex): Promise<void> {
table.text('telemetry'); // JSON-serialized Telemetry object
table.string('k8s_job_name');
table.string('callback_token');
table.string('commit_id').nullable();
table
.uuid('project_id')
.notNullable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const collectArtifactsRequestSchema = z.object({
jobId: z.string().uuid('Job ID must be a valid UUID'),
artifacts: z.array(artifactSchema).optional(),
telemetry: telemetrySchema.optional(),
commitId: z.string().optional(),
});

export interface CollectArtifactsRequestBody {
Expand All @@ -69,6 +70,7 @@ export interface CollectArtifactsRequestBody {
jobId: string;
artifacts?: Artifact[];
telemetry?: Telemetry;
commitId?: string;
}

export function registerCollectArtifactsRoutes(
Expand Down Expand Up @@ -164,6 +166,7 @@ export function registerCollectArtifactsRoutes(
log: logs,
artifacts: validatedRequest.artifacts || [],
telemetry: validatedRequest.telemetry || null,
commitId: validatedRequest.commitId,
});

logger.info(
Expand Down
6 changes: 6 additions & 0 deletions workspaces/x2a/plugins/x2a-backend/src/schema/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ paths:
$ref: '#/components/schemas/Artifact'
telemetry:
$ref: '#/components/schemas/Telemetry'
commitId:
type: string
description: Git commit SHA from the job's push to target repo
required:
- status
- jobId
Expand Down Expand Up @@ -665,6 +668,9 @@ components:
$ref: '#/components/schemas/Artifact'
telemetry:
$ref: '#/components/schemas/Telemetry'
commitId:
type: string
description: Git commit SHA produced by this job

ArtifactType:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ export interface Job {
*/
artifacts?: Array<Artifact>;
telemetry?: Telemetry;
/**
* Git commit SHA produced by this job
*/
commitId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface ProjectsProjectIdCollectArtifactsPostRequest {
*/
artifacts?: Array<Artifact>;
telemetry?: Telemetry;
/**
* Git commit SHA from the job's push to target repo
*/
commitId?: string;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ export const spec = {
},
"telemetry": {
"$ref": "#/components/schemas/Telemetry"
},
"commitId": {
"type": "string",
"description": "Git commit SHA from the job's push to target repo"
}
},
"required": [
Expand Down Expand Up @@ -939,6 +943,10 @@ export const spec = {
},
"telemetry": {
"$ref": "#/components/schemas/Telemetry"
},
"commitId": {
"type": "string",
"description": "Git commit SHA produced by this job"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export class X2ADatabaseService {
k8sJobName?: string | null;
artifacts?: Artifact[];
telemetry?: Telemetry | null;
commitId?: string;
}): Promise<Job | undefined> {
return this.#jobOps.updateJob(update);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export class JobOperations {
'k8s_job_name',
'callback_token',
'telemetry',
'commit_id',
)
.first();
if (!row) {
Expand Down Expand Up @@ -269,6 +270,7 @@ export class JobOperations {
'k8s_job_name',
'callback_token',
'telemetry',
'commit_id',
)
.orderBy('started_at', 'desc')
.modify(queryBuilder => {
Expand All @@ -295,6 +297,7 @@ export class JobOperations {
k8sJobName,
artifacts,
telemetry,
commitId,
}: {
id: string;
log?: string | null;
Expand All @@ -304,6 +307,7 @@ export class JobOperations {
k8sJobName?: string | null;
artifacts?: Artifact[];
telemetry?: Telemetry | null;
commitId?: string;
}): Promise<Job | undefined> {
this.#logger.info(`updateJob called for id: ${id}`);

Expand Down Expand Up @@ -332,6 +336,9 @@ export class JobOperations {
if (telemetry !== undefined) {
updateData.telemetry = telemetry ? JSON.stringify(telemetry) : null;
}
if (commitId !== undefined) {
updateData.commit_id = commitId;
}

if (Object.keys(updateData).length > 0) {
await this.#dbClient('jobs').where('id', id).update(updateData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function mapRowToJob(
errorDetails: (row.error_details as string | undefined) ?? undefined,
k8sJobName: (row.k8s_job_name as string) ?? undefined,
callbackToken: (row.callback_token as string | undefined) ?? undefined,
commitId: (row.commit_id as string | undefined) ?? undefined,
telemetry: parseTelemetry(
(row.telemetry as string | undefined) ?? undefined,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ERROR_MESSAGE=""
ARTIFACTS=()
PUSH_FAILED=""
TERMINATED=false
COMMIT_ID=""

# Report job result back to the backend.
# TODO: Incorporate CALLBACK_TOKEN for request signing (HMAC-SHA256).
Expand All @@ -34,6 +35,10 @@ report_result() {
cmd+=(--error-message "${message}")
fi

if [ -n "${COMMIT_ID:-}" ]; then
cmd+=(--commit-id "${COMMIT_ID}")
fi

echo "Reporting result: status=${status}, phase=${PHASE}"
cd /app && "${cmd[@]}" || echo "WARNING: Failed to report result to backend"
}
Expand Down Expand Up @@ -90,6 +95,8 @@ Co-Authored-By: ${GIT_AUTHOR_NAME} <${GIT_AUTHOR_EMAIL}>
if ! git push origin "${TARGET_REPO_BRANCH}"; then
PUSH_FAILED="Failed to push to ${TARGET_REPO_URL} branch ${TARGET_REPO_BRANCH}"
echo "ERROR: ${PUSH_FAILED}"
else
COMMIT_ID=$(git rev-parse HEAD 2>/dev/null || echo "")
fi
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ export interface Job {
*/
artifacts?: Array<Artifact>;
telemetry?: Telemetry;
/**
* Git commit SHA produced by this job
*/
commitId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface ProjectsProjectIdCollectArtifactsPostRequest {
*/
artifacts?: Array<Artifact>;
telemetry?: Telemetry;
/**
* Git commit SHA from the job's push to target repo
*/
commitId?: string;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions workspaces/x2a/plugins/x2a-common/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface GitRepoAuth {
// @public (undocumented)
export interface Job {
artifacts?: Array<Artifact>;
commitId?: string;
errorDetails?: string;
finishedAt?: Date;
id: string;
Expand Down Expand Up @@ -210,6 +211,7 @@ export interface ProjectsProjectIdCollectArtifactsPost200Response {
// @public (undocumented)
export interface ProjectsProjectIdCollectArtifactsPostRequest {
artifacts?: Array<Artifact>;
commitId?: string;
errorDetails?: string;
jobId: string;
status: ProjectsProjectIdCollectArtifactsPostRequestStatusEnum;
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ readonly "modulePage.phases.publishInstructions": string;
readonly "modulePage.phases.runPublish": string;
readonly "modulePage.phases.republishInstructions": string;
readonly "modulePage.phases.rerunPublish": string;
readonly "modulePage.phases.commitId": string;
readonly "modulePage.phases.viewLog": string;
readonly "modulePage.phases.hideLog": string;
readonly "project.id": string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ const PhaseDetails = ({
value={phase?.id || empty}
/>
</Grid>
<Grid item xs={3}>
<ItemField
label={t('modulePage.phases.commitId')}
value={phase?.commitId || empty}
/>
</Grid>

{phase && (
<Grid item xs={12}>
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/src/translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const x2aPluginTranslationDe = createTranslationMessages({
'Das Modul wurde bereits veröffentlicht. Lösen Sie die Veröffentlichung erneut aus, um das Ziel-Repository zu aktualisieren.',
'modulePage.phases.rerunPublish':
'Im Ziel-Repository erneut veröffentlichen',
'modulePage.phases.commitId': 'Letzte Commit-ID',
'modulePage.phases.viewLog': 'Log anzeigen',
'modulePage.phases.hideLog': 'Log ausblenden',
},
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/src/translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const x2aPluginTranslationEs = createTranslationMessages({
'El módulo ya ha sido publicado. Vuelva a ejecutar la publicación para actualizar el repositorio de destino.',
'modulePage.phases.rerunPublish':
'Volver a publicar en el repositorio de destino',
'modulePage.phases.commitId': 'Ultimo ID de commit',
'modulePage.phases.viewLog': 'Ver registro',
'modulePage.phases.hideLog': 'Ocultar registro',
},
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/src/translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const x2aPluginTranslationFr = createTranslationMessages({
'modulePage.phases.republishInstructions':
'Le module a déjà été publié. Relancez la publication pour mettre à jour le dépôt cible.',
'modulePage.phases.rerunPublish': 'Republier dans le dépôt cible',
'modulePage.phases.commitId': 'Dernier ID de commit',
'modulePage.phases.viewLog': 'Voir le journal',
'modulePage.phases.hideLog': 'Masquer le journal',
},
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/src/translations/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const x2aPluginTranslationIt = createTranslationMessages({
'Il modulo è già stato pubblicato. Riavvia la pubblicazione per aggiornare il repository di destinazione.',
'modulePage.phases.rerunPublish':
'Ripubblica nel repository di destinazione',
'modulePage.phases.commitId': 'Ultimo ID commit',
'modulePage.phases.viewLog': 'Visualizza log',
'modulePage.phases.hideLog': 'Nascondi log',
},
Expand Down
1 change: 1 addition & 0 deletions workspaces/x2a/plugins/x2a/src/translations/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const x2aPluginMessages = {
republishInstructions:
'The module has already been published. Retrigger the publish to update the target repository.',
rerunPublish: 'Republish to target repository',
commitId: 'Last Commit ID',
viewLog: 'View Log',
hideLog: 'Hide Log',
},
Expand Down