Skip to content

Commit e06cc1d

Browse files
committed
chore(ci): when deploying compass web, deploy to all previous environments to make sure release version is consistent
1 parent cae6ba4 commit e06cc1d

File tree

4 files changed

+98
-10
lines changed

4 files changed

+98
-10
lines changed

.github/workflows/publish-compass-web.yaml

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,53 @@ permissions:
3232
contents: read
3333

3434
jobs:
35+
configure_deployments:
36+
name: Configure deployments
37+
runs-on: ubuntu-latest
38+
outputs:
39+
environments: ${{ steps.define_environments.outputs.environments }}
40+
commit_hash: ${{ steps.define_commit_hash.outputs.commit_hash }}
41+
steps:
42+
- id: define_environments
43+
name: Define environments configurations
44+
run: |
45+
# Select all environments up to and including the one selected for the
46+
# release
47+
environments=""
48+
for env in "dev" "qa" "staging" "prod"; do
49+
environments+="\"$env\", "
50+
if [[ $env == "${{ inputs.publish_environment }}" ]]; then
51+
break
52+
fi
53+
done
54+
environments=${environments/%, /} # remove trailing comma
55+
echo "Publishing compass-web to $environments"
56+
echo "environments=[$environments]" >> "$GITHUB_OUTPUT"
57+
- id: define_commit_hash
58+
name: Resolve release hash
59+
env:
60+
COMPASS_WEB_RELEASE_COMMIT: '${{ inputs.dangerously_override_commit_hash }}'
61+
run: |
62+
# Use latest dev deploy as a default one for the release: this matches
63+
# our continuous deployment strategy
64+
commit_hash=${COMPASS_WEB_RELEASE_COMMIT:-"$(npm run --silent latest-release -w packages/compass-web dev)"}
65+
echo "commit_hash=\"$commit_hash\"" >> "$GITHUB_OUTPUT"
66+
3567
publish:
36-
name: Upload compass-web entrypoint file to assets bucket
68+
name: Upload compass-web entrypoint file to assets bucket in ${{ matrix.environment }}
3769
runs-on: ubuntu-latest
70+
needs: configure_deployments
71+
strategy:
72+
# By using matrix with max parallel we run the combinations in sequence
73+
# one after another. The fail fast option guarantees that deploy doesn't
74+
# proceed when a previous one failed
75+
max-parallel: 1
76+
fail-fast: true
77+
matrix:
78+
environment: ${{ fromJSON(needs.configure_deployments.outputs.environments) }}
3879
environment: compass-web
80+
outputs:
81+
environments: ${{ steps.check_if_deployed.outputs.already_deployed }}
3982
steps:
4083
- name: Checkout
4184
uses: actions/checkout@v4
@@ -64,28 +107,42 @@ jobs:
64107
run: |
65108
npm ci
66109
110+
- id: check_if_deployed
111+
name: Check current release version for ${{ matrix.environment }} env
112+
env:
113+
COMPASS_WEB_RELEASE_COMMIT: ${{ inputs.dangerously_override_commit_hash }}
114+
run: |
115+
current_release_commit_hash="$(npm run --silent latest-release -w packages/compass-web ${{ matrix.environment }})"
116+
if [[ $current_release_commit_hash == $COMPASS_WEB_RELEASE_COMMIT ]]; then
117+
echo "Release $COMPASS_WEB_RELEASE_COMMIT already published on ${{ matrix.environment }}"
118+
echo "already_deployed=true" >> "$GITHUB_OUTPUT"
119+
fi
120+
67121
- name: Test compass-web with Atlas Cloud
68-
if: ${{ !inputs.dangerously_skip_e2e_tests }}
122+
# TODO(CLOUDP-388180): can't run automated tests in staging, prod environments at the moment
123+
if: ${{ !steps.check_if_deployed.outputs.already_deployed && !inputs.dangerously_skip_e2e_tests && contains(fromJSON('["dev", "qa"]'), matrix.environment) }}
69124
env:
70125
EVG_USER: ${{ secrets.EVERGREEN_SERVICE_USER_USERNAME }}
71126
EVG_API_KEY: ${{ secrets.EVERGREEN_SERVICE_USER_API_KEY }}
72-
COMPASS_E2E_ATLAS_CLOUD_ENVIRONMENT: ${{ inputs.publish_environment }}
73-
COMPASS_WEB_E2E_TEST_EVERGREEN_PATCH_DESCRIPTION: 'Test compass-web against Atlas ${{ inputs.publish_environment }} env before release (GHA: https://github.com/mongodb-js/compass/actions/runs/${{ github.run_id }})'
74-
COMPASS_WEB_RELEASE_COMMIT: ${{ inputs.dangerously_override_commit_hash }}
127+
COMPASS_E2E_ATLAS_CLOUD_ENVIRONMENT: ${{ matrix.environment }}
128+
COMPASS_WEB_E2E_TEST_EVERGREEN_PATCH_DESCRIPTION: 'Test compass-web against Atlas ${{ matrix.environment }} env before release (GHA: https://github.com/mongodb-js/compass/actions/runs/${{ github.run_id }})'
129+
COMPASS_WEB_RELEASE_COMMIT: ${{ steps.define_commit_hash.outputs.commit_hash }}
75130
run: |
76131
npm run --workspace @mongodb-js/compass-web test-e2e-atlas
77132
78133
- name: Configure AWS Credentials
134+
if: ${{ !steps.check_if_deployed.outputs.already_deployed }}
79135
uses: aws-actions/configure-aws-credentials@56d6a583f00f6bad6d19d91d53a7bc3b8143d0e9 # v5.1.1
80136
with:
81137
role-to-assume: arn:aws:iam::119629040606:role/s3-access.cdn-origin-compass
82138
aws-region: us-east-1
83139

84140
- name: Upload updated entrypoint
141+
if: ${{ !steps.check_if_deployed.outputs.already_deployed }}
85142
env:
86143
COMPASS_WEB_PUBLISH_DRY_RUN: ${{ inputs.dry_run }}
87-
COMPASS_WEB_PUBLISH_ENVIRONMENT: ${{ inputs.publish_environment }}
88-
COMPASS_WEB_RELEASE_COMMIT: ${{ inputs.dangerously_override_commit_hash }}
144+
COMPASS_WEB_PUBLISH_ENVIRONMENT: ${{ matrix.environment }}
145+
COMPASS_WEB_RELEASE_COMMIT: ${{ steps.define_commit_hash.outputs.commit_hash }}
89146
# Set by "Configure AWS Credentials" step
90147
DOWNLOAD_CENTER_NEW_AWS_ACCESS_KEY_ID: '${{ env.AWS_ACCESS_KEY_ID }}'
91148
DOWNLOAD_CENTER_NEW_AWS_SECRET_ACCESS_KEY: '${{ env.AWS_SECRET_ACCESS_KEY }}'

packages/compass-web/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"reformat": "npm run eslint . -- --fix && npm run prettier -- --write .",
6666
"upload-dist": "node --experimental-strip-types scripts/release/upload-dist.mts",
6767
"upload-entrypoint": "node --experimental-strip-types scripts/release/upload-entrypoint.mts",
68-
"serve-dist": "node --experimental-strip-types scripts/dist-file-server.mts"
68+
"serve-dist": "node --experimental-strip-types scripts/dist-file-server.mts",
69+
"latest-release": "node --experimental-strip-types scripts/release/get-latest.mts"
6970
},
7071
"peerDependencies": {
7172
"react": "^17.0.2",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { parseArgs } from 'util';
2+
import {
3+
ALLOWED_PUBLISH_ENVIRONMENTS,
4+
DOWNLOADS_BUCKET_PUBLIC_HOST,
5+
} from './utils.mts';
6+
7+
const { positionals } = parseArgs({ allowPositionals: true });
8+
9+
const env = positionals[0] ?? 'dev';
10+
11+
if (!ALLOWED_PUBLISH_ENVIRONMENTS.includes(env)) {
12+
throw new Error(
13+
`Trying to resolve latest release for a non-existent environment: "${env}"`
14+
);
15+
}
16+
17+
const res = await fetch(
18+
new URL(`/compass/compass-web/${env}/index.mjs`, DOWNLOADS_BUCKET_PUBLIC_HOST)
19+
);
20+
const body = await res.text();
21+
const { groups } = /compass\/tree\/(?<commitHash>.+?)\b/.exec(body) ?? {};
22+
23+
if (!groups?.commitHash) {
24+
throw new Error(
25+
`Failed to resolve latest compass-web release for "${env}" environment`
26+
);
27+
}
28+
29+
process.stdout.write(groups.commitHash);

packages/compass-web/scripts/release/utils.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import S3 from 'aws-sdk/clients/s3.js';
1+
import type S3 from 'aws-sdk/clients/s3.js';
22
import child_process from 'child_process';
33
import path from 'path';
44
import { promisify } from 'util';
@@ -44,7 +44,8 @@ let s3Client;
4444

4545
export const asyncPutObject: (
4646
params: S3.Types.PutObjectRequest
47-
) => Promise<S3.Types.PutObjectOutput> = (params) => {
47+
) => Promise<S3.Types.PutObjectOutput> = async (params) => {
48+
const { default: S3 } = await import('aws-sdk/clients/s3.js');
4849
s3Client ??= new S3({
4950
credentials: getAWSCredentials(),
5051
});

0 commit comments

Comments
 (0)