@payfit/nx-core 0.0.0-e2e → 0.1.0-ephemeral-nx-common-packages-migration.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -37
- package/dist/src/executors/docker-build/executor.d.ts +4 -0
- package/dist/src/executors/docker-build/executor.js +42 -0
- package/dist/src/executors/docker-build/executor.js.map +1 -0
- package/dist/src/executors/docker-build/schema.json +29 -0
- package/dist/src/executors/preview-deploy/argocdOverride.d.ts +1 -1
- package/dist/src/executors/preview-deploy/argocdOverride.js +3 -3
- package/dist/src/executors/preview-deploy/argocdOverride.js.map +1 -1
- package/dist/src/executors/preview-deploy/executor.js +120 -103
- package/dist/src/executors/preview-deploy/executor.js.map +1 -1
- package/dist/src/executors/preview-deploy/github.d.ts +4 -0
- package/dist/src/executors/preview-deploy/github.js +10 -0
- package/dist/src/executors/preview-deploy/github.js.map +1 -0
- package/dist/src/executors/preview-deploy/kargoPolicy.d.ts +1 -1
- package/dist/src/executors/preview-deploy/kargoPolicy.js +4 -3
- package/dist/src/executors/preview-deploy/kargoPolicy.js.map +1 -1
- package/dist/src/executors/publisher/README.md +65 -1
- package/dist/src/executors/publisher/docker.d.ts +1 -1
- package/dist/src/executors/publisher/docker.js +24 -36
- package/dist/src/executors/publisher/docker.js.map +1 -1
- package/dist/src/executors/publisher/executor.js +36 -5
- package/dist/src/executors/publisher/executor.js.map +1 -1
- package/dist/src/executors/publisher/frontend.d.ts +3 -0
- package/dist/src/executors/publisher/frontend.js +42 -0
- package/dist/src/executors/publisher/frontend.js.map +1 -0
- package/dist/src/executors/publisher/helm.js +13 -22
- package/dist/src/executors/publisher/helm.js.map +1 -1
- package/dist/src/executors/publisher/lambda.d.ts +3 -1
- package/dist/src/executors/publisher/lambda.js +36 -40
- package/dist/src/executors/publisher/lambda.js.map +1 -1
- package/dist/src/executors/publisher/schema.d.ts +23 -0
- package/dist/src/executors/publisher/schema.js +3 -0
- package/dist/src/executors/publisher/schema.js.map +1 -0
- package/dist/src/executors/publisher/schema.json +29 -5
- package/dist/src/executors/release/README.md +1 -1
- package/dist/src/executors/release/executor.js +25 -32
- package/dist/src/executors/release/executor.js.map +1 -1
- package/dist/src/generators/init/README.md +2 -0
- package/dist/src/generators/init/docker/Dockerfile.template +44 -0
- package/dist/src/generators/init/globalFiles/_github/workflows/ide-nx-migrate.yml.template +17 -0
- package/dist/src/generators/init/globalFiles/_github/workflows/preview-deploy.yml.template +17 -0
- package/dist/src/generators/init/init.d.ts +1 -0
- package/dist/src/generators/init/init.js +72 -11
- package/dist/src/generators/init/init.js.map +1 -1
- package/dist/src/generators/init/schema.json +21 -1
- package/dist/src/generators/local-lambda-setup/files/docker-compose/docker-compose.yml.template +21 -0
- package/dist/src/generators/local-lambda-setup/files/scripts/invoke_lambda_local.sh.template +97 -0
- package/dist/src/generators/local-lambda-setup/local-lambda-setup.d.ts +29 -0
- package/dist/src/generators/local-lambda-setup/local-lambda-setup.js +176 -0
- package/dist/src/generators/local-lambda-setup/local-lambda-setup.js.map +1 -0
- package/dist/src/generators/local-lambda-setup/schema.json +24 -0
- package/dist/src/generators/sync/files/lambda_functions.ts.template +1 -0
- package/dist/src/generators/sync/schema.json +8 -0
- package/dist/src/generators/sync/sync-list-lambda-functions.d.ts +4 -0
- package/dist/src/generators/sync/sync-list-lambda-functions.js +45 -0
- package/dist/src/generators/sync/sync-list-lambda-functions.js.map +1 -0
- package/dist/src/index.d.ts +6 -19
- package/dist/src/index.js +64 -55
- package/dist/src/index.js.map +1 -1
- package/dist/src/{generators/init/files/.circleci/config.yml.template → migrations/20250926-config.test.yaml} +27 -70
- package/dist/src/migrations/20250926-separate-docker-build-from-release.d.ts +2 -0
- package/dist/src/migrations/20250926-separate-docker-build-from-release.js +127 -0
- package/dist/src/migrations/20250926-separate-docker-build-from-release.js.map +1 -0
- package/dist/src/migrations/20251003-rename-ecr-registry-to-ecr-repository.d.ts +2 -0
- package/dist/src/migrations/20251003-rename-ecr-registry-to-ecr-repository.js +23 -0
- package/dist/src/migrations/20251003-rename-ecr-registry-to-ecr-repository.js.map +1 -0
- package/dist/src/migrations/20251029-nx-conformance-requirement-publish.d.ts +2 -0
- package/dist/src/migrations/20251029-nx-conformance-requirement-publish.js +85 -0
- package/dist/src/migrations/20251029-nx-conformance-requirement-publish.js.map +1 -0
- package/dist/src/migrations/20251112-fix-parallelization-circleci.d.ts +2 -0
- package/dist/src/migrations/20251112-fix-parallelization-circleci.js +98 -0
- package/dist/src/migrations/20251112-fix-parallelization-circleci.js.map +1 -0
- package/dist/src/migrations/20251205-metadata-lambda-function-to-object.d.ts +2 -0
- package/dist/src/migrations/20251205-metadata-lambda-function-to-object.js +28 -0
- package/dist/src/migrations/20251205-metadata-lambda-function-to-object.js.map +1 -0
- package/dist/src/migrations/5.11.0/20251209-nx-renovate-gha.d.ts +2 -0
- package/dist/src/migrations/5.11.0/20251209-nx-renovate-gha.js +24 -0
- package/dist/src/migrations/5.11.0/20251209-nx-renovate-gha.js.map +1 -0
- package/dist/src/migrations/5.11.0/templates/_github/workflows/ide-nx-migrate.yml.template +17 -0
- package/dist/src/migrations/5.13.0/20251222-remove-tbot-conf.d.ts +2 -0
- package/dist/src/migrations/5.13.0/20251222-remove-tbot-conf.js +14 -0
- package/dist/src/migrations/5.13.0/20251222-remove-tbot-conf.js.map +1 -0
- package/dist/src/migrations/5.13.2/20251226-switch-renovate-config.d.ts +2 -0
- package/dist/src/migrations/5.13.2/20251226-switch-renovate-config.js +41 -0
- package/dist/src/migrations/5.13.2/20251226-switch-renovate-config.js.map +1 -0
- package/dist/src/migrations/README.md +20 -0
- package/dist/src/scripts/nx-core-updater.js +564 -0
- package/dist/src/scripts/version-actions-frontend.d.ts +7 -0
- package/dist/src/scripts/version-actions-frontend.js +42 -0
- package/dist/src/scripts/version-actions-frontend.js.map +1 -0
- package/dist/src/scripts/version-actions.js +21 -6
- package/dist/src/scripts/version-actions.js.map +1 -1
- package/dist/src/scripts/version-actions.mock.d.ts +3 -3
- package/dist/src/scripts/version-actions.mock.js +12 -5
- package/dist/src/scripts/version-actions.mock.js.map +1 -1
- package/dist/src/utils/common/aws-auth.d.ts +0 -15
- package/dist/src/utils/common/aws-auth.js +17 -27
- package/dist/src/utils/common/aws-auth.js.map +1 -1
- package/dist/src/utils/common/constants.d.ts +7 -0
- package/dist/src/utils/common/constants.js +10 -0
- package/dist/src/utils/common/constants.js.map +1 -0
- package/dist/src/utils/common/ecr.d.ts +13 -0
- package/dist/src/utils/common/ecr.js +194 -0
- package/dist/src/utils/common/ecr.js.map +1 -0
- package/dist/src/utils/common/environment.d.ts +1 -0
- package/dist/src/utils/common/environment.js +11 -0
- package/dist/src/utils/common/environment.js.map +1 -0
- package/dist/src/utils/common/exec.js +0 -3
- package/dist/src/utils/common/exec.js.map +1 -1
- package/dist/src/utils/common/github.d.ts +13 -2
- package/dist/src/utils/common/github.js +55 -3
- package/dist/src/utils/common/github.js.map +1 -1
- package/dist/src/utils/common/nx.d.ts +3 -21
- package/dist/src/utils/common/nx.js +27 -135
- package/dist/src/utils/common/nx.js.map +1 -1
- package/dist/src/utils/common/oci.d.ts +30 -0
- package/dist/src/utils/common/oci.js +83 -0
- package/dist/src/utils/common/oci.js.map +1 -0
- package/dist/src/utils/common/octokit.d.ts +2 -0
- package/dist/src/utils/common/octokit.js +22 -0
- package/dist/src/utils/common/octokit.js.map +1 -0
- package/dist/src/utils/common/renovate.d.ts +2 -0
- package/dist/src/utils/common/renovate.js +26 -0
- package/dist/src/utils/common/renovate.js.map +1 -0
- package/dist/src/utils/common/tsh.d.ts +1 -1
- package/dist/src/utils/common/tsh.js +15 -3
- package/dist/src/utils/common/tsh.js.map +1 -1
- package/dist/src/utils/common/types.d.ts +4 -0
- package/dist/src/utils/common/types.js +3 -0
- package/dist/src/utils/common/types.js.map +1 -0
- package/dist/src/utils/docker.d.ts +4 -1
- package/dist/src/utils/docker.js +67 -14
- package/dist/src/utils/docker.js.map +1 -1
- package/dist/src/utils/frontend/s3.d.ts +1 -0
- package/dist/src/utils/frontend/s3.js +41 -0
- package/dist/src/utils/frontend/s3.js.map +1 -0
- package/dist/src/utils/helm.d.ts +2 -2
- package/dist/src/utils/helm.js +53 -19
- package/dist/src/utils/helm.js.map +1 -1
- package/dist/src/utils/lambda/aws-lambda.d.ts +3 -3
- package/dist/src/utils/lambda/aws-lambda.js +11 -12
- package/dist/src/utils/lambda/aws-lambda.js.map +1 -1
- package/dist/src/utils/lambda/publish.d.ts +2 -2
- package/dist/src/utils/lambda/publish.js +3 -4
- package/dist/src/utils/lambda/publish.js.map +1 -1
- package/dist/src/utils/spacelift/lib/__generated__/graphql.d.ts +3 -385
- package/dist/src/utils/spacelift/lib/__generated__/graphql.js +0 -6
- package/dist/src/utils/spacelift/lib/__generated__/graphql.js.map +1 -1
- package/executors.json +5 -0
- package/generators.json +12 -1
- package/package.json +30 -14
- package/dist/src/generators/init/files/.circleci/teleport/shared-charts.conf.template +0 -24
- package/dist/src/generators/init/files/.npmrc.template +0 -1
- package/dist/src/utils/helm.mock.d.ts +0 -85
- package/dist/src/utils/helm.mock.js +0 -100
- package/dist/src/utils/helm.mock.js.map +0 -1
- package/dist/src/utils/lambda/oci.d.ts +0 -8
- package/dist/src/utils/lambda/oci.js +0 -22
- package/dist/src/utils/lambda/oci.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# @payfit/nx-core
|
|
2
2
|
|
|
3
|
-
A Nx plugin that simplifies Docker image
|
|
3
|
+
A Nx plugin that simplifies Docker image, Helm chart, lambda, frontend, and OpenTofu/Terraform module packaging and releases using Nx release & Nx's versionActions feature.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- Automated Docker image building and publishing
|
|
7
|
+
- Automated Docker image building and publishing to ECR
|
|
8
8
|
- Helm chart packaging and versioning
|
|
9
|
-
- AWS Lambda function packaging and deployment
|
|
10
|
-
-
|
|
9
|
+
- AWS Lambda function packaging and deployment (ZIP and Docker-based)
|
|
10
|
+
- Frontend publishing to S3 with CDN-optimized caching
|
|
11
|
+
- Transparent version management through Nx's versionActions (CalVer by default)
|
|
11
12
|
- Seamless integration with your Nx workspace
|
|
12
13
|
- Auto setup using init generator to update your repository at plugin installation
|
|
13
14
|
|
|
@@ -32,7 +33,7 @@ This command will:
|
|
|
32
33
|
|
|
33
34
|
Using the above command will setup your repo with the default recommended configuration. You are free to edit this configuration to your needs.
|
|
34
35
|
|
|
35
|
-
It will also generate the CircleCI config file
|
|
36
|
+
It will also generate the CircleCI config file and GitHub Actions workflows needed.
|
|
36
37
|
|
|
37
38
|
The plugin uses Nx's versionActions to handle versioning transparently. [We only override the semver calculation to switch it to calver (which you can opt out)](./src/scripts/version-actions.ts).
|
|
38
39
|
|
|
@@ -44,7 +45,7 @@ The plugin automatically handles:
|
|
|
44
45
|
|
|
45
46
|
- Building Docker images
|
|
46
47
|
- Tagging with appropriate versions
|
|
47
|
-
- Publishing
|
|
48
|
+
- Publishing your container
|
|
48
49
|
|
|
49
50
|
### Helm Chart Release
|
|
50
51
|
|
|
@@ -77,83 +78,98 @@ The plugin automates the process of packaging and deploying AWS Lambda functions
|
|
|
77
78
|
|
|
78
79
|
#### Lambda Configuration Parameters
|
|
79
80
|
|
|
80
|
-
When using Lambda functions, you
|
|
81
|
+
When using Lambda functions, you must configure the following parameters in your project's `project.json` file:
|
|
81
82
|
|
|
82
83
|
```json
|
|
83
84
|
{
|
|
84
85
|
"metadata": {
|
|
85
|
-
"lambdaFunctions": [
|
|
86
|
+
"lambdaFunctions": [
|
|
87
|
+
{
|
|
88
|
+
"name": "your-lambda",
|
|
89
|
+
"healthCheckPayload": "{\"key\": \"value\"}" // Escaped JSON string
|
|
90
|
+
}
|
|
91
|
+
],
|
|
86
92
|
"lambdaStacks": ["your-lambda-stack"],
|
|
87
93
|
"lambdaBucket": "your-lambda-bucket",
|
|
88
|
-
"
|
|
94
|
+
"lambdaOciRepository": "your-lambda-oci-repository"
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
```
|
|
92
98
|
|
|
93
99
|
These fields are used to:
|
|
94
100
|
|
|
95
|
-
- `lambdaFunctions
|
|
96
|
-
- `lambdaStacks
|
|
101
|
+
- `lambdaFunctions` **(required)**: Lambda functions to deploy with their name and healthcheck payload. The `healthCheckPayload` must be a valid JSON string.
|
|
102
|
+
- `lambdaStacks` **(required)**: Spacelift stacks deploying lambdas
|
|
97
103
|
- `lambdaBucket`: the S3 bucket where Lambda function zip archives are stored
|
|
98
|
-
- `
|
|
104
|
+
- `lambdaOciRepository`: the OCI repository used to publish lambda release candidates for Kargo
|
|
99
105
|
|
|
100
106
|
If `lambdaBucket` is not specified, the plugin will fall back to the default bucket: `payfit-shared-lambda-artifacts`.
|
|
107
|
+
If `lambdaOciRepository` is not specified for ZIP-based Lambdas, the plugin will fall back to the value of `lambdaFunctions[0].name`.
|
|
108
|
+
|
|
109
|
+
> **Note**: For Docker-based Lambdas (projects with both `Dockerfile` and lambda metadata), `lambdaOciRepository` must be explicitly specified and the fallback does not apply.
|
|
101
110
|
|
|
102
111
|
#### Lambda Detection
|
|
103
112
|
|
|
104
|
-
The plugin automatically detects Lambda functions by looking for
|
|
113
|
+
The plugin automatically detects Lambda functions by looking for **both** `lambdaFunctions` and `lambdaStacks` metadata arrays in your project's `project.json`. When both are present and non-empty, the plugin will configure the necessary targets for packaging and deploying your Lambda function.
|
|
114
|
+
|
|
115
|
+
### Frontend Release
|
|
116
|
+
|
|
117
|
+
The plugin automates the process of packaging and deploying frontend applications:
|
|
118
|
+
|
|
119
|
+
- Publishing built assets to an S3 bucket with proper cache headers
|
|
120
|
+
- Creating an OCI artifact and pushing it to ECR for Kargo promotion
|
|
105
121
|
|
|
106
|
-
|
|
122
|
+
#### Frontend Configuration Parameters
|
|
107
123
|
|
|
108
|
-
|
|
124
|
+
When using frontend projects, you can configure the following parameters in your project's `project.json` file:
|
|
109
125
|
|
|
110
126
|
```json
|
|
111
127
|
{
|
|
112
128
|
"metadata": {
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
116
|
-
"
|
|
117
|
-
"lambdaFunctions": ["your-lambda-registry"],
|
|
118
|
-
"lambdaStacks": ["your-lambda-stack"],
|
|
119
|
-
"lambdaBucket": "your-lambda-bucket",
|
|
120
|
-
"lambdaHealthCheckPayload": "your-lambda-payload-json-string-formatted"
|
|
129
|
+
"frontendArtifactsBucketName": "your-frontend-bucket",
|
|
130
|
+
"frontendOciRepository": "your-frontend-oci-repository",
|
|
131
|
+
"frontendFilesWithoutCache": ["index.html", "favicon.ico"],
|
|
132
|
+
"frontendFoldersWithoutCache": ["config"]
|
|
121
133
|
}
|
|
122
134
|
}
|
|
123
135
|
```
|
|
124
136
|
|
|
125
137
|
These fields are used to:
|
|
126
138
|
|
|
127
|
-
- `
|
|
128
|
-
- `
|
|
129
|
-
- `
|
|
130
|
-
- `
|
|
131
|
-
- `lambdaStacks`: the spacelift stacks containing lambda to deploy
|
|
132
|
-
- `lambdaFunctions`: the lambda functions to deploy
|
|
133
|
-
- `lambdaBucket`: the S3 bucket where Lambda function zip archives are stored (defaults to `payfit-shared-lambda-artifacts`)
|
|
134
|
-
- `lambdaHealthCheckPayload`: Payload used for smoke tests invocation before lambda being released
|
|
139
|
+
- `frontendArtifactsBucketName` **(required)**: The S3 bucket where frontend assets are stored
|
|
140
|
+
- `frontendOciRepository`: The OCI repository used to publish frontend release candidates for Kargo. Defaults to the project name.
|
|
141
|
+
- `frontendFilesWithoutCache`: Files that should be served without cache headers (defaults to `["index.html", "favicon.ico"]`)
|
|
142
|
+
- `frontendFoldersWithoutCache`: Folders that should be served without cache headers (defaults to `[]`)
|
|
135
143
|
|
|
136
144
|
## Automatic Release Target Inference
|
|
137
145
|
|
|
138
|
-
The plugin automatically infers release targets for your projects based on the presence of deployment files:
|
|
146
|
+
The plugin automatically infers release targets for your projects based on the presence of deployment files and metadata:
|
|
139
147
|
|
|
140
|
-
1. **Docker Image Release**: If a `Dockerfile` exists in your project root, the plugin will automatically:
|
|
148
|
+
1. **Docker Image Release**: If a `Dockerfile` exists in your project root **AND** `ecrRepository` metadata is set, the plugin will automatically:
|
|
141
149
|
- Configure Docker image building and publishing
|
|
142
150
|
- Set up version management for the image
|
|
143
151
|
- Handle ECR repository integration
|
|
144
152
|
|
|
145
|
-
2. **Helm Chart Release**: If a `Chart.yaml` exists in your Helm chart folder (defaults to `.deploy/Chart.yaml`), the plugin will automatically:
|
|
153
|
+
2. **Helm Chart Release**: If a `Chart.yaml` exists in your Helm chart folder (defaults to `.deploy/Chart.yaml`) **AND** `chartRegistry` metadata is set, the plugin will automatically:
|
|
146
154
|
- Configure Helm chart packaging and versioning
|
|
147
155
|
- Set up chart publishing to your registry
|
|
148
156
|
- Handle chart dependencies and updates
|
|
149
157
|
|
|
150
|
-
3. **Lambda Function Release**: If
|
|
151
|
-
- Configure Lambda function packaging (zip archive creation)
|
|
158
|
+
3. **Lambda Function Release**: If both `lambdaFunctions` and `lambdaStacks` metadata arrays are present and non-empty, the plugin will automatically:
|
|
159
|
+
- Configure Lambda function packaging (zip archive creation for non-Docker lambdas)
|
|
152
160
|
- Set up S3 bucket uploading for the Lambda artifact
|
|
153
|
-
-
|
|
161
|
+
- Trigger Spacelift stacks and run smoke tests
|
|
162
|
+
- Create and push an OCI artifact to ECR for versioning (for Kargo promotion)
|
|
163
|
+
|
|
164
|
+
4. **Frontend Release**: If `frontendArtifactsBucketName` metadata is set, the plugin will automatically:
|
|
165
|
+
- Configure frontend asset publishing to S3
|
|
166
|
+
- Set up cache headers for optimal CDN caching
|
|
167
|
+
- Create and push an OCI artifact to ECR for versioning (for Kargo promotion)
|
|
154
168
|
|
|
155
169
|
The inference of the `nx-release-publish` target is handled through Nx's plugin system, which automatically adds the necessary targets and version actions to your project configuration. You don't need to manually configure these targets.
|
|
156
170
|
|
|
171
|
+
**Note**: For Terraform/OpenTofu module management (formatting, linting, validation), see the `@payfit/iac` plugin.
|
|
172
|
+
|
|
157
173
|
---
|
|
158
174
|
|
|
159
175
|
# Debug locally
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExecutorContext } from '@nx/devkit';
|
|
2
|
+
import { DockerBuildExecutorOptions, DockerBuildExecutorSchema } from './schema';
|
|
3
|
+
declare const runExecutor: (options: DockerBuildExecutorOptions, context: ExecutorContext) => Promise<DockerBuildExecutorSchema>;
|
|
4
|
+
export default runExecutor;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const ecr_1 = require("../../utils/common/ecr");
|
|
5
|
+
const github_1 = require("../../utils/common/github");
|
|
6
|
+
const logger_1 = require("../../utils/common/logger");
|
|
7
|
+
const docker_1 = require("../../utils/docker");
|
|
8
|
+
const runExecutor = async (options, context) => {
|
|
9
|
+
const projectRoot = context.projectGraph.nodes[context.projectName].data.root;
|
|
10
|
+
const projectDockerfile = `${projectRoot}/Dockerfile`;
|
|
11
|
+
const isCI = process.env.CI === 'true';
|
|
12
|
+
if (!fs.existsSync(projectDockerfile)) {
|
|
13
|
+
logger_1.consola.warn(`Dockerfile not found at ${projectDockerfile}, skipping`);
|
|
14
|
+
return { success: true };
|
|
15
|
+
}
|
|
16
|
+
if (!options.ecrRepository) {
|
|
17
|
+
logger_1.consola.error('Dockerfile detected but No ECR registry provided, add "ecrRepository" to your project.json metadata');
|
|
18
|
+
return { success: false };
|
|
19
|
+
}
|
|
20
|
+
const registry = {
|
|
21
|
+
url: options.isPublicRegistry
|
|
22
|
+
? 'public.ecr.aws/payfit'
|
|
23
|
+
: (0, ecr_1.getAwsEcrRegistry)(),
|
|
24
|
+
name: options.isPublicRegistry ? 'public.ecr.aws' : (0, ecr_1.getAwsEcrRegistry)(),
|
|
25
|
+
};
|
|
26
|
+
const commitSha = await (0, github_1.getCurrentGitCommitSha)();
|
|
27
|
+
const sanitizedRepoUrl = await (0, github_1.getSanitizedCurrentGitRepoUrl)();
|
|
28
|
+
const tag = `ephemeral-sha-${commitSha}`;
|
|
29
|
+
if (options.isDryRun) {
|
|
30
|
+
logger_1.consola.box(`Would have published docker image located at ${projectDockerfile} to registry ${options.ecrRepository} with tag ${tag} but --dry-run is enabled`);
|
|
31
|
+
return { success: true };
|
|
32
|
+
}
|
|
33
|
+
if (isCI) {
|
|
34
|
+
await (0, ecr_1.ensureEcrAuth)(registry.name, options.isPublicRegistry);
|
|
35
|
+
}
|
|
36
|
+
// Build ephemeral sha tag (immutable)
|
|
37
|
+
logger_1.consola.box(`${isCI ? 'Building and pushing ephemeral' : 'Building locally'} image to ${isCI ? registry.url + '/' : ''}${options.ecrRepository}:${tag}`);
|
|
38
|
+
await (0, docker_1.buildAndPushDockerImage)(options.ecrRepository, projectDockerfile, tag, sanitizedRepoUrl, commitSha, registry.url, [], context.projectName, options.buildArgs, isCI);
|
|
39
|
+
return { success: true };
|
|
40
|
+
};
|
|
41
|
+
exports.default = runExecutor;
|
|
42
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../src/executors/docker-build/executor.ts"],"names":[],"mappings":";;AAAA,8BAA6B;AAI7B,gDAI+B;AAC/B,sDAGkC;AAClC,sDAAmD;AACnD,+CAA4D;AAG5D,MAAM,WAAW,GAGyB,KAAK,EAC7C,OAAmC,EACnC,OAAwB,EACxB,EAAE;IACF,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;IAC7E,MAAM,iBAAiB,GAAG,GAAG,WAAW,aAAa,CAAA;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,KAAK,MAAM,CAAA;IAEtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,CAAC;QACtC,gBAAO,C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AAC,aAAa,IAAI,GAAG,EAAE,CAC5I,CAAA;IAED,MAAM,IAAA,gCAAuB,EAC3B,OAAO,CAAC,aAAa,EACrB,iBAAiB,EACjB,GAAG,EACH,gBAAgB,EAChB,SAAS,EACT,QAAQ,CAAC,GAAG,EACZ,EAAE,EACF,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,SAAS,EACjB,IAAI,CACL,CAAA;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAC1B,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"title": "Docker build executor",
|
|
5
|
+
"description": "Build and push ephemeral Docker image (ephemeral-sha-<commit>) with Buildx",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"ecrRepository": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The ecr repository name (i.e. the image name)"
|
|
11
|
+
},
|
|
12
|
+
"isPublicRegistry": {
|
|
13
|
+
"type": "boolean",
|
|
14
|
+
"description": "Use AWS public ECR (us-east-1)",
|
|
15
|
+
"default": false
|
|
16
|
+
},
|
|
17
|
+
"isDryRun": {
|
|
18
|
+
"type": "boolean",
|
|
19
|
+
"description": "Do not build/push, only print what would happen",
|
|
20
|
+
"default": false
|
|
21
|
+
},
|
|
22
|
+
"buildArgs": {
|
|
23
|
+
"type": "string",
|
|
24
|
+
"description": "Build arguments to pass to Docker build",
|
|
25
|
+
"examples": ["NODE_VERSION=18.20.0"]
|
|
26
|
+
},
|
|
27
|
+
"required": ["ecrRepository"]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Updates the ArgoCD override configuration based on the target branch
|
|
3
3
|
*/
|
|
4
|
-
export declare function updateArgoCDOverride(argocdOverride: Record<string, unknown>, targetBranchName: string): Record<string, unknown> | undefined
|
|
4
|
+
export declare function updateArgoCDOverride(argocdOverride: Record<string, unknown>, targetBranchName: string): Promise<Record<string, unknown> | undefined>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateArgoCDOverride = updateArgoCDOverride;
|
|
4
|
-
const github_1 = require("
|
|
4
|
+
const github_1 = require("./github");
|
|
5
5
|
/**
|
|
6
6
|
* Updates the ArgoCD override configuration based on the target branch
|
|
7
7
|
*/
|
|
8
|
-
function updateArgoCDOverride(argocdOverride, targetBranchName) {
|
|
8
|
+
async function updateArgoCDOverride(argocdOverride, targetBranchName) {
|
|
9
9
|
// Handle main/master branches - remove target revision
|
|
10
|
-
if ((0, github_1.isDefaultBranch)(targetBranchName)) {
|
|
10
|
+
if (await (0, github_1.isDefaultBranch)(targetBranchName)) {
|
|
11
11
|
if (argocdOverride.targetRevision) {
|
|
12
12
|
delete argocdOverride.targetRevision;
|
|
13
13
|
return argocdOverride;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argocdOverride.js","sourceRoot":"","sources":["../../../../src/executors/preview-deploy/argocdOverride.ts"],"names":[],"mappings":";;AAKA,oDAiBC;AAtBD,
|
|
1
|
+
{"version":3,"file":"argocdOverride.js","sourceRoot":"","sources":["../../../../src/executors/preview-deploy/argocdOverride.ts"],"names":[],"mappings":";;AAKA,oDAiBC;AAtBD,qCAA0C;AAE1C;;GAEG;AACI,KAAK,UAAU,oBAAoB,CACxC,cAAuC,EACvC,gBAAwB;IAExB,uDAAuD;IACvD,IAAI,MAAM,IAAA,wBAAe,EAAC,gBAAgB,CAAC,EAAE,CAAC;QAC5C,IAAI,cAAc,CAAC,cAAc,EAAE,CAAC;YAClC,OAAO,cAAc,CAAC,cAAc,CAAA;YACpC,OAAO,cAAc,CAAA;QACvB,CAAC;QACD,oDAAoD;QACpD,OAAM;IACR,CAAC;IAED,gDAAgD;IAChD,cAAc,CAAC,cAAc,GAAG,gBAAgB,CAAA;IAChD,OAAO,cAAc,CAAA;AACvB,CAAC"}
|
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const auth_app_1 = require("@octokit/auth-app");
|
|
4
|
-
const rest_1 = require("@octokit/rest");
|
|
5
3
|
const yaml = require("yaml");
|
|
6
4
|
const logger_1 = require("../../utils/common/logger");
|
|
5
|
+
const octokit_1 = require("../../utils/common/octokit");
|
|
7
6
|
const argocdOverride_1 = require("./argocdOverride");
|
|
8
7
|
const kargoPolicy_1 = require("./kargoPolicy");
|
|
8
|
+
function sleep(ms) {
|
|
9
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Retry a function when it throws a 409 Conflict error, up to 5 times.
|
|
13
|
+
* Waits 2 seconds between retries.
|
|
14
|
+
*/
|
|
15
|
+
async function retryOnConflict(fn) {
|
|
16
|
+
const maxAttempts = 5;
|
|
17
|
+
const retryDelay = 2000;
|
|
18
|
+
let lastError;
|
|
19
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
return await fn();
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
lastError = error;
|
|
25
|
+
// Only retry on 409 Conflict errors
|
|
26
|
+
if (error?.status !== 409) {
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
// Don't retry on the last attempt
|
|
30
|
+
if (attempt === maxAttempts - 1) {
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
logger_1.consola.warn(`Conflict detected (409), retrying in ${retryDelay}ms (attempt ${attempt + 1}/${maxAttempts})`);
|
|
34
|
+
await sleep(retryDelay);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw lastError;
|
|
38
|
+
}
|
|
9
39
|
function readFileYamlContent(file) {
|
|
10
40
|
if (!file) {
|
|
11
41
|
return undefined;
|
|
@@ -27,112 +57,99 @@ function readFileYamlContent(file) {
|
|
|
27
57
|
throw new Error(`Failed to parse YAML file: ${error}`);
|
|
28
58
|
}
|
|
29
59
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
auth: {
|
|
44
|
-
appId: getEnvVar('GITHUB_APP_ID'),
|
|
45
|
-
privateKey: getEnvVar('GITHUB_PRIVATE_KEY'),
|
|
46
|
-
installationId: getEnvVar('GITHUB_INSTALLATION_ID'),
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
const argocdOverridePath = `apps/${options.targetAppName}/${options.targetEnv}/.argocd-override.yaml`;
|
|
50
|
-
const kargoPolicyPath = `.kargo/policy.yaml`;
|
|
51
|
-
const message = `chore(${options.targetAppName}): switch deployment branch to ${options.targetBranchName} on ${options.targetEnv}`;
|
|
52
|
-
// Retrieve both files - throw error if either doesn't exist
|
|
53
|
-
const [argocdOverrideFile, kargoPolicyFile] = await Promise.all([
|
|
54
|
-
octokit.repos
|
|
55
|
-
.getContent({
|
|
56
|
-
owner: 'PayFit',
|
|
57
|
-
repo: options.targetRepo,
|
|
58
|
-
path: argocdOverridePath,
|
|
59
|
-
ref: 'heads/main',
|
|
60
|
-
})
|
|
61
|
-
.catch(e => {
|
|
62
|
-
// we don't update this file if it does not exist as it's optional
|
|
63
|
-
if (e.status === 404) {
|
|
64
|
-
logger_1.consola.info(`${options.targetRepo}/${argocdOverridePath} not found, ignoring this file`);
|
|
60
|
+
const getFileWithSha = async (octokit, owner, repo, path, optional = false) => {
|
|
61
|
+
const file = await octokit.repos
|
|
62
|
+
.getContent({
|
|
63
|
+
owner,
|
|
64
|
+
repo,
|
|
65
|
+
path,
|
|
66
|
+
ref: 'heads/main',
|
|
67
|
+
})
|
|
68
|
+
.catch(e => {
|
|
69
|
+
// we don't update this file if it does not exist as it's optional
|
|
70
|
+
if (e.status === 404) {
|
|
71
|
+
if (optional) {
|
|
72
|
+
logger_1.consola.info(`${repo}/${path} not found, ignoring this file`);
|
|
65
73
|
return undefined;
|
|
66
74
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
octokit.repos
|
|
70
|
-
.getContent({
|
|
71
|
-
owner: 'PayFit',
|
|
72
|
-
repo: options.targetRepo,
|
|
73
|
-
path: kargoPolicyPath,
|
|
74
|
-
ref: 'heads/main',
|
|
75
|
-
})
|
|
76
|
-
.catch(e => {
|
|
77
|
-
if (e.status === 404) {
|
|
78
|
-
throw new Error(`${options.targetRepo}/${kargoPolicyPath} not found`);
|
|
75
|
+
else {
|
|
76
|
+
throw new Error(`${repo}/${path} not found`);
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (argocdOverrideYaml)
|
|
86
|
-
argocdOverrideYaml = (0, argocdOverride_1.updateArgoCDOverride)(argocdOverrideYaml, options.targetBranchName);
|
|
87
|
-
kargoPolicyYaml = (0, kargoPolicy_1.updateKargoPolicy)(kargoPolicyYaml, options.targetBranchName, options.targetEnv, options.targetAppName);
|
|
88
|
-
if (!argocdOverrideYaml && !kargoPolicyYaml) {
|
|
89
|
-
logger_1.consola.warn('Everything is already setup correctly, skipping');
|
|
90
|
-
return {
|
|
91
|
-
success: true,
|
|
92
|
-
};
|
|
78
|
+
}
|
|
79
|
+
throw e;
|
|
80
|
+
});
|
|
81
|
+
if (!file) {
|
|
82
|
+
return undefined;
|
|
93
83
|
}
|
|
94
|
-
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
repo
|
|
101
|
-
|
|
102
|
-
message,
|
|
103
|
-
content: updatedArgocdContent,
|
|
104
|
-
branch: 'main',
|
|
105
|
-
sha: argocdOverrideFile.data.sha,
|
|
106
|
-
committer: {
|
|
107
|
-
name: 'github-actions[bot]',
|
|
108
|
-
email: 'github-actions[bot]@users.noreply.github.com',
|
|
109
|
-
},
|
|
110
|
-
author: {
|
|
111
|
-
name: 'github-actions[bot]',
|
|
112
|
-
email: 'github-actions[bot]@users.noreply.github.com',
|
|
113
|
-
},
|
|
114
|
-
});
|
|
84
|
+
const content = readFileYamlContent(file);
|
|
85
|
+
if (!content) {
|
|
86
|
+
if (optional) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw new Error(`${repo}/${path} exists but contains invalid or empty YAML content`);
|
|
91
|
+
}
|
|
115
92
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
93
|
+
return {
|
|
94
|
+
content,
|
|
95
|
+
sha: file.data.sha,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
const updateFile = async (octokit, owner, repo, path, message, content, sha) => {
|
|
99
|
+
const updatedContent = Buffer.from(content).toString('base64');
|
|
100
|
+
return await octokit.repos.createOrUpdateFileContents({
|
|
101
|
+
owner,
|
|
102
|
+
repo,
|
|
103
|
+
path,
|
|
104
|
+
message,
|
|
105
|
+
content: updatedContent,
|
|
106
|
+
branch: 'main',
|
|
107
|
+
sha,
|
|
108
|
+
committer: {
|
|
109
|
+
name: 'github-actions[bot]',
|
|
110
|
+
email: 'github-actions[bot]@users.noreply.github.com',
|
|
111
|
+
},
|
|
112
|
+
author: {
|
|
113
|
+
name: 'github-actions[bot]',
|
|
114
|
+
email: 'github-actions[bot]@users.noreply.github.com',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
const runExecutor = async (options) => {
|
|
119
|
+
logger_1.consola.box(`Start preview deploy switch for ${options.targetAppName} to target branch ${options.targetBranchName} on the ${options.targetEnv} env`);
|
|
120
|
+
const octokit = (0, octokit_1.OctokitAuth)();
|
|
121
|
+
const argocdOverridePath = `apps/${options.targetAppName}/${options.targetEnv}/.argocd-override.yaml`;
|
|
122
|
+
const kargoPolicyPath = `.kargo/policy.yaml`;
|
|
123
|
+
const message = `chore(${options.targetAppName}): switch deployment branch to ${options.targetBranchName} on ${options.targetEnv} [skip ci]`;
|
|
124
|
+
let hasUpdates = false;
|
|
125
|
+
// Update ArgoCD override file (optional)
|
|
126
|
+
await retryOnConflict(async () => {
|
|
127
|
+
const currentFile = await getFileWithSha(octokit, 'PayFit', options.targetRepo, argocdOverridePath, true);
|
|
128
|
+
if (!currentFile) {
|
|
129
|
+
return; // File doesn't exist (optional), skip
|
|
130
|
+
}
|
|
131
|
+
const updatedContent = await (0, argocdOverride_1.updateArgoCDOverride)(currentFile.content, options.targetBranchName);
|
|
132
|
+
if (!updatedContent) {
|
|
133
|
+
return; // No update needed
|
|
134
|
+
}
|
|
135
|
+
hasUpdates = true;
|
|
136
|
+
await updateFile(octokit, 'PayFit', options.targetRepo, argocdOverridePath, message, yaml.stringify(updatedContent), currentFile.sha);
|
|
137
|
+
});
|
|
138
|
+
// Update Kargo policy file (required)
|
|
139
|
+
await retryOnConflict(async () => {
|
|
140
|
+
const currentFile = await getFileWithSha(octokit, 'PayFit', options.targetRepo, kargoPolicyPath, false);
|
|
141
|
+
if (!currentFile) {
|
|
142
|
+
throw new Error(`Kargo policy file ${kargoPolicyPath} not found or contains invalid content`);
|
|
143
|
+
}
|
|
144
|
+
const updatedContent = await (0, kargoPolicy_1.updateKargoPolicy)(currentFile.content, options.targetBranchName, options.targetEnv, options.targetAppName);
|
|
145
|
+
if (!updatedContent) {
|
|
146
|
+
return; // No update needed
|
|
147
|
+
}
|
|
148
|
+
hasUpdates = true;
|
|
149
|
+
await updateFile(octokit, 'PayFit', options.targetRepo, kargoPolicyPath, message, yaml.stringify(updatedContent), currentFile.sha);
|
|
150
|
+
});
|
|
151
|
+
if (!hasUpdates) {
|
|
152
|
+
logger_1.consola.info('No updates needed, configuration is already correct');
|
|
136
153
|
}
|
|
137
154
|
logger_1.consola.success('Preview deploy switch succeed !');
|
|
138
155
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../src/executors/preview-deploy/executor.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../../src/executors/preview-deploy/executor.ts"],"names":[],"mappings":";;AAEA,6BAA4B;AAE5B,sDAAmD;AACnD,wDAAwD;AACxD,qDAAuD;AACvD,+CAA8D;AAM9D,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;AACxD,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,eAAe,CAAI,EAAoB;IACpD,MAAM,WAAW,GAAG,CAAC,CAAA;IACrB,MAAM,UAAU,GAAG,IAAI,CAAA;IACvB,IAAI,SAAkB,CAAA;IAEtB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAA;QACnB,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,SAAS,GAAG,KAAK,CAAA;YACjB,oCAAoC;YACpC,IAAI,KAAK,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC1B,MAAM,KAAK,CAAA;YACb,CAAC;YACD,kCAAkC;YAClC,IAAI,OAAO,KAAK,WAAW,GAAG,CAAC,EAAE,CAA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B,OAAO,EACP,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAC9B,WAAW,CAAC,GAAG,CAChB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,sCAAsC;IACtC,MAAM,eAAe,CAAC,KAAK,IAAI,EAAE;QAC/B,MAAM,WAAW,GAAG,MAAM,cAAc,CACtC,OAAO,EACP,QAAQ,EACR,OAAO,CAAC,UAAU,EAClB,eAAe,EACf,KAAK,CACN,CAAA;QACD,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CACb,qBAAqB,eAAe,wCAAwC,CAC7E,CAAA;QACH,CAAC;QACD,MAAM,cAAc,GAAG,MAAM,IAAA,+BAAiB,EAC5C,WAAW,CAAC,OAAsB,EAClC,OAAO,CAAC,gBAAgB,EACxB,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,aAAa,CACtB,CAAA;QACD,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAM,CAAC,mBAAmB;QAC5B,CAAC;QACD,UAAU,GAAG,IAAI,CAAA;QACjB,MAAM,UAAU,CACd,OAAO,EACP,QAAQ,EACR,OAAO,CAAC,UAAU,EAClB,eAAe,EACf,OAAO,EACP,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,EAC9B,WAAW,CAAC,GAAG,CAChB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,gBAAO,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;IACrE,CAAC;IAED,gBAAO,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAA;IAElD,OAAO;QACL,OAAO,EAAE,IAAI;KACd,CAAA;AACH,CAAC,CAAA;AAED,kBAAe,WAAW,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isDefaultBranch = isDefaultBranch;
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the current branch is a default branch
|
|
6
|
+
*/
|
|
7
|
+
async function isDefaultBranch(branchName) {
|
|
8
|
+
return branchName === 'main' || branchName === 'master';
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../../../src/executors/preview-deploy/github.ts"],"names":[],"mappings":";;AAGA,0CAEC;AALD;;GAEG;AACI,KAAK,UAAU,eAAe,CAAC,UAAkB;IACtD,OAAO,UAAU,KAAK,MAAM,IAAI,UAAU,KAAK,QAAQ,CAAA;AACzD,CAAC"}
|
|
@@ -11,4 +11,4 @@ export interface KargoPolicy {
|
|
|
11
11
|
/**
|
|
12
12
|
* Updates the Kargo policy configuration based on the target branch
|
|
13
13
|
*/
|
|
14
|
-
export declare function updateKargoPolicy(kargoPolicy: KargoPolicy, targetBranchName: string, targetEnv: string, targetAppName: string): KargoPolicy | undefined
|
|
14
|
+
export declare function updateKargoPolicy(kargoPolicy: KargoPolicy, targetBranchName: string, targetEnv: string, targetAppName: string): Promise<KargoPolicy | undefined>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateKargoPolicy = updateKargoPolicy;
|
|
4
|
-
|
|
4
|
+
// Type definition for Kargo policy structure
|
|
5
|
+
const github_1 = require("./github");
|
|
5
6
|
/**
|
|
6
7
|
* Ensures the service structure exists in the kargo policy
|
|
7
8
|
* Returns true if any structure was created, false otherwise
|
|
@@ -49,7 +50,7 @@ function setEphemeralBranch(kargoPolicy, appName, env, branchName) {
|
|
|
49
50
|
/**
|
|
50
51
|
* Updates the Kargo policy configuration based on the target branch
|
|
51
52
|
*/
|
|
52
|
-
function updateKargoPolicy(kargoPolicy, targetBranchName, targetEnv, targetAppName) {
|
|
53
|
+
async function updateKargoPolicy(kargoPolicy, targetBranchName, targetEnv, targetAppName) {
|
|
53
54
|
// Early return if service doesn't exist
|
|
54
55
|
if (!kargoPolicy.services || !kargoPolicy.services[targetAppName]) {
|
|
55
56
|
throw new Error('Unable to update kargo policy, service does not exist in the configuration');
|
|
@@ -57,7 +58,7 @@ function updateKargoPolicy(kargoPolicy, targetBranchName, targetEnv, targetAppNa
|
|
|
57
58
|
let hasChanged = false;
|
|
58
59
|
// Ensure structure exists and track if changes were made
|
|
59
60
|
ensureServiceStructure(kargoPolicy, targetAppName, targetEnv);
|
|
60
|
-
if ((0, github_1.isDefaultBranch)(targetBranchName)) {
|
|
61
|
+
if (await (0, github_1.isDefaultBranch)(targetBranchName)) {
|
|
61
62
|
// reset to default branch
|
|
62
63
|
hasChanged = resetKargoPolicyForDefaultBranch(kargoPolicy, targetAppName, targetEnv);
|
|
63
64
|
}
|