Skip to content

Commit d771cf0

Browse files
committed
Centralize env vars in env; Refactor deployment checks
1 parent cb1a73a commit d771cf0

File tree

10 files changed

+194
-115
lines changed

10 files changed

+194
-115
lines changed

.env

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Get the current git values from GitHub Action variables if triggered from pull-reqest or push; otherwise fallback to the current local git branch
2+
BRANCH="$(git branch --show-current)"
3+
BRANCH=${PULL_REQUEST_HEAD_REF:-${GITHUB_REF_NAME:-${BRANCH}}}
4+
COMMIT_SHA="$(git rev-parse HEAD)"
5+
COMMIT_SHA=${PULL_REQUEST_HEAD_SHA:-${GITHUB_SHA:-${COMMIT_SHA}}}
6+
7+
# Read the Cesium version from package.json
8+
CESIUM_VERSION=$(npm pkg get version | tr -d '"')
9+
10+
# Build artifact configuration
11+
BUILD_ARTIFACT_BUCKET="cesium-public-builds"
12+
BUILD_ARTIFACT_URL="https://ci-builds.cesium.com/cesium/${BRANCH}"
13+
14+
INDEX_URL="${BUILD_ARTIFACT_URL}/index.html"
15+
ZIP_URL="${BUILD_ARTIFACT_URL}/Cesium-${CESIUM_VERSION}.zip"
16+
NPM_URL="${BUILD_ARTIFACT_URL}/cesium-${CESIUM_VERSION}.tgz"
17+
COVERAGE_URL="${BUILD_ARTIFACT_URL}/Build/Coverage/index.html"

.github/workflows/deploy.yml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ jobs:
1414
statuses: write
1515
contents: read
1616
env:
17-
BUILD_VERSION: ${{ github.ref_name }}.${{ github.run_number }}
1817
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
1918
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
2019
AWS_REGION: us-east-1
21-
BRANCH: ${{ github.ref_name }}
2220
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23-
GITHUB_REPO: ${{ github.repository }}
2421
GITHUB_SHA: ${{ github.sha }}
2522
BASE_URL: /cesium/${{ github.ref_name }}/
26-
DEPLOYED_URL: https://ci-builds.cesium.com/cesium/${{ github.ref_name }}/
2723
steps:
2824
- uses: actions/checkout@v5
2925
- name: install node 22
@@ -32,8 +28,16 @@ jobs:
3228
node-version: '22'
3329
- name: npm install
3430
run: npm install
35-
- name: set the version in package.json
36-
run: npm run deploy-set-version -- --buildVersion $BUILD_VERSION
31+
- name: set version in package.json
32+
run: |
33+
npx @dotenvx/dotenvx run -- sh -c \
34+
'npm version prerelease --preid $BRANCH --ws --include-workspace-root --no-git-tag-version'
35+
- name: set status pending
36+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
37+
run: |
38+
node ./scripts/setDeployStatus.js zip pending
39+
node ./scripts/setDeployStatus.js npm pending
40+
node ./scripts/setDeployStatus.js index pending
3741
- name: create release zip
3842
run: npm run make-zip
3943
- name: package cesium module
@@ -48,7 +52,8 @@ jobs:
4852
- name: deploy to s3
4953
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
5054
run: |
51-
aws s3 sync . s3://cesium-public-builds/cesium/$BRANCH/ \
55+
npx @dotenvx/dotenvx run -- sh -c \
56+
'aws s3 sync . s3://$BUILD_ARTIFACT_BUCKET/cesium/$BRANCH/ \
5257
--cache-control "no-cache" \
5358
--exclude ".git/*" \
5459
--exclude ".github/*" \
@@ -61,7 +66,10 @@ jobs:
6166
--exclude "node_modules/*" \
6267
--exclude "scripts/*" \
6368
--exclude "Tools/*" \
64-
--delete
65-
- name: set status
69+
--delete'
70+
- name: set status success
6671
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
67-
run: npm run deploy-status -- --status success --message Deployed
72+
run: |
73+
node ./scripts/setDeployStatus.js zip ${{ job.status }}
74+
node ./scripts/setDeployStatus.js npm ${{ job.status }}
75+
node ./scripts/setDeployStatus.js index ${{ job.status }}

.github/workflows/dev.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ jobs:
3030
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
3131
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
3232
AWS_REGION: us-east-1
33-
BRANCH: ${{ github.ref_name }}
34-
DEPLOYED_URL: https://ci-builds.cesium.com/cesium/${{ github.ref_name }}/
33+
PULL_REQUEST_HEAD_SHA: ${{ github.event.pull_request && github.event.pull_request.head.sha || '' }}
34+
PULL_REQUEST_HEAD_REF: ${{ github.event.pull_request && github.event.pull_request.head.ref || '' }}
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
permissions:
37+
statuses: write
38+
contents: read
3539
steps:
3640
- uses: actions/checkout@v5
3741
- name: install node 22
@@ -40,13 +44,19 @@ jobs:
4044
node-version: '22'
4145
- name: npm install
4246
run: npm install
47+
- name: set status pending
48+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
49+
run: node ./scripts/setDeployStatus.js coverage pending
4350
- name: build
4451
run: npm run build
4552
- name: coverage (firefox)
4653
run: npm run coverage -- --browsers FirefoxHeadless --webgl-stub --failTaskOnError --suppressPassed
4754
- name: upload coverage artifacts
4855
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
49-
run: aws s3 sync ./Build/Coverage s3://cesium-public-builds/cesium/$BRANCH/Build/Coverage --delete --color on
56+
run: npx @dotenvx/dotenvx run -- sh -c 'aws s3 sync ./Build/Coverage s3://$BUILD_ARTIFACT_BUCKET/cesium/$BRANCH/Build/Coverage --delete --color on'
57+
- name: set status success
58+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
59+
run: node ./scripts/setDeployStatus.js coverage ${{ job.status }}
5060
release-tests:
5161
runs-on: ubuntu-latest
5262
steps:

.github/workflows/prod.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
AWS_REGION: us-east-1
3030
BRANCH: ${{ github.ref_name }}
3131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
GITHUB_REPO: ${{ github.repository }}
3332
GITHUB_SHA: ${{ github.sha }}
3433
steps:
3534
- uses: actions/checkout@v5

.github/workflows/sandcastle-dev.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
AWS_REGION: us-east-1
1414
BRANCH: ${{ github.ref_name }}
1515
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16-
GITHUB_REPO: ${{ github.repository }}
1716
GITHUB_SHA: ${{ github.sha }}
1817
steps:
1918
- uses: actions/checkout@v5

Documentation/Contributors/BuildGuide/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,3 @@ Here's the full set of scripts and what they do.
153153
- `test-webgl-stub` - Runs all tests using the WebGL stub, which WebGL calls a noop and ignores related test expectations
154154
- `test-webgl-validation` - Runs all tests with Karma and enables low-level WebGL validation
155155
- `test-release` - Runs all tests on the minified release version of built Cesium
156-
- **Deployment scripts**
157-
- `deploy-status` - Sets the deployment statuses in GitHub, for use in CI
158-
- `deploy-set-version` - Sets the version of `package.json`, for use in CI

Documentation/Contributors/ContinuousIntegration/README.md

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,42 @@ CesiumJS uses [GitHub Actions](https://docs.github.com/en/actions) for continuou
1818

1919
Reusable actions are defined in `/.github/actions/` and workflows in `.github/workflows/`.
2020

21-
A workflow is triggered whenever someone pushes code to the CesiumJS repository, or an external contributor opens a pull request. After the build has completed, at the bottom of the pull request page the status of the build is shown. In the dropdown menu, individual checks are displayed. Logs and deployed artifacts can be accessed by clicking the "Details" link.
21+
Workflows are triggered when a commit is pushed to the `cesium` repository and when a contributor opens or updates a pull request. After the build has completed, the overall status of the build is shown at the bottom of the pull request page.
22+
23+
In the dropdown menu, individual status checks are displayed. Logs and deployed build artifacts can be accessed by clicking the link associated with the individual check.
2224

2325
![GitHub Action Checks](github_action_checks.png)
2426

25-
The workflow checks for any CesiumJS branch are accessible under the [Branches](https://github.com/CesiumGS/cesium/branches/all) page by clicking the icon next to the branch name.
27+
The status checks for any branch are also accessible under the [Branches](https://github.com/CesiumGS/cesium/branches/all) page by clicking the icon next to the branch name.
2628

2729
![GitHub Branches](github_branches.png)
2830

2931
## Continuous deployment
3032

31-
Automated deployments make recent code changes available for testing and review without needing to fetch and build locally. We deploy each of the following on a per-branch basis.
33+
Automated deployments make recent code changes available for convenient testing and review—No need to fetch or build locally. In the `cesium` repository, all continuous deployment artifacts are uploaded for commits authored by users with commit access.
34+
35+
Each of the following are deployed on a per-branch basis.
3236

33-
| Artifact | Link (`main` branch) |
34-
| ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
35-
| Sandcastle | [`https://ci-builds.cesium.com/cesium/main/Apps/Sandcastle/index.html`](https://ci-builds.cesium.com/cesium/main/Apps/Sandcastle/index.html) |
36-
| Documentation | [`https://ci-builds.cesium.com/cesium/main/Build/Documentation/index.html`](https://ci-builds.cesium.com/cesium/main/Build/Documentation/index.html) |
37-
| Coverage results | [`https://ci-builds.cesium.com/cesium/main/Build/Coverage/index.html`](https://ci-builds.cesium.com/cesium/main/Build/Coverage/index.html) |
38-
| Release zip | [`https://ci-builds.cesium.com/cesium/main/<github-ref-name>.<github-run-number>.zip`](https://ci-builds.cesium.com/cesium/main/<github-ref-name>.<github-run-number>.zip) |
39-
| npm package | [`https://ci-builds.cesium.com/cesium/main/<github-ref-name>.<github-run-number>.tgz`](https://ci-builds.cesium.com/cesium/main/<github-ref-name>.<github-run-number>.tgz) |
37+
| Artifact | Link pattern (`main`) |
38+
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
39+
| Sandcastle | `https://ci-builds.cesium.com/cesium/<BRANCH>/Apps/Sandcastle/index.html` (i.e., [`https://ci-builds.cesium.com/cesium/main/Apps/Sandcastle/index.html`](https://ci-builds.cesium.com/cesium/main/Apps/Sandcastle/index.html)) |
40+
| Documentation | `https://ci-builds.cesium.com/cesium/<BRANCH>/Build/Documentation/index.html` (i.e., [`https://ci-builds.cesium.com/cesium/main/Build/Documentation/index.html`](https://ci-builds.cesium.com/cesium/main/Build/Documentation/index.html)) |
41+
| Coverage results | `https://ci-builds.cesium.com/cesium/<BRANCH>/Build/Coverage/index.html` (i.e., [`https://ci-builds.cesium.com/cesium/main/Build/Coverage/index.html`](https://ci-builds.cesium.com/cesium/main/Build/Coverage/index.html)) |
42+
| Release zip | `https://ci-builds.cesium.com/cesium/<BRANCH>/Cesium-<VERSION>-<BRANCH>.0.zip` (i.e., [`https://ci-builds.cesium.com/cesium/main/Cesium-1.X.X-main.0.zip`](https://ci-builds.cesium.com/cesium/main/Cesium-1.X.X-main.0.zip)) |
43+
| npm package | `https://ci-builds.cesium.com/cesium/<BRANCH>/cesium-<VERSION>-<BRANCH>.0.tgz` (i.e., [`https://ci-builds.cesium.com/cesium/main/cesium-1.X.X-main.0.tgz`](https://ci-builds.cesium.com/cesium/main/cesium-1.X.X-main.0.tgz)) |
4044

4145
## Configuration
4246

43-
Additional set up is required for deployment if you do not have commit access to CesiumJS.
47+
Additional set up is required for deployment _only_ if you do not have commit access to CesiumJS.
4448

4549
### Configure a different S3 bucket
4650

47-
It is possible to configure your development branch of CesiumJS to deploy build artifacts to a different [AWS S3 Bucket](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html). If you are using the cesium-public-builds bucket and have valid credentials, skip to [Configure S3 Credentials](#configure-s3-credentials)
48-
49-
- In `.gtihub/workflows/dev.yml`, in the following lines, replace "cesium-public-builds" with the name of your S3 bucket.
50-
51-
```sh
52-
aws s3 sync ./Build/Coverage s3://cesium-public-builds/cesium/$BRANCH/Build/Coverage --delete --color on
53-
```
54-
55-
```sh
56-
aws s3 sync Build/unzipped/ s3://cesium-public-builds/cesium/$BRANCH/Build/ --cache-control "no-cache" --delete
57-
```
58-
59-
- In `gulpfile.js`, edit the following line:
51+
It is possible to configure your development branch of CesiumJS to deploy build artifacts to a different [AWS S3 Bucket](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html). If you are using the default "cesium-public-builds" bucket and have valid credentials, skip to [Configure S3 Credentials](#configure-s3-credentials)
6052

61-
```javascript
62-
const devDeployUrl = "https://ci-builds.cesium.com/cesium/";
63-
```
53+
In the environment file `.env`, update the following values:
6454

65-
- Edit the URL to match the URL hosting the S3 bucket specified in the previous step.
55+
- Replace the value of `BUILD_ARTIFACT_BUCKET` with the name of the target S3 bucket.
56+
- Replace the value of `BUILD_ARTIFACT_URL` with the public URL correspondeding to the target S3 bucket.
6657

6758
### Configure S3 credentials
6859

gulpfile.js

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { writeFileSync, copyFileSync, readFileSync, existsSync } from "fs";
22
import { readFile, writeFile } from "fs/promises";
33
import { join, basename, resolve, dirname } from "path";
44
import { exec, execSync } from "child_process";
5-
import fetch from "node-fetch";
65
import { createRequire } from "module";
76
import { finished } from "stream/promises";
87

@@ -39,7 +38,8 @@ const scope = "cesium";
3938
const require = createRequire(import.meta.url);
4039
const packageJson = require("./package.json");
4140
let version = packageJson.version;
42-
if (/\.0$/.test(version)) {
41+
if (/\.\d+\.0$/.test(version)) {
42+
// Removes the patch release ".0" at the end of any non-prelease version
4343
version = version.substring(0, version.length - 2);
4444
}
4545
const karmaConfigFile = resolve("./Specs/karma.conf.cjs");
@@ -54,7 +54,6 @@ function getWorkspaces(onlyDependencies = false) {
5454
: packageJson.workspaces;
5555
}
5656

57-
const devDeployUrl = process.env.DEPLOYED_URL;
5857
const isProduction = process.env.PROD;
5958

6059
//Gulp doesn't seem to have a way to get the currently running tasks for setting
@@ -554,8 +553,6 @@ async function pruneScriptsForZip(packageJsonPath) {
554553
delete scripts.prettier;
555554

556555
// Remove deploy tasks
557-
delete scripts["deploy-status"];
558-
delete scripts["deploy-set-version"];
559556
delete scripts["website-release"];
560557

561558
// Set server tasks to use production flag
@@ -698,66 +695,6 @@ export const makeZip = gulp.series(release, async function createZipFile() {
698695
return src;
699696
});
700697

701-
export async function deploySetVersion() {
702-
const buildVersion = argv.buildVersion;
703-
if (buildVersion) {
704-
// NPM versions can only contain alphanumeric and hyphen characters
705-
packageJson.version += `-${buildVersion.replace(/[^[0-9A-Za-z-]/g, "")}`;
706-
return writeFile("package.json", JSON.stringify(packageJson, undefined, 2));
707-
}
708-
}
709-
710-
export async function deployStatus() {
711-
const status = argv.status;
712-
const message = argv.message;
713-
const deployUrl = `${devDeployUrl}`;
714-
const zipUrl = `${deployUrl}Cesium-${version}.zip`;
715-
const npmUrl = `${deployUrl}cesium-${version}.tgz`;
716-
const coverageUrl = `${deployUrl}Build/Coverage/index.html`;
717-
718-
return Promise.all([
719-
setStatus(status, deployUrl, message, "deploy / artifact: deployment"),
720-
setStatus(status, zipUrl, message, "deploy / artifact: zip file"),
721-
setStatus(status, npmUrl, message, "deploy / artifact: npm package"),
722-
setStatus(
723-
status,
724-
coverageUrl,
725-
message,
726-
"deploy / artifact: coverage results",
727-
),
728-
]);
729-
}
730-
731-
async function setStatus(state, targetUrl, description, context) {
732-
// skip if the environment does not have the token
733-
if (!process.env.GITHUB_TOKEN) {
734-
return;
735-
}
736-
737-
const body = {
738-
state: state,
739-
target_url: targetUrl,
740-
description: description,
741-
context: context,
742-
};
743-
744-
const response = await fetch(
745-
`https://api.github.com/repos/${process.env.GITHUB_REPO}/statuses/${process.env.GITHUB_SHA}`,
746-
{
747-
method: "post",
748-
body: JSON.stringify(body),
749-
headers: {
750-
"Content-Type": "application/json",
751-
Authorization: `token ${process.env.GITHUB_TOKEN}`,
752-
"User-Agent": "Cesium",
753-
},
754-
},
755-
);
756-
757-
const result = await response.json();
758-
return result;
759-
}
760-
761698
/**
762699
* Generates coverage report.
763700
*

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
],
2424
"repository": {
2525
"type": "git",
26-
"url": "https://github.com/CesiumGS/cesium.git"
26+
"url": "git+https://github.com/CesiumGS/cesium.git"
2727
},
2828
"bugs": {
2929
"url": "https://github.com/CesiumGS/cesium/issues"
@@ -56,6 +56,7 @@
5656
},
5757
"devDependencies": {
5858
"@cesium/eslint-config": "^12.0.0",
59+
"@dotenvx/dotenvx": "^1.51.0",
5960
"@playwright/test": "^1.41.1",
6061
"chokidar": "^4.0.1",
6162
"cloc": "^2.6.0-cloc",
@@ -95,7 +96,6 @@
9596
"markdownlint-cli": "^0.45.0",
9697
"merge-stream": "^2.0.0",
9798
"mkdirp": "^3.0.1",
98-
"node-fetch": "^3.2.10",
9999
"open": "^10.0.2",
100100
"prettier": "3.6.2",
101101
"prismjs": "^1.28.0",
@@ -139,8 +139,6 @@
139139
"test-e2e-release-all": "release=true playwright test -c Specs/e2e/playwright.config.js",
140140
"test-e2e-report": "playwright show-report Build/Specs/e2e/report",
141141
"test-e2e-update": "playwright test -c Specs/e2e/playwright.config.js --project=chromium -u",
142-
"deploy-status": "gulp deployStatus",
143-
"deploy-set-version": "gulp deploySetVersion",
144142
"prettier": "prettier --write \"**/*\"",
145143
"prettier-check": "prettier --check \"**/*\"",
146144
"cspell": "npx cspell lint -c .vscode/cspell.json --unique --no-progress"

0 commit comments

Comments
 (0)