-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cdn warming scripts and action (#153)
* Add cdn warming scripts and action * Prettify * Add secrets
- Loading branch information
Showing
3 changed files
with
100 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Warm CDN | ||
|
||
on: | ||
# Trigger it when the publish workflow succeeded | ||
workflow_run: | ||
workflows: ['Publish'] | ||
types: | ||
- completed | ||
# Trigger it every day | ||
schedule: | ||
- cron: '0 0 * * *' | ||
# Trigger it manually | ||
workflow_dispatch: | ||
|
||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install Node.js and npm | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 14.x | ||
registry-url: https://registry.npmjs.org | ||
|
||
- name: Retrieve dependencies from cache | ||
id: cacheNpm | ||
uses: actions/cache@v2 | ||
with: | ||
path: | | ||
~/.npm | ||
node_modules | ||
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }} | ||
restore-keys: npm-v14-${{ runner.os }}-refs/heads/master- | ||
|
||
- name: Install dependencies | ||
if: steps.cacheNpm.outputs.cache-hit != 'true' | ||
run: | | ||
npm update --no-save | ||
npm update --save-dev --no-save | ||
- name: Run the script | ||
env: | ||
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} | ||
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} | ||
run: npm run warmCDN |
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
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,48 @@ | ||
'use strict'; | ||
/** | ||
* Runs after publishing new version & every day regualrly | ||
* 1. Get latest version of binaries | ||
* 2. Warm them up | ||
*/ | ||
const tencentcloud = require('tencentcloud-sdk-nodejs'); | ||
const { version } = require('../../package.json'); | ||
|
||
console.log(`Going to warm up CDN for version ${version}`); | ||
|
||
const CdnClient = tencentcloud.cdn.v20180606.Client; | ||
|
||
const clientConfig = { | ||
credential: { | ||
secretId: process.env.TENCENT_SECRET_ID, | ||
secretKey: process.env.TENCENT_SECRET_KEY, | ||
}, | ||
region: '', | ||
profile: { | ||
httpProfile: { | ||
endpoint: 'cdn.tencentcloudapi.com', | ||
}, | ||
}, | ||
}; | ||
|
||
const client = new CdnClient(clientConfig); | ||
const params = { | ||
Urls: [ | ||
'https://slt-binary-sv-1300963013.file.myqcloud.com/latest-tag', | ||
`https://slt-binary-sv-1300963013.file.myqcloud.com/${version}/serverless-tencent-macos-x64`, | ||
`https://slt-binary-sv-1300963013.file.myqcloud.com/${version}/serverless-tencent-macos-armv6`, | ||
`https://slt-binary-sv-1300963013.file.myqcloud.com/${version}/serverless-tencent-linux`, | ||
`https://slt-binary-sv-1300963013.file.myqcloud.com/${version}/serverless-tencent-win-x64`, | ||
], | ||
}; | ||
|
||
// eslint-disable-next-line new-cap | ||
client.PushUrlsCache(params).then( | ||
(data) => { | ||
console.log(data); | ||
console.log(`${version} is warmed up successfully`); | ||
}, | ||
(err) => { | ||
console.error('error', err); | ||
throw err; | ||
} | ||
); |