Skip to content

Commit df43691

Browse files
s4khxnyo
andauthored
fix: add prod-canary (#280)
Co-authored-by: Giuseppe Guerra <[email protected]>
1 parent 2908cea commit df43691

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

.github/workflows/cd.yml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ on:
203203
- `none` (or empty string): Skip deployment (run only CI)
204204
- `dev`: Deploy to dev catalog
205205
- `ops`: Deploy to ops catalog
206-
- `prod`: Deploy to dev AND ops AND prod
206+
- `prod-canary`: Deploy to subset of prod instances - free and on instant wave
207+
- `prod`: Deploy to dev AND ops AND prod-canary AND prod
207208
- A comma separated combination of the values above. E.g.: `dev,ops`
208209
209210
Docs will only be published to the website when targeting `prod`.
@@ -330,9 +331,22 @@ jobs:
330331
echo "plugin_version_suffix=${INPUT_PLUGIN_VERSION_SUFFIX}" >> "$GITHUB_OUTPUT"
331332
else
332333
# Default behavior:
333-
# - Use the commit SHA as the version suffix when not on main
334+
# - Add commit hash for prod-canary only deployments OR non-main branches
334335
# - Otherwise, do not set the suffix
335-
if [ "${INPUT_BRANCH}" != 'main' ]; then
336+
IFS=',' read -ra envs <<< "$ENVIRONMENT"
337+
has_prod_canary=false
338+
has_prod=false
339+
for e in "${envs[@]}"; do
340+
if [[ "$e" == "prod-canary" ]]; then
341+
has_prod_canary=true
342+
fi
343+
if [[ "$e" == "prod" ]]; then
344+
has_prod=true
345+
fi
346+
done
347+
348+
if { $has_prod_canary && ! $has_prod; } || [[ "${INPUT_BRANCH}" != 'main' ]]; then
349+
echo "setting plugin version suffix => ${COMMIT_SHA}"
336350
echo "plugin_version_suffix=${COMMIT_SHA}" >> "$GITHUB_OUTPUT"
337351
else
338352
echo "plugin_version_suffix=" >> "$GITHUB_OUTPUT"
@@ -341,6 +355,7 @@ jobs:
341355
env:
342356
INPUT_PLUGIN_VERSION_SUFFIX: ${{ inputs.plugin-version-suffix }}
343357
INPUT_BRANCH: ${{ inputs.branch }}
358+
ENVIRONMENT: ${{ inputs.environment }}
344359
COMMIT_SHA: ${{ steps.checkout-specified-branch.outputs.commit }}
345360
shell: bash
346361

@@ -411,6 +426,12 @@ jobs:
411426
- ci
412427

413428
outputs:
429+
# JSON list of target environments, based on the `environment` input.
430+
# It returns a JSON array even if only one environment is targeted (e.g.: `dev` -> `["dev"]`)
431+
# This output can be used to determine target catalogs.
432+
# When targeting `prod`, all environments are returned, excluding `prod-canary` (`["dev", "ops", "prod"]`)
433+
# When targeting `prod-canary` explicitly, it will be included in the list.
434+
# If the environment value is exactly `none`, an empty array is returned (`[]`)
414435
environments: ${{ steps.vars.outputs.environments }}
415436
publish-docs: ${{ steps.vars.outputs.publish-docs }}
416437
platforms: ${{ steps.vars.outputs.platforms }}
@@ -453,15 +474,16 @@ jobs:
453474
}
454475
455476
// Parse and filter environments
456-
const allowedEnvironments = ['dev', 'ops', 'prod'];
477+
const allowedEnvironments = ['dev', 'ops', 'prod-canary', 'prod'];
457478
let environments = [];
458479
environments = ENVIRONMENT.split(',')
459480
.map(e => e.trim())
460481
.filter(e => allowedEnvironments.includes(e));
461482
462483
// Special case: 'prod' means we deploy to all environments
463484
if (environments.includes('prod')) {
464-
environments = allowedEnvironments;
485+
// no need to publish the version to prod-canary because it uses the same catalog as prod
486+
environments = allowedEnvironments.filter(e => e !== 'prod-canary');
465487
}
466488
467489
// Remove duplicates and sort
@@ -521,7 +543,7 @@ jobs:
521543
- name: Login to Google Cloud (ID token for IAP)
522544
id: gcloud
523545
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3.0.0
524-
if: ${{ matrix.environment != 'prod' }}
546+
if: ${{ matrix.environment != 'prod' && matrix.environment != 'prod-canary' }}
525547
with:
526548
workload_identity_provider: "projects/304398677251/locations/global/workloadIdentityPools/github/providers/github-provider"
527549
service_account: github-plugin-ci-workflows@grafanalabs-workload-identity.iam.gserviceaccount.com
@@ -550,7 +572,7 @@ jobs:
550572
elif [ "${ENVIRONMENT}" == 'ops' ]; then
551573
echo "Picked ops token"
552574
token="${{ fromJSON(steps.get-secrets.outputs.secrets).GCOM_PUBLISH_TOKEN_OPS }}"
553-
elif [ "${ENVIRONMENT}" == 'prod' ]; then
575+
elif [[ "${ENVIRONMENT}" == 'prod-canary' || "${ENVIRONMENT}" == 'prod' ]]; then
554576
echo "Picked prod token"
555577
token="${{ fromJSON(steps.get-secrets.outputs.secrets).GCOM_PUBLISH_TOKEN_PROD }}"
556578
else
@@ -564,7 +586,7 @@ jobs:
564586

565587
- name: Check and create stub
566588
uses: grafana/plugin-ci-workflows/actions/plugins/publish/check-and-create-stub@main
567-
if: ${{ matrix.environment != 'prod' }}
589+
if: ${{ matrix.environment != 'prod' && matrix.environment != 'prod-canary' }}
568590
with:
569591
plugin-id: ${{ fromJSON(needs.ci.outputs.plugin).id }}
570592
environment: ${{ matrix.environment }}
@@ -581,12 +603,12 @@ jobs:
581603
uses: grafana/plugin-ci-workflows/actions/plugins/publish/publish@main
582604
with:
583605
zips: ${{ needs.upload-to-gcs-release.outputs.gcs-zip-urls }}
584-
environment: ${{ matrix.environment }}
606+
environment: ${{ matrix.environment == 'prod-canary' && 'prod' || matrix.environment }}
585607
scopes: ${{ inputs.scopes }}
586608
gcom-publish-token: ${{ env.GCOM_PUBLISH_TOKEN }}
587609
gcloud-auth-token: ${{ steps.gcloud.outputs.id_token }}
588610
ignore-conflicts: ${{ steps.determine-continue.outputs.ignore_conflicts }}
589-
publish-as-pending: ${{ inputs.publish-to-catalog-as-pending }}
611+
publish-as-pending: ${{ matrix.environment == 'prod-canary' || inputs.publish-to-catalog-as-pending }}
590612

591613
trigger-argo-workflow:
592614
name: Trigger Argo Workflow for Grafana Cloud deployment

examples/base/provisioned-plugin-auto-cd/publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020
options:
2121
- "dev"
2222
- "ops"
23+
- "prod-canary"
2324
- "prod"
2425
docs-only:
2526
description: Only publish docs, do not publish the plugin

examples/base/provisioned-plugin-manual-deployment/publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020
options:
2121
- "dev"
2222
- "ops"
23+
- "prod-canary"
2324
- "prod"
2425
docs-only:
2526
description: Only publish docs, do not publish the plugin

examples/base/simple/publish.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ on:
2020
options:
2121
- "dev"
2222
- "ops"
23+
- "prod-canary"
2324
- "prod"
2425
docs-only:
2526
description: Only publish docs, do not publish the plugin

0 commit comments

Comments
 (0)