Skip to content

Commit 9a459e9

Browse files
committed
Seperate .env per environment, docs
1 parent ef2875d commit 9a459e9

File tree

8 files changed

+97
-67
lines changed

8 files changed

+97
-67
lines changed

.env

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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
1+
# These variables are ovveridden in CI with GitHub Action variables if triggered from pull-reqest or push;
2+
# Locally, fallback to the current local git status
23
BRANCH="$(git branch --show-current)"
3-
BRANCH=${PULL_REQUEST_HEAD_REF:-${GITHUB_REF_NAME:-${BRANCH}}}
44
COMMIT_SHA="$(git rev-parse HEAD)"
5-
COMMIT_SHA=${PULL_REQUEST_HEAD_SHA:-${GITHUB_SHA:-${COMMIT_SHA}}}
65

76
# Read the CesiumJS version from package.json
87
CESIUM_VERSION=$(npm pkg get version | tr -d '"')
98

109
# Build artifact configuration
11-
BUILD_ARTIFACT_BUCKET="cesium-public-builds"
12-
BUILD_ARTIFACT_URL="https://ci-builds.cesium.com/cesium/${BRANCH}"
10+
BUILD_ARTIFACT_PATH="cesium/${BRANCH}"
11+
BUILD_ARTIFACT_BUCKET="s3://cesium-public-builds/${BUILD_ARTIFACT_PATH}"
12+
BUILD_ARTIFACT_URL="https://ci-builds.cesium.com/${BUILD_ARTIFACT_PATH}"
1313

1414
INDEX_URL="${BUILD_ARTIFACT_URL}/index.html"
1515
ZIP_URL="${BUILD_ARTIFACT_URL}/Cesium-${CESIUM_VERSION}.zip"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BRANCH="$(jq -r .pull_request.head.ref ${GITHUB_EVENT_PATH})"
2+
COMMIT_SHA="$(jq -r .pull_request.head.sha ${GITHUB_EVENT_PATH})"

.github/workflows/.env.push

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BRANCH=${GITHUB_REF_NAME}
2+
COMMIT_SHA=${GITHUB_SHA}

.github/workflows/coverage.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: coverage
2+
on:
3+
pull_request:
4+
concurrency:
5+
group: coverage-${{ github.ref }}
6+
cancel-in-progress: true
7+
jobs:
8+
coverage:
9+
runs-on: ubuntu-latest
10+
env:
11+
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
12+
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
13+
AWS_REGION: us-east-1
14+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15+
permissions:
16+
statuses: write
17+
contents: read
18+
steps:
19+
- uses: actions/checkout@v5
20+
- name: install node 22
21+
uses: actions/setup-node@v5
22+
with:
23+
node-version: "22"
24+
- name: npm install
25+
run: npm install
26+
- name: set status pending
27+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
28+
run: |
29+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.pull_request -- \
30+
node ./scripts/setCommitStatus.js coverage pending
31+
- name: build
32+
run: npm run build
33+
- name: coverage (firefox)
34+
run: npm run coverage -- --browsers FirefoxHeadless --webgl-stub --failTaskOnError --suppressPassed
35+
- name: upload coverage artifacts
36+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
37+
run: |
38+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.pull_request -f .env \
39+
-- sh -c \
40+
'aws s3 sync ./Build/Coverage $BUILD_ARTIFACT_BUCKET/Build/Coverage --delete'
41+
- name: set status success
42+
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
43+
run: |
44+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.pull_request -- \
45+
node ./scripts/setCommitStatus.js coverage ${{ job.status }}

.github/workflows/deploy.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: deploy
22
on:
33
push:
44
branches-ignore:
5-
- 'cesium.com'
5+
- "cesium.com"
66
- production
77
concurrency:
88
group: deploy-${{ github.ref }}
@@ -18,26 +18,27 @@ jobs:
1818
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
1919
AWS_REGION: us-east-1
2020
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21-
GITHUB_SHA: ${{ github.sha }}
2221
BASE_URL: /cesium/${{ github.ref_name }}/
2322
steps:
2423
- uses: actions/checkout@v5
2524
- name: install node 22
2625
uses: actions/setup-node@v5
2726
with:
28-
node-version: '22'
27+
node-version: "22"
2928
- name: npm install
3029
run: npm install
3130
- name: set version in package.json
3231
run: |
33-
npx @dotenvx/dotenvx run -- sh -c \
32+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.push \
33+
-- sh -c \
3434
'npm version prerelease --preid $BRANCH --ws --include-workspace-root --no-git-tag-version'
3535
- name: set status pending
3636
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
3737
run: |
38-
node ./scripts/setDeployStatus.js zip pending
39-
node ./scripts/setDeployStatus.js npm pending
40-
node ./scripts/setDeployStatus.js index pending
38+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.push -- \
39+
node ./scripts/setCommitStatus.js zip pending && \
40+
node ./scripts/setCommitStatus.js npm pending && \
41+
node ./scripts/setCommitStatus.js index pending
4142
- name: create release zip
4243
run: npm run make-zip
4344
- name: package cesium module
@@ -52,8 +53,9 @@ jobs:
5253
- name: deploy to s3
5354
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
5455
run: |
55-
npx @dotenvx/dotenvx run -- sh -c \
56-
'aws s3 sync . s3://$BUILD_ARTIFACT_BUCKET/cesium/$BRANCH/ \
56+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.push -f .env \
57+
-- sh -c \
58+
'aws s3 sync . $BUILD_ARTIFACT_BUCKET \
5759
--cache-control "no-cache" \
5860
--exclude ".git/*" \
5961
--exclude ".github/*" \
@@ -70,6 +72,7 @@ jobs:
7072
- name: set status success
7173
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
7274
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 }}
75+
npx @dotenvx/dotenvx run -f ./.github/workflows/.env.push -- \
76+
node ./scripts/setCommitStatus.js zip ${{ job.status }} && \
77+
node ./scripts/setCommitStatus.js npm ${{ job.status }} && \
78+
node ./scripts/setCommitStatus.js index ${{ job.status }}

.github/workflows/dev.yml

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: install node 22
1616
uses: actions/setup-node@v5
1717
with:
18-
node-version: '22'
18+
node-version: "22"
1919
- name: npm install
2020
run: npm install
2121
- name: lint *.js
@@ -24,47 +24,14 @@ jobs:
2424
run: npm run markdownlint
2525
- name: format code
2626
run: npm run prettier-check
27-
coverage:
28-
runs-on: ubuntu-latest
29-
env:
30-
AWS_ACCESS_KEY_ID: ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
31-
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
32-
AWS_REGION: us-east-1
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
39-
steps:
40-
- uses: actions/checkout@v5
41-
- name: install node 22
42-
uses: actions/setup-node@v5
43-
with:
44-
node-version: '22'
45-
- name: npm install
46-
run: npm install
47-
- name: set status pending
48-
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
49-
run: node ./scripts/setDeployStatus.js coverage pending
50-
- name: build
51-
run: npm run build
52-
- name: coverage (firefox)
53-
run: npm run coverage -- --browsers FirefoxHeadless --webgl-stub --failTaskOnError --suppressPassed
54-
- name: upload coverage artifacts
55-
if: ${{ env.AWS_ACCESS_KEY_ID != '' }}
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 }}
6027
release-tests:
6128
runs-on: ubuntu-latest
6229
steps:
6330
- uses: actions/checkout@v5
6431
- name: install node 22
6532
uses: actions/setup-node@v5
6633
with:
67-
node-version: '22'
34+
node-version: "22"
6835
- name: npm install
6936
run: npm install
7037
- name: release build
@@ -80,7 +47,7 @@ jobs:
8047
- name: install node 20
8148
uses: actions/setup-node@v5
8249
with:
83-
node-version: '20'
50+
node-version: "20"
8451
- name: npm install
8552
run: npm install
8653
- name: release build

Documentation/Contributors/ContinuousIntegration/README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
- [Background](#background)
44
- [Actions and workflows](#actions-and-workflows)
5+
- [Environment variables](#environment-variables)
56
- [Continuous deployment](#continuous-deployment)
6-
- [Configuration](#configuration)
7+
- [Configuration guide](#configuration-guide)
78
- [Configure a different S3 bucket](#configure-a-different-s3-bucket)
89
- [Configure S3 credentials](#configure-s3-credentials)
910

@@ -28,6 +29,16 @@ The status checks for any branch are also accessible under the [Branches](https:
2829

2930
![GitHub Branches](github_branches.png)
3031

32+
### Environment variables
33+
34+
Any non-secret environment variables for CI and CD are managed using `.env` files and [dotenvx](https://github.com/dotenvx/dotenvx).
35+
36+
- **Local dev**: `.env` is checked in at the repository root and provides defaults constant values and local fallbacks.
37+
- To run a script or command with these variables configured locally, use `npx @dotenvx/dotenvx run -- <COMMAND>`, e.g., `npx @dotenvx/dotenvx run -- node ./scripts/setCommitStatus.js`.
38+
- To expand a variable directly in a command, use a subshell command, e.g., `npx @dotenvx/dotenvx run -- sh -c 'echo "${BRANCH}"'`.
39+
- **GitHub Actions workflow - `push` trigger**: `.github/workflows/.env.push`
40+
- **GitHub Actions workflow - `pull_request` trigger**: `.github/workflows/.env.pull_request`
41+
3142
## Continuous deployment
3243

3344
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.
@@ -42,7 +53,7 @@ Each of the following are deployed on a per-branch basis.
4253
| 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)) |
4354
| 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)) |
4455

45-
## Configuration
56+
## Configuration guide
4657

4758
Additional set up is required for deployment _only_ if you do not have commit access to CesiumJS.
4859

scripts/setDeployStatus.js renamed to scripts/setCommitStatus.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const GITHUB_WORKFLOW = process.env.GITHUB_WORKFLOW;
88
const COMMIT_SHA = process.env.COMMIT_SHA;
99
const CESIUM_VERSION = process.env.CESIUM_VERSION;
1010

11-
export async function setDeployStatus({ status, url, context, message }) {
11+
export async function setCommitStatus({ status, url, context, message }) {
1212
if (!GITHUB_TOKEN || GITHUB_TOKEN === "") {
1313
throw new Error(`Environment variable is not defined: "GITHUB_TOKEN"`);
1414
}
@@ -63,7 +63,7 @@ const getArtifactContext = (artifact) => {
6363
await yargs()
6464
.command(
6565
"* <status> [context] [url] [message]",
66-
"set deploy status of a build artifact",
66+
"set commit status, for example, to link to a build artifact",
6767
(yargs) =>
6868
yargs
6969
.positional("status", {
@@ -81,49 +81,49 @@ await yargs()
8181
})
8282
.positional("message", {
8383
type: "string",
84-
describe: "A short description of the status.",
84+
describe: "A short description of this status.",
8585
}),
86-
setDeployStatus,
86+
setCommitStatus,
8787
)
8888
.command(
8989
"coverage <status>",
90-
"set deploy status of a build artifact",
90+
"set deployment status of coverage results",
9191
() => {},
9292
async ({ status }) =>
93-
setDeployStatus({
93+
setCommitStatus({
9494
status,
9595
url: process.env.COVERAGE_URL,
9696
context: getArtifactContext("coverage report"),
9797
}),
9898
)
9999
.command(
100100
"zip <status>",
101-
"set deploy status of the zip file",
101+
"set deployment status of the release zip file",
102102
() => {},
103103
async ({ status }) =>
104-
setDeployStatus({
104+
setCommitStatus({
105105
status,
106106
url: process.env.ZIP_URL,
107107
context: getArtifactContext(`Cesium-${CESIUM_VERSION}.zip`),
108108
}),
109109
)
110110
.command(
111111
"npm <status>",
112-
"set deploy status of the npm package",
112+
"set deployment status of the npm package",
113113
() => {},
114114
async ({ status }) =>
115-
setDeployStatus({
115+
setCommitStatus({
116116
status,
117117
url: process.env.NPM_URL,
118118
context: getArtifactContext(`cesium-${CESIUM_VERSION}.tgz`),
119119
}),
120120
)
121121
.command(
122122
"index <status>",
123-
"set deploy status of the static build",
123+
"set deployment status of the static build",
124124
() => {},
125125
async ({ status }) =>
126-
setDeployStatus({
126+
setCommitStatus({
127127
status,
128128
url: process.env.INDEX_URL,
129129
context: getArtifactContext("index.html"),

0 commit comments

Comments
 (0)