diff --git a/.github/scripts/cleanup.js b/.github/scripts/cleanup.js deleted file mode 100644 index 512f233..0000000 --- a/.github/scripts/cleanup.js +++ /dev/null @@ -1,31 +0,0 @@ -import { fetch_token } from './token.js' - -const token = await fetch_token() -const headers = { authorization: `Bearer ${token}`, 'content-type': 'application/json' } - -const url = 'https://service-manager.cfapps.eu10.hana.ondemand.com' - -const contains = 'telemetry' -const AGE = 1000 * 60 * 60 * 1 // 1 hour - -const b_url = url + `/v1/service_bindings?fieldQuery=name contains '${contains}'` -const b_res = await fetch(b_url, { method: 'GET', headers }) -let { items: bindings } = await b_res.json() -bindings = bindings.filter(b => Date.now() - new Date(b.created_at) > AGE) - -console.log(`>>> Found ${bindings.length} old service bindings containing '${contains}'`) - -for (const binding of bindings) { - await fetch(url + `/v1/service_bindings/${binding.id}`, { method: 'DELETE', headers }) -} - -const i_url = url + `/v1/service_instances?fieldQuery=name contains '${contains}'` -const i_res = await fetch(i_url, { method: 'GET', headers }) -let { items: instances } = await i_res.json() -instances = instances.filter(i => Date.now() - new Date(i.created_at) > AGE) - -console.log(`>>> Found ${instances.length} old service instances containing '${contains}'`) - -for (const instance of instances) { - await fetch(url + `/v1/service_instances/${instance.id}`, { method: 'DELETE', headers }) -} diff --git a/.github/scripts/setup.js b/.github/scripts/setup.js deleted file mode 100644 index 94ec158..0000000 --- a/.github/scripts/setup.js +++ /dev/null @@ -1,63 +0,0 @@ -import { promisify } from 'node:util' -const sleep = promisify(setTimeout) - -import { join as path_join } from 'node:path' -import { writeFileSync } from 'node:fs' - -import { fetch_token } from './token.js' - -const token = await fetch_token() -const headers = { authorization: `Bearer ${token}`, 'content-type': 'application/json' } - -const url = 'https://service-manager.cfapps.eu10.hana.ondemand.com' - -const i_url = url + '/v1/service_instances' -const i_name = `telemetry_ci_${Math.random().toString(36).substring(2, 15)}` -const i_options = { - method: 'POST', - headers, - body: JSON.stringify({ - name: i_name, - service_plan_id: 'fa787a6e-4e35-461a-ac5d-4189a2cf8084' - }) -} -const i_res = await fetch(i_url, i_options) -const i_loc = i_res.headers.get('location') -const service_instance_id = i_loc.split('/')[3] - -for (let i = 0; i < 60; i++) { - await sleep(1000) - const res = await fetch(url + i_loc, { method: 'GET', headers }) - const { state } = await res.json() - if (state === 'succeeded') break -} - -const b_url = url + '/v1/service_bindings' -const b_name = i_name + '_binding' -const b_options = { - method: 'POST', - headers, - body: JSON.stringify({ - name: b_name, - service_instance_id - }) -} -const b_res = await fetch(b_url, b_options) -const b_loc = b_res.headers.get('location') -const service_binding_id = b_loc.split('/')[3] - -for (let i = 0; i < 60; i++) { - await sleep(1000) - const res = await fetch(url + b_loc, { method: 'GET', headers }) - const { state } = await res.json() - if (state === 'succeeded') break -} - -const res = await fetch(b_url + '/' + service_binding_id, { method: 'GET', headers }) -const { credentials } = await res.json() - -const cdsrc = path_join(process.cwd(), 'test', 'bookshop', '.cdsrc.json') -writeFileSync(cdsrc, JSON.stringify({ requires: { db: { kind: 'hana', credentials } } }, null, 2)) - -const vcap = path_join(process.cwd(), 'test', 'bookshop', 'vcap.json') -writeFileSync(vcap, JSON.stringify({ VCAP_SERVICES: { hana: [{ tags: ['hana'], credentials }] } }, null, 2)) diff --git a/.github/scripts/token.js b/.github/scripts/token.js deleted file mode 100644 index 8dff2f9..0000000 --- a/.github/scripts/token.js +++ /dev/null @@ -1,22 +0,0 @@ -import { URLSearchParams } from 'url' - -const fetch_token = async () => { - const url = 'https://cdx-stakeholder-tests.authentication.eu10.hana.ondemand.com/oauth/token' - - const encodedParams = new URLSearchParams() - encodedParams.set('grant_type', 'client_credentials') - encodedParams.set('client_id', process.env.SM_CLIENT_ID) - encodedParams.set('client_secret', process.env.SM_CLIENT_SECRET) - - const options = { - method: 'POST', - headers: { 'content-type': 'application/x-www-form-urlencoded' }, - body: encodedParams - } - - const response = await fetch(url, options) - const { access_token } = await response.json() - return access_token -} - -export { fetch_token } diff --git a/.github/workflows/hana.yml b/.github/workflows/hana.yml index 4d43b9c..993b223 100644 --- a/.github/workflows/hana.yml +++ b/.github/workflows/hana.yml @@ -19,15 +19,20 @@ jobs: hana-driver: [hdb, hana-client] hana-prom: [true, false] env: - SM_CLIENT_ID: ${{ secrets.SM_CLIENT_ID }} - SM_CLIENT_SECRET: ${{ secrets.SM_CLIENT_SECRET }} HANA_DRIVER: ${{ matrix.hana-driver }} HANA_PROM: ${{ matrix.hana-prom }} steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 - - run: node .github/scripts/cleanup.js - - run: node .github/scripts/setup.js + - uses: cap-js/.github/.github/actions/hana-hdi-container@main + with: + instance-prefix: telemetry + config-path: test/bookshop + service-manager-url: ${{ secrets.SM_URL }} + hana-plan-id: ${{ secrets.HANA_PLAN_ID }} + service-manager-auth-url: ${{ secrets.SM_AUTH_URL }} + service-manager-client-id: ${{ secrets.SM_CLIENT_ID }} + service-manager-client-secret: ${{ secrets.SM_CLIENT_SECRET }} - run: npm i -g @sap/cds-dk - run: npm add @cap-js/hana - run: npm add hdb