This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(git): only deploy site if it's a new commit, fixes #3655
- Loading branch information
1 parent
9a01c36
commit a018f5c
Showing
6 changed files
with
32,343 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
timeout: 2700s # set build timeout to 45 mins | ||
steps: | ||
- name: node | ||
id: 'Install dependencies' | ||
entrypoint: npm | ||
args: ['ci'] | ||
- name: node | ||
id: 'Generate .env file' | ||
entrypoint: npm | ||
args: ['run', 'cloud-secrets'] | ||
env: | ||
- 'PROJECT_ID=$PROJECT_ID' | ||
- name: 'node' | ||
id: 'Verify new commit' | ||
entrypoint: npm | ||
args: ['run', 'HEAD'] | ||
env: | ||
- 'BUILD_ID=$BUILD_ID' | ||
- name: node | ||
id: 'Build site' | ||
entrypoint: npm | ||
args: ['run', 'build'] | ||
env: | ||
- 'ELEVENTY_ENV=prod' | ||
- name: node | ||
id: 'Configure firebase.json' | ||
entrypoint: npm | ||
args: ['run', 'firebase-config'] | ||
- name: 'gcr.io/$PROJECT_ID/firebase' | ||
id: 'Deploy site to Firebase' | ||
args: ['deploy'] | ||
- name: node | ||
id: 'Algolia index site' | ||
entrypoint: npm | ||
args: ['run', 'algolia'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const request = require('request'); | ||
const {execSync} = require('child_process'); | ||
const {CloudBuildClient} = require('@google-cloud/cloudbuild'); | ||
|
||
const client = new CloudBuildClient(); | ||
|
||
/** | ||
* @returns {Promise<string>} | ||
*/ | ||
const getDeployedHead = () => { | ||
return new Promise((resolve) => | ||
request('https://web.dev/HEAD', (e, r) => { | ||
resolve(r.statusCode >= 400 || e ? '' : r.body); | ||
}), | ||
); | ||
}; | ||
|
||
(async () => { | ||
const deployedHEAD = await getDeployedHead(); | ||
const currentHEAD = execSync('git rev-parse HEAD').toString().trim(); | ||
|
||
console.log(`Current HEAD: ${currentHEAD}`); | ||
console.log(`Deployed HEAD: ${deployedHEAD}`); | ||
|
||
if (currentHEAD === currentHEAD) { | ||
console.log('The current and deployed HEADs are the same, stopping build.'); | ||
const BUILD_ID = process.env.BUILD_ID; | ||
client.cancelBuild({ | ||
id: BUILD_ID, | ||
}); | ||
} else { | ||
console.log( | ||
'The current and deployed HEADs are different, continuing build.', | ||
); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const {execSync} = require('child_process'); | ||
|
||
const isProd = process.env.ELEVENTY_ENV === 'prod'; | ||
|
||
/** | ||
* Write the HEAD SHA to the `dist` on prod builds. | ||
* | ||
* @returns {Promise<void>} | ||
*/ | ||
const writeHEAD = async () => { | ||
if (isProd) { | ||
const HEAD = execSync('git rev-parse HEAD').toString().trim(); | ||
require('fs').writeFileSync('./dist/HEAD', HEAD); | ||
} | ||
}; | ||
|
||
module.exports = writeHEAD; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.