Skip to content

Commit f048ef0

Browse files
build(cloudbuild): migrate deploy to cloud build (GoogleChrome#6082)
* build(cloudbuild): migrate deploy to cloud build * docs(README): update `Manual deploys` section * chore: update readme and deploy script based on minor issues * docs(README): add note about auto deploys * build(deploy): updgrade machine type
1 parent a92eb30 commit f048ef0

File tree

7 files changed

+162
-80
lines changed

7 files changed

+162
-80
lines changed

.cloudbuild/deploy.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
timeout: 2700s # set build timeout to 45 mins
2+
steps:
3+
- name: node:14
4+
id: 'Install dependencies'
5+
entrypoint: npm
6+
args: ['ci']
7+
8+
- name: node:14
9+
id: 'Generate .env file'
10+
entrypoint: npm
11+
args: ['run', 'cloud-secrets']
12+
env:
13+
- 'PROJECT_ID=$PROJECT_ID'
14+
15+
- name: node:14
16+
id: 'Verify new version'
17+
entrypoint: npm
18+
args: ['run', 'version-check']
19+
env:
20+
- 'BUILD_ID=$BUILD_ID'
21+
- 'PROJECT_ID=$PROJECT_ID'
22+
- 'NODE_ENV=production'
23+
24+
- name: node:14
25+
id: 'Build site'
26+
entrypoint: npm
27+
args: ['run', 'build']
28+
env:
29+
- 'ELEVENTY_ENV=prod'
30+
31+
- name: 'gcr.io/$PROJECT_ID/firebase'
32+
id: 'Deploy site to Firebase'
33+
args: ['deploy']
34+
35+
- name: node:14
36+
id: 'Algolia index site'
37+
entrypoint: npm
38+
args: ['run', 'algolia']
39+
40+
options:
41+
machineType: 'E2_HIGHCPU_8'

.github/workflows/firebase-hosting-cron.yml

-43
This file was deleted.

.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ typings/
6969
# build artifacts
7070
dist
7171

72-
# deploy scripts
73-
devsite.js
74-
local-devsite.js
75-
7672
# DS_Store
7773
.DS_Store
7874

README.md

+7-10
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,16 @@ of the next hour.
8787

8888
### Manual deploys
8989

90-
To manually deploy the site you'll need to be a member of one of these GitHub
91-
teams:
90+
To manually deploy the site you'll need to be a member of one of these Google teams:
9291

93-
- @GoogleChrome/web-dev-admins
94-
- @GoogleChrome/web-dev-content
95-
- @GoogleChrome/web-dev-contributors
96-
- @GoogleChrome/web-dev-eng
97-
- @GoogleChrome/web-devrel
92+
- web.dev-eng
93+
- web.dev-owners
9894

99-
1. Navigate to [the Deploy workflow in the Actions panel](https://github.com/GoogleChrome/web.dev/actions?query=workflow%3ADeploy).
100-
2. Click the **Run workflow** button. Make sure the branch says `main`, then click the green **Run workflow** button.
95+
1. Navigate to [the Cloud Build Triggers page](https://console.cloud.google.com/cloud-build/triggers?project=web-dev-production-1).
96+
2. Click the **RUN** button for the trigger named **Deploy**.
97+
3. In the side drawer that opens up, click the **RUN TRIGGER** button for the trigger for the **main** branch.
10198

102-
![An expanded workflow popup with a green run workflow button inside of it.](https://user-images.githubusercontent.com/1066253/89584965-da6eb500-d7f1-11ea-8a43-d8b1abe2cd3b.png)
99+
*NOTE: web.dev auto deploys every hour if there is a new commit in the `main` branch. Manual deploys should only occur when a build fails or if auto deploys are disabled.*
103100

104101
## Debugging 🐛
105102

package-lock.json

+97-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@
7878
"@11ty/eleventy-cache-assets": "^2.3.0",
7979
"@11ty/eleventy-plugin-rss": "^1.0.7",
8080
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.1",
81-
"@actions/core": "^1.3.0",
82-
"@google-cloud/secret-manager": "^3.2.3",
81+
"@google-cloud/cloudbuild": "^2.6.0",
82+
"@google-cloud/error-reporting": "^2.0.3",
83+
"@google-cloud/secret-manager": "^3.10.0",
8384
"@mdn/browser-compat-data": "^3.3.14",
8485
"@percy/script": "^1.1.0",
8586
"@rollup/plugin-commonjs": "^17.1.0",

version-check.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
*/
66

77
const fetch = require('node-fetch');
8-
const core = require('@actions/core');
8+
const {ErrorReporting} = require('@google-cloud/error-reporting');
9+
const {execSync} = require('child_process');
10+
const {CloudBuildClient} = require('@google-cloud/cloudbuild');
911

12+
const client = new CloudBuildClient();
13+
const errors = new ErrorReporting();
1014
const ERROR_MESSAGE = 'NOT FOUND';
1115

1216
/**
@@ -21,19 +25,26 @@ const getDeployedVersion = () => {
2125

2226
(async () => {
2327
const deployedVersion = await getDeployedVersion();
24-
const currentVersion = process.env.GITHUB_SHA;
28+
const currentVersion = execSync('git rev-parse HEAD').toString().trim();
2529

2630
console.log(`Current version: ${currentVersion}`);
2731
console.log(`Deployed version: ${deployedVersion}`);
2832

33+
if (deployedVersion === ERROR_MESSAGE) {
34+
errors.report('Deployed commit SHA not found');
35+
}
36+
2937
if (deployedVersion === currentVersion) {
3038
console.log(
3139
'The current and deployed versions are the same, stopping build.',
3240
);
41+
await client.cancelBuild({
42+
id: process.env.BUILD_ID,
43+
projectId: process.env.PROJECT_ID,
44+
});
3345
} else {
3446
console.log(
3547
'The current and deployed versions are different, continuing build.',
3648
);
3749
}
38-
core.setOutput('isDifferent', deployedVersion !== currentVersion);
3950
})();

0 commit comments

Comments
 (0)