[MANIFEST] Set up a workflow to test clearing cache on the notify website post a deploy #26
Workflow file for this run
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
name: Call Notification clear cache API | |
# on: | |
# workflow_call: | |
# secrets: | |
# CACHE_CLEAR_USER_NAME: | |
# required: true | |
# CACHE_CLEAR_CLIENT_SECRET: | |
# required: true | |
# API_KEY: | |
# required: true | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
inputs: | |
reason: | |
description: "Reason for manual trigger" | |
required: true | |
default: "Testing" | |
jobs: | |
call-api: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: "14" | |
- name: Install dependencies | |
run: | | |
npm install jsonwebtoken axios | |
- name: Install dependencies and call API | |
env: | |
CACHE_CLEAR_USER_NAME: ${{ secrets.STAGING_CACHE_CLEAR_USER_NAME }} | |
CACHE_CLEAR_CLIENT_SECRET: ${{ secrets.STAGING_CACHE_CLEAR_CLIENT_SECRET }} | |
run: | | |
node -e " | |
const jwt = require('jsonwebtoken'); | |
const axios = require('axios'); | |
console.log('CACHE_CLEAR_USER_NAME:', process.env.CACHE_CLEAR_USER_NAME); | |
const payload = { | |
iss: process.env.CACHE_CLEAR_USER_NAME, | |
iat: Math.floor(Date.now() / 1000), | |
exp: Math.floor(Date.now() / 1000) + (60 * 60), // 1 hour from now | |
}; | |
const options = { | |
algorithm: 'HS256', | |
header: { | |
alg: 'HS256', | |
typ: 'JWT' | |
} | |
}; | |
const token = jwt.sign(payload, process.env.CACHE_CLEAR_CLIENT_SECRET, options); | |
console.log('Token first 10 characters:', token.substring(0, 10)); | |
console.log('Token length:', token.length); | |
try { | |
const decoded = jwt.verify(token, process.env.CACHE_CLEAR_CLIENT_SECRET, { algorithms: ['HS256'] }); | |
console.log('Token verified successfully. Payload:', decoded); | |
} catch (err) { | |
console.error('Token verification failed:', err.message); | |
} | |
axios.post('https://api-lambda.staging.notification.cdssandbox.xyz/cache-clear', null, { | |
headers: { | |
'Authorization': `Bearer ${token}`, | |
'Content-Type': 'application/json' | |
} | |
}) | |
.then(response => { | |
console.log('API call successful:', response.data); | |
}) | |
.catch(error => { | |
console.error('Error calling API:', error.response ? error.response.data : error.message); | |
process.exit(1); | |
}); | |
" |